Important: Please read the Qt Code of Conduct -

How to make widget use maximum height

  • I'm using qt creator and designer to create an app, and so far I have in the MainWindow 4 things:

    1. a qtreeview
    2. a group box
    3. another group box
    4. a vertical spacer

    The treeview is to the left and first groupbox is in the upper right corner, and the other box below and the spacer below that group box.

    I selected each group box in turn and clicked "Lay out in a grid" and set "LayoutSizeConstraint" to "SetFixedSize" for them both, so they look very nice and keep their size when resizing the mainwindow.

    Then I selected the central widget and clicked "Lay out in a grid".

    Now the groupboxes are close to eachother and stay in the upper right corner when resizing the mainwindow, and the treeview changes size to fit as much as possible horrizontaly (great!) but how can I get it to scale vertically and use maximum height?

  • Moderators

    You need to modify sizePolicy of your QTreeView widget and set it to expanding in both directions.

  • Thanks for the suggestion, but it didn't help. It was already set to Expanding in both directions.

  • I solved it by breaking up the layout of the central widget, and putting the widgets to the right (2. 3. and 4.) in a vertical layout, and then add a grid layout in the central widget.

  • Moderators

    Nice, thanks for sharing the solution

Log in to reply