Layouts in QtCreator for beginners
I’m new to designing user interfaces with Qt and I am having a hard time trying to define the layout of my gui in QtCreator.
Can anyone point me to some decent documentation on how to use layouts in QtCreator?
For example, I have a group box containing a number of buttons and labels arranged more or less on a grid. When I apply a grid layout to the group box, a number of things happen that I don’t understand and don’t want to happen:
- the size of the group box changes, even though the size policy of the group box is fixed,fixed – the size of some of the buttons changes, even though their size policy is again fixed,fixed. – I cannot find a way to add rows or columns to the layout
A hint or pointer to documentation would be very useful.
Thanks for the hint on using a minimum size; this was the key problem that was bogging me. I intuitively assumed that using a size policy of “fixed” would freeze the size of my widgets, but this is clearly not the case.
Thanks for the link; I am still reading to try and understand why my intuitive interpretation was not correct, and how these layouts really work. It is not really intuitive to me.
The “layout” link explains layout in terms of Qt classes, whereas I was really looking for an explanation of layouts in Qt Designer. Anyway, it is still useful background information.
From the QSizePolicy documentation, one can learn that a sizePolicy works relative to the sizeHint, and not to the current size as I intuitively expected.
How the size hint is defined for widgets like push buttons and labels is not obvious from the documentation [doc.qt.nokia.com] ; it seems to be unspecified by default, and the relationship to minimum and maximum size is not clear. I also checked the documentation for a derived class like QPushButton [doc.qt.nokia.com] , but there is no extra information there.
My conclusion is that the Qt documentation could use some improvements there. In the mean time, I guess I’ll just have to experiment to find out how it works.
One of the open questions for me is how a grid layout assigns widgets to rows and columns. There seems to be some sophisticated heuristics involved (or just magic?), but it is unclear how to fix things if it doesn’t do what I want.