AFAIK Qt has not this feature. You have to handle docks rearrange manually by their signals. Here is a quick sample:
#include <QtCore>
#include <QtGui>
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow mainWindow;
mainWindow.setCentralWidget(new QLabel("<B>I am a<BR>central widget.</B>"));
QDockWidget dock1("Dock1");
dock1.setWidget(new QLabel("Content1"));
QDockWidget dock2("Dock2");
dock2.setWidget(new QLabel("Content2"));
dock2.setAllowedAreas(Qt::LeftDockWidgetArea);
const auto relocateDock1 = [&] (Qt::DockWidgetArea newArea) {
if (dock1.isFloating())
return;
if (newArea == Qt::LeftDockWidgetArea) {
// Dock is tabified before user drops it. See also
// QMainWindow::splitDockWidget notes in documentation.
if (!mainWindow.tabifiedDockWidgets(&dock2).isEmpty())
mainWindow.addDockWidget(Qt::LeftDockWidgetArea, &dock2);
mainWindow.splitDockWidget(&dock1, &dock2, Qt::Horizontal);
}
};
const auto relocateDock2 = [&] (bool topLevel) {
if (topLevel)
return;
if (mainWindow.dockWidgetArea(&dock1) == Qt::LeftDockWidgetArea) {
mainWindow.splitDockWidget(&dock1, &dock2, Qt::Horizontal);
}
};
QObject::connect(&dock1, &QDockWidget::dockLocationChanged, relocateDock1);
QObject::connect(&dock2, &QDockWidget::topLevelChanged, relocateDock2);
mainWindow.addDockWidget(Qt::LeftDockWidgetArea, &dock1);
mainWindow.addDockWidget(Qt::LeftDockWidgetArea, &dock2);
relocateDock2(false);
mainWindow.show();
return app.exec();
}
This way looks ugly and is full of workarounds. But I don't know a way better.
I have spent a lot of time to do it and my advice is to pass up this idea. Maybe it is easier to have a two-column widget in one dock?