I want mainwindow to keep approximate ratio of dock widget sizes and central widget size, when the window's size is changed. I've written simplest mainwindow with central widget and 6 dock widgets:
#include <QPlainTextEdit>
#include <QDockWidget>
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
this->setGeometry(20, 20, 600, 600);
this->setCentralWidget(
new QPlainTextEdit("central", this)
);
QDockWidget *p_dw;
for (int i = 0; i < 6; ++i){
p_dw = new QDockWidget("dock " + QString::number(i));
p_dw->setWidget(
new QPlainTextEdit("dock " + QString::number(i), this)
);
Qt::DockWidgetArea area;
switch (i){
case 0:
case 1:
area = Qt::TopDockWidgetArea;
break;
case 2:
area = Qt::RightDockWidgetArea;
break;
case 3:
case 4:
area = Qt::BottomDockWidgetArea;
break;
default:
area = Qt::LeftDockWidgetArea;
break;
}
addDockWidget(area, p_dw);
}
}
MainWindow::~MainWindow()
{
}
When started, it looks as follows:
I can shrink it:
And expand back, and after expanded, it looks as at the first screenshot. It is fine.
The problem is that if user "touches" central widget bounds (I mean, changes the central widget size manually, ever for a little bit), then main window changes its policy dramatically: after user touches central widget, then shrinks window, and then expands it back, all dockwidgets have their minimum sizes:
The question is, how to prevent this behavior? Or, more generally, how can I influence on the size policy of QMainWindow
? I can't find any documentation about the behaviour I've explained above.