QDockWidget *dw1 = new QDockWidget("1", this);QDockWidget *dw2 = new QDockWidget("2", this);addDockWidget(Qt::RightDockWidgetArea, dw1);addDockWidget(Qt::RightDockWidgetArea, dw2);tabifyDockWidget(dw1, dw2);
#include "mainwindow.h"#include <qaction.h>#include <qdockwidget.h>#include <qpushbutton.h>MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags){ QPushButton *btn = new QPushButton("Create docks", this); setCentralWidget(btn); connect(btn, SIGNAL(clicked()), this, SLOT(createDocks())); // createDocks();}void MainWindow::createDocks() { QDockWidget *dw1 = new QDockWidget("1", this); QDockWidget *dw2 = new QDockWidget("2", this); addDockWidget(Qt::RightDockWidgetArea, dw1); addDockWidget(Qt::RightDockWidgetArea, dw2); tabifyDockWidget(dw2, dw1);}
MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags){ QPushButton *btn = new QPushButton("Create docks", this); setCentralWidget(btn); connect(btn, SIGNAL(clicked()), this, SLOT(createDocks())); dw1 = new QDockWidget("1", this); dw1->hide(); dw2 = new QDockWidget("2", this); dw2->hide(); //createDocks();}void MainWindow::createDocks(){ addDockWidget(Qt::RightDockWidgetArea, dw1); addDockWidget(Qt::RightDockWidgetArea, dw2); dw1->show(); dw2->show(); tabifyDockWidget(dw2, dw1);}
MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags){ QPushButton *btn = new QPushButton("Create docks", this); setCentralWidget(btn); connect(btn, SIGNAL(clicked()), this, SLOT(createDocks())); //createDocks();}void MainWindow::createDocks(){ QDockWidget *dw1 = new QDockWidget("1", this); addDockWidget(Qt::RightDockWidgetArea, dw1); QApplication::processEvents(); QDockWidget *dw2 = new QDockWidget("2", this); addDockWidget(Qt::RightDockWidgetArea, dw2); QApplication::processEvents(); tabifyDockWidget(dw2, dw1);}
void MainWindow::updateDock(int index){ QTabBar *tabBar = findChild<QTabBar *>(); tabBar->setCurrentIndex(index);}
QList<QTabBar *> tabBars = findChildren<QTabBar *>();