3

I have a QMainWindow with the widgets laid out in a grid. They all resize proportionally when the window resizes as expected, except for the widgets placed inside a QGroupBox. The QGroupBox itself resizes, but the widgets inside just stay on the same place. If I apply a lay out on the QGroupBox, the widgets loose their original positions. Note that I'm using the .ui file with PyQt4. You can get the file here.

And this is what happens:

enter image description here

enter image description here

R01k
  • 735
  • 3
  • 12
  • 26
  • 3
    The widgets inside the group box must be in a layout. If they are not in a layout, their size is fixed (the layout manages the size, no layout, no resize) – Fabio Aug 27 '16 at 15:23
  • What do you mean when you say "the widgets lose their original positions"? (PS: please do not link to code on other sites - put it in the question itself). – ekhumoro Aug 27 '16 at 15:29
  • I mean that if I apply a layout on the QGroupBox all widgets inside accommodate themselves according the layout type. Even if it's a Grid layout, they don't stay where you see them in the screenshot, but occupy positions completely different. – R01k Aug 27 '16 at 20:11

1 Answers1

6

From Qt documentation on QGroupBox:

QGroupBox doesn't automatically lay out the child widgets (which are often QCheckBoxes or QRadioButtons but can be any widgets).

There is an example showing how to setup a layout for a QGroupBox (which is the same a setting up a layout for any QWidget based object meant to store other objects, like QFrame for instance).

You must create a layout, call QGroupBox::setLayout and then add widgets to the layout. If you use QtCreator, right-click the QGroupBox and select the layout you want to use for it from the context menu.

jpo38
  • 20,821
  • 10
  • 70
  • 151
  • Thank you. I ended up just getting rid of the QGroupBox and playing with layouts until got it right. – R01k Aug 31 '16 at 16:21