qtresizepyqtqwidgetqgroupbox

Why won't QGroupBox widgets dynamically resize with rest of window?


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


Solution

  • 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.