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.
-
You need to set the 'minimum' sizes of your objects before applying layouts I noticed.
-
Maybe this link will get you started: "Qt 4.7: Tutorials":http://doc.qt.nokia.com/4.7-snapshot/tutorials.html and "Videotutorials":http://www.voidrealms.com/tutorials.aspx?filter=qt
-
Mark,
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.
Woody,
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.
Rahul,
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.
-
The "Qt Designer documentation about layouts":http://doc.qt.nokia.com/4.7/designer-layouts.html does not explain size policies; it seems necessary to delve into the documentation of the "QSizePolicy class":http://doc.qt.nokia.com/4.7/qsizepolicy.html#details.
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":http://doc.qt.nokia.com/4.7/qwidget.html#sizeHint-prop ; 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":http://doc.qt.nokia.com/4.7/qpushbutton.html#sizeHint , 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.
-
Yes of course I can experiment, I have experimented and I will experiment. Its just that when I don't get the results I want while experimenting, I try to understand better what is happening and how to get the desired results. That's why I started looking for help and reading documentation ...
-
I found this useful when I was beginning to learn about layouts: "http://www.informit.com/articles/article.aspx?p=1405224&seqNum=4":http://www.informit.com/articles/article.aspx?p=1405224&seqNum=4