Qt
has a flexible and powerful layout mechanism to handle view of desktop application's windows.
But it is so flexible, that it nearly cannot be understood, when something goes wrong and needs fine-tuning. And so powerful, that it can beat anyone in their tries to overwhelm Qt's opinion of how form should look.
So, can anyone explain, or provide articles, or source of Qt's positioning mechanisms?
I'm trying to force the QLabel
, QPushButton
and QTableView
, marked by trailing underscores in their names, be two times higher than QTextBrowser
having verticalStretch = 1
below. How can I handle widget's height properly?
Layouts are actually easy to understand "I think" :)
A simple explanation of layouts can be found in the Qt book C++ Gui programming with Qt 2nd edition.
QSizePolicy
. A size policy has both vertical and horizontal components.QSizePolicy
has a stretch factor to allow widgets to grow at different ratesYou may want to ask: What is the difference between preferred and expanding?
Answer: Imagine a form with 2 widgets, one with preferred and another with expanding policy. Then any extra space will be given to the widget with the expanding policy. The widget with the preferred policy will remain at its size hint.
I recommend (WARNING: I am not an expert :)) you buy and read through C++ Gui programming with Qt 2nd edition. I am currently reading it and it is making a lot of sense. Look at the images and see if they make some sense.
This is a simple dialog with 2 buttons whose horizontal and vertical size policies are shown as are the horizontal and vertical stretch.
You can see that every widget has a size hint which is vital because Qt's layout system always respects the size hint. This is only a problem if the default size of the widget is not exactly what you want. The only way around this problem is to extend (subclass) the widget and reimplement its sizeHint()
member function. An example is worth 1000 words. To save space, see my blog where there is an example project.