PDA

View Full Version : Doubt with spacing between widgets in layout managers



PulseReaction
27th November 2008, 18:35
Hi. I'm a newbie to Qt and I'm studying it using Python, but understanding C/C++ code is not a problem. My situation is this: I have a QHBoxLayout and I added a QGroupBox to it. Then I added some checkboxes to my QGroupBox (using a QVBoxLayout inside).

My problem is: when the window is resized, the checkboxes grow apart (I believe they grow vertically) and I want them to stay together, as they do when the QGroupBox is in its minimum size.

What should I do to achieve this?

rexi
27th November 2008, 20:49
You can add a spacer to the QVBoxLayout after the two checkboxes. The spacer takes up the excess space and pushes the checkboxes up, so they stay together. See http://doc.trolltech.com/4.4/qboxlayout.html#addStretch.

PulseReaction
27th November 2008, 23:29
Thank you, this solved my problem :D

And what if I want to allocate any extra space to the other widget, instead of the groupbox? I added a QGLWidget next to the QGroupBox and I want any extra horizontal space to be given to the QGLWidget. How can I do it?

wysota
27th November 2008, 23:57
Set the sizePolicy property of the GL widget to expanding. In addition you can also set the group box's size policy to fixed.