Home > other >  Qt Designer: how to remove empty space around QTableWidget
Qt Designer: how to remove empty space around QTableWidget

Time:01-03

The Question is like said in the Title, how can i remove the Empty Space in the QTableWidget in the QT Designer? Here is a screenshot of it:

enter image description here More important is the white space below and not the whie spaces on the right!

the QTableWidget is inside a Vertical Layout and underneath the Layout is a Vertical Spacer with these Propertys:

enter image description here

Here are the Vertical Layout Propertys:

enter image description here

CodePudding user response:

It can be done with sizeAdjustPolicy, which is located in the QAbstractScrollArea section of the Property Editor in Qt Designer. When this is combined with a Minimum size-policy on the table (and possibly also hidden scrollbars), it should achieve what you want:

screenshot

However, it should be noted that the size-adjust-policy doesn't seem to handle hidden table-headers properly (which looks like a bug).

Here's a demo designer ui file:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Form</class>
 <widget  name="Form">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>392</width>
    <height>199</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Test</string>
  </property>
  <layout  name="verticalLayout">
   <item>
    <widget  name="label">
     <property name="text">
      <string>Table</string>
     </property>
     <property name="alignment">
      <set>Qt::AlignCenter</set>
     </property>
    </widget>
   </item>
   <item>
    <widget  name="tableWidget">
     <property name="sizePolicy">
      <sizepolicy hsizetype="Expanding" vsizetype="Minimum">
       <horstretch>0</horstretch>
       <verstretch>0</verstretch>
      </sizepolicy>
     </property>
     <property name="verticalScrollBarPolicy">
      <enum>Qt::ScrollBarAlwaysOff</enum>
     </property>
     <property name="horizontalScrollBarPolicy">
      <enum>Qt::ScrollBarAlwaysOff</enum>
     </property>
     <property name="sizeAdjustPolicy">
      <enum>QAbstractScrollArea::AdjustToContents</enum>
     </property>
     <row>
      <property name="text">
       <string>1</string>
      </property>
     </row>
     <row>
      <property name="text">
       <string>2</string>
      </property>
     </row>
     <column>
      <property name="text">
       <string>A</string>
      </property>
     </column>
     <column>
      <property name="text">
       <string>B</string>
      </property>
     </column>
     <column>
      <property name="text">
       <string>C</string>
      </property>
     </column>
    </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>
 </widget>
 <resources/>
 <connections/>
</ui>
  • Related