Important: Please read the Qt Code of Conduct -

QFormLayout does not expand widget full height to maximum widget height

  • I have an issue with getting a QTreewidget full height inside a QFormLayout. I'm on Windows 10 and use QT 5.7

    Things I tried:

    • all possible Vertical policy's without success.
    • Change the FieldGrowthPolicy of the layout to AllNonFixedFieldsGrow
    • Use another widget, all fail to make this work

    That's all the options I found to possibly make this work.

    Here's what I try to achieve:

    Here's my ui file:

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <widget class="QDialog" name="Dialog">
      <property name="geometry">
      <property name="windowTitle">
      <layout class="QFormLayout" name="formLayout">
       <item row="0" column="0">
        <widget class="QLabel" name="label">
         <property name="text">
          <string>Please grow the treeview:</string>
       <item row="0" column="1">
        <widget class="QTreeWidget" name="treeWidget">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
          <property name="text">
           <string notr="true">1</string>

  • I think QFormLayout inserts a spacer at the bottom by default. Convert it to a QGridLayout to have the desired result

  • @VRonin Okay, that works better, thanks.
    However, now the labels are center aligned vertically and the only way to change this seems to be in the AddWidget function.
    Is there a way to do this in Qt Designer? Can't seem to select a QGridLayout's cell to set properties of that cell.

  • Just click on the label and set the alignment property

  • You should set the object in the last row of formlayout (see QTreewidget), its vertical expanding factor should not be 0.

Log in to reply