PDA

View Full Version : QGridLayout: force all widget to the same size



Spooky
23rd March 2011, 11:00
Let's say I want to make a simple layout like this:
+----------+----------+----------+
| | | |
| QWidget | QWidget | QWidget |
| | | |
+----------+----------+----------+
| | | |
| QWidget | QWidget | QWidget |
| | | |
+----------+----------+----------+This is easy enough, however I want all the widgets to always have the same size, i.e. all the widgets within the grid layout should take up the space equally.

For instance, if I have a setup like this:
+----------+----------+
| | |
| QTable |QGLWidget |
| Widget | |
+----------+----------+
| | |
|QGLWidget |QGLWidget |
| | |
+----------+----------+the space taken by each widget should be equal. However, in that setup, without doing any size policy changes etc., the table widget will take up the whole space, since its default policy will expand in all directions and the QGLWidgets have 'no content to work against that' so to speak.

Is there a way to achieve this through size policies or layout settings, without setting the sizes of each widget manually?

wladek
23rd March 2011, 13:37
Hi Spooky,

Personally, I do not believe that you can achieve what you want only through size policies.
Basically, when you setup a layout to a Widget, you tell him to occupy all the space available.
And if your QGLWidgets do not have "any content", then it is expected for the QTableWidget to fill the parent widget.

One idea to do it would be to get the size of the top widget (the one that contains all the 4 widgets) and to set a maximumSize on the QTableWidget (maximumSize which you can calculate from the top widget's size).

Again I have to mention that this is only my personal opinion, does anybody else have a different point of view?

Hope this helps though.

Regards,
Wladek

Spooky
23rd March 2011, 14:58
Well, I played around a bit and I now think, that QSplitter fits my needs better. It was just an initial desire, that all widgets, no matter their actual content, should have the same size, if possible, but it's better for the user anyway, if he has the possibility to resize the layout in some way, which I can achieve with QSplitter. I also played around with the stretch factors of my QSplitter setup and managed to get good initial sizes for that particular setup (the one with the table widget on the top left and 3 QGL Widgets).