PDA

View Full Version : Struggling with layouts in QtCreator



davethomaspilot
4th February 2023, 13:57
I've been using QtCreator for some time, but I have to admit, I really don't understand all the parameters that can be used in a layout.

For example, I have a vertical layout with three QFrames.

The Qframes have vertical stretch and horizontal stretch policies. But the layout also has a layoutStretch property, which is a list (I think) of the vertical stretch properties for each widget it contains.

Are these the same thing? Which one takes precedent (they aren't kept in sync).

Also, it seems sometimes widgets inside a layout overlap each other. I didn't think that was supposed to happen. Or, maybe it's a widget contained by the QFrame that goes outside its frame Either way, stuff definitely overlaps. What are the rules for this?

Thanks!

d_stranz
4th February 2023, 17:16
AFAIK, the layout's policies take precedence over the widgets inside it. The layout will try to honor the widgets' minimum size and size hints and size policy, but i suppose if you externally compress a layout by forcing it into a container smaller than the minimum sizes of the widgets in the layout, then the layout might have no choice except to overlap widgets.

On the other hand, if it is a custom widget doing its own drawing and that drawing doesn't respect the bounding rect imposed on it by the layout, it will color outside the lines and appear to be overlapping.

Stretch in layouts is a mystery. I have not found anywhere in the documentation that describes how stretch actually behaves other than cryptic things like
Sets the stretch factor at position index. to stretch. Well, duh, but what does that mean? The closest I have come to understanding it is that if you have two panes in a layout, one with stretch factor 1 and the other with stretch factor 2, the second seems to stretch at twice the rate of the first. Sometimes. Until you add a third or fourth pane.

davethomaspilot
4th February 2023, 21:33
I'd love to see something that discusses each layout parameter, both in QtCreator and from code (e.g, setting sizeHint in QtCreator is done using several other parameters (I think)).

Some have recommended purchasing a book that supposed to have a good explanation--I'd have to track down the name again. But, it was qt4 and I don't know how much has changed since then.

I always get something working, close to what I want, but it's very empirical. Tweak, try again until I get something like I want.