[Interest] constraining minimum widget size

Bo Thorsen bo at vikingsoft.eu
Wed Sep 23 09:33:34 CEST 2015

Den 23-09-2015 kl. 09:07 skrev Hamish Moffatt:
> I want to be able to set the minimum size for a container widget without
> ignoring the minimum sizes of the children. ie I want to constrain the
> minimum size of the container, not override it. Is this possible?
> Here's what I mean. Let's say I have a QFrame with a QVBoxLayout
> containing a couple of widgets, for example QRadioButton. I want this
> QFrame to be a particular size, no smaller (it looks silly), big enough
> to contain the child widgets, but no bigger. The size policies on the
> frame and radio buttons are all minimum.
> If I set the minimumSize property on the QFrame, I get the minimum size
> I requested - but now the QFrame ignores the minimum sizes of the
> children, so if the children require more room they are clipped. For
> example if the user is using 150% font scaling in Windows...
> Examples: no minimum size, with a minimum size set, with the minimum
> size set but larger fonts...
> If I were writing a custom widget then overriding
> sizeHint()/minimumSizeHint() might help, but I want to do this in Qt
> Designer/Creator using the standard container widgets. Is it possible?

Yes it is.

The stacked widget is useful for many things, this is one of them.

Create a stacked widget with two pages. Page 1 has all the widgets you 
need for this page, so it's just a container for them. On page 2 you put 
an empty QWidget inside with the minimum size you want. You never show 
page 2, but the minimum size is used.

The stacked widget minimum size is just the maximum of each pages 
minimum size, which is exactly what you want here.

I hope this helps,

Bo Thorsen,
Director, Viking Software.

Viking Software
Qt and C++ developers for hire

More information about the Interest mailing list