Important: Please read the Qt Code of Conduct -

Nesting QLayouts vs. nesting QWidgets?

  • Hello,

    I'm creating a UI strictly via Qt Designer that needs some nested layouts. Several layers of VBox and HBox plus a GridLayout or two. The UI is not too complex, but it is more detailed than most Qt examples in the docs.

    Is it better to use a series of nested layouts, or a series of nested "invisible" QWidgets each with a layout for it's children?

    I started with just nested layouts under a QMainWindow, but managing the layout hierarchy via the Object Inspector was difficult. The Qt Designer UI seems lacking here.

    Furthermore, I had to tediously re-create everything every time I broke the layout to add an extra QFrame around some other controls or the like. Not cool.

    Using nested QWidgets seems to make using Qt Designer much more sane, but adding all those extra objects cant be a good thing.

    Which is the best way? Is there a recommended workflow I'm missing?


  • Lifetime Qt Champion


    Without more info on what your UI should be doing, i'll be asking question in the hope it'll help you.

    If you need so much nesting, are you sure you are using the proper layouts ? Did you took a look at QFormLayout for example ? Or QGroupBox ?

    Do you have several "logic blocks" ? In that case, each might be in its own widget to avoid a one size fits all design while also encouraging re-usability.

    Hope it helps

  • Thanks for the reminder about QGroupBox. It'll help in a spot or two. I don't think QFormLayout is applicable, though.

    Setting aside the question of if there is any way to avoid nesting layouts in the first place, I'm still wondering what is the best way to handle nested layouts via Qt Designer.

    What do folks tend to do? (Directly nested, or nesting via QWidgets?)

Log in to reply