I've just ported my application from Qt 4.8.4 to Qt 5.2.1. I have an issue with the FlowLayout
class as provided in the FlowLayout example code in the Qt docs.
I have a QMainWindow
with a QDockWidget
docked at the bottom of the central widget.
The QDockWidget
has a FlowLayout
with several child widgets. In Qt 4.8, this worked like a charm, the size of the child widgets fitted the standard size of the DockWidget
. However, in Qt 5.2, the DockWidget
tries to increase its size to the maximum (taking the place from the central widget). Changing its layout prevents this unwanted behavior. But of course, I use FlowLayout
on purpose.
To illustrate the problem, I created a minimal example:
The constructor of the DockWidget
:
QGroupBox *generalBox = new QGroupBox("");
generalBoxLayout = new FlowLayout;
generalBox->setLayout(generalBoxLayout);
for(int i=0; i<10; ++i)
{
QPushButton *button = new QPushButton("Test", this);
button->setMinimumWidth(100);
button->setMinimumHeight(100);
generalBoxLayout->addWidget(button);
}
this->setWidget(generalBox);
Does someone know what the problem is and how I can solve it?
Edit I've created a new minimal working example and unfortunately cannot reproduce the discrepancy between Qt 4.8 and Qt 5.2. The same problem shows up in Qt 4.8, so I would still like to present it here:
Initial view showing the bottom-docked dockwidget taking the whole vertical space:
View after resizing the dockwidget with the mouse
View after resizing the mainwindow with the mouse
These screenshots show that the dockwidgets behaves as expected after changing the size of the dockwidget manually. However, on initialization, the widget takes all available space from central widget, which is not desired.
Does someone know of a solution / workaround?