You should take a look at the QWidget::sizePolicy
. It controls how the layout takes into account the sizeHint()
its children when updating the geometry.
So, you need to do the following: Make the layout ignore the horizontal size of the Hints of the child widgets by setting the horizontal size policy of the three child widgets to QSizePolicy::Ignored
:
QLabel *label = ...; ... label->setSizePolicy(QSizePolicy::Ignored, label->sizePolicy().verticalPolicy());
(The second argument ensures that this instruction does not change the vertical policy. Of course, you must set the size policy for each child widget, this code example is for label only.)
Note that the contents of your layout should be widgets; It seems to me that size policies cannot be assigned to nested layouts (but I could be wrong). At least using QtDesigner, there is no way to apply the size policy to the layout itself (unless it is a widget layout). See comments for more details.
In QtDesigner, you can set the sizePolicy of child widgets as follows:
Before:
Heat shrinkable:
Select items in the layout:
Set the horizontal size policy to Ignore:
Result:
source share