1

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: qtQformLayoutIssue.png

Here's my ui file:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Dialog</class>
 <widget class="QDialog" name="Dialog">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>760</width>
    <height>747</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Dialog</string>
  </property>
  <layout class="QFormLayout" name="formLayout">
   <item row="0" column="0">
    <widget class="QLabel" name="label">
     <property name="text">
      <string>Please grow the treeview:</string>
     </property>
    </widget>
   </item>
   <item row="0" column="1">
    <widget class="QTreeWidget" name="treeWidget">
     <property name="sizePolicy">
      <sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
       <horstretch>0</horstretch>
       <verstretch>0</verstretch>
      </sizepolicy>
     </property>
     <column>
      <property name="text">
       <string notr="true">1</string>
      </property>
     </column>
    </widget>
   </item>
  </layout>
 </widget>
 <resources/>
 <connections/>
</ui>
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Stormenet
  • 25,926
  • 9
  • 53
  • 65

2 Answers2

2

Please read the Qt tutorials about layouts. I added a two layouts and a spacer to your ui file.

widgets with layouts

tree

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Dialog</class>
 <widget class="QDialog" name="Dialog">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>489</width>
    <height>215</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Dialog</string>
  </property>
  <layout class="QHBoxLayout" name="horizontalLayout_2">
   <item>
    <layout class="QHBoxLayout" name="horizontalLayout">
     <item>
      <layout class="QVBoxLayout" name="verticalLayout">
       <item>
        <widget class="QLabel" name="label">
         <property name="text">
          <string>Please grow the treeview:</string>
         </property>
        </widget>
       </item>
       <item>
        <spacer name="verticalSpacer">
         <property name="orientation">
          <enum>Qt::Vertical</enum>
         </property>
         <property name="sizeHint" stdset="0">
          <size>
           <width>20</width>
           <height>40</height>
          </size>
         </property>
        </spacer>
       </item>
      </layout>
     </item>
     <item>
      <widget class="QTreeWidget" name="treeWidget">
       <property name="sizePolicy">
        <sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
         <horstretch>0</horstretch>
         <verstretch>0</verstretch>
        </sizepolicy>
       </property>
       <column>
        <property name="text">
         <string notr="true">1</string>
        </property>
       </column>
      </widget>
     </item>
    </layout>
   </item>
  </layout>
 </widget>
 <resources/>
 <connections/>
</ui>
znoopy2k
  • 58
  • 5
  • Basically when I want something to take up full space with a QFormLayout I can't and should use another kind of Layout such as your example or QGridLayout. Too bad this limitation is there. – Stormenet Jan 18 '17 at 12:03
  • this solution does not use QFormLayout which is what OP requested (I'm having the same problem in my code) – Jean-Michaël Celerier Dec 19 '18 at 08:54
0

Based on this answer: Qt formlayout not expanding qplaintextedit vertically which worked for me, setting the Vertical Stretch attribute to something other than 0 should do the trick.

Erwan Leroy
  • 160
  • 10