QDockWidget设置为tab切换形式的,其实就是调用一下
void QMainWindow::tabifyDockWidget(QDockWidget *first, QDockWidget *second)的此方法即可实现。
/******************************************************************************** ** Form generated from reading UI file 'guitest.ui' ** ** Created by: Qt User Interface Compiler version 5.12.2 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/ #ifndef UI_GUITEST_H #define UI_GUITEST_H #include <QtCore/QVariant> #include <QtWidgets/QApplication> #include <QtWidgets/QDockWidget> #include <QtWidgets/QMainWindow> #include <QtWidgets/QMenuBar> #include <QtWidgets/QStatusBar> #include <QtWidgets/QToolBar> #include <QtWidgets/QWidget> QT_BEGIN_NAMESPACE class Ui_GUITestClass { public: QWidget *centralWidget; QMenuBar *menuBar; QToolBar *mainToolBar; QStatusBar *statusBar; QDockWidget *dockWidget; QWidget *dockWidgetContents; QDockWidget *dockWidget_2; QWidget *dockWidgetContents_2; void setupUi(QMainWindow *GUITestClass) { if (GUITestClass->objectName().isEmpty()) GUITestClass->setObjectName(QString::fromUtf8("GUITestClass")); GUITestClass->resize(933, 671); centralWidget = new QWidget(GUITestClass); centralWidget->setObjectName(QString::fromUtf8("centralWidget")); GUITestClass->setCentralWidget(centralWidget); menuBar = new QMenuBar(GUITestClass); menuBar->setObjectName(QString::fromUtf8("menuBar")); menuBar->setGeometry(QRect(0, 0, 933, 26)); GUITestClass->setMenuBar(menuBar); mainToolBar = new QToolBar(GUITestClass); mainToolBar->setObjectName(QString::fromUtf8("mainToolBar")); GUITestClass->addToolBar(Qt::TopToolBarArea, mainToolBar); statusBar = new QStatusBar(GUITestClass); statusBar->setObjectName(QString::fromUtf8("statusBar")); GUITestClass->setStatusBar(statusBar); dockWidget = new QDockWidget(GUITestClass); dockWidget->setObjectName(QString::fromUtf8("dockWidget")); dockWidget->setAutoFillBackground(true); dockWidgetContents = new QWidget(); dockWidgetContents->setObjectName(QString::fromUtf8("dockWidgetContents")); dockWidget->setWidget(dockWidgetContents); dockWidget->setStyleSheet("border:1px solid #ccc;"); GUITestClass->addDockWidget(static_cast<Qt::DockWidgetArea>(1), dockWidget); dockWidget_2 = new QDockWidget(GUITestClass); dockWidget_2->setObjectName(QString::fromUtf8("dockWidget_2")); dockWidgetContents_2 = new QWidget(); dockWidgetContents_2->setObjectName(QString::fromUtf8("dockWidgetContents_2")); dockWidget_2->setStyleSheet("border:1px solid #ccc;"); //dockWidgetContents_2->setLayoutDirection(Qt::LeftToRight); dockWidget_2->setWidget(dockWidgetContents_2); GUITestClass->addDockWidget(static_cast<Qt::DockWidgetArea>(1), dockWidget_2); GUITestClass->tabifyDockWidget(dockWidget, dockWidget_2); retranslateUi(GUITestClass); QMetaObject::connectSlotsByName(GUITestClass); } // setupUi void retranslateUi(QMainWindow *GUITestClass) { GUITestClass->setWindowTitle(QApplication::translate("GUITestClass", "GUITest", nullptr)); dockWidget->setWindowTitle(QApplication::translate("GUITestClass", "BBB", nullptr)); dockWidget_2->setWindowTitle(QApplication::translate("GUITestClass", "AAA", nullptr)); } // retranslateUi }; namespace Ui { class GUITestClass: public Ui_GUITestClass {}; } // namespace Ui QT_END_NAMESPACE #endif // UI_GUITEST_H