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?
This is the answer given by Marek R. I'm putting it here so this question gets an answer. For too long it has been masquerading as an unanswered question.
I see the problem now. I did some experiments and research. It looks like some bug in Qt.
FlowLayout::heightForWidthis always called with samewidthvalue (in my case 103) independently on main window size and this leads height bigger then desired (usually window is much wider). Also it is not called when width of main window is changing (it suppose to to update height of dock area).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With