views:

23

answers:

0

Hello everyone,

Here are two designer .ui files :

  • resize_not_ok.ui is a QTabWidget. In its first tab (layout being a QVerticalLayout) there is a QPushButton and a QVerticalSpacer

  • resize_ok.ui follows the same structure, but the QTabWidget is inserted in a QWidget. This top-level QWidget has a QVertical layout with only the QTabWidget inside.

Resizing resize_ok works as expected : the QPushButton can grow and shrink in width but its height stays constant. However, resize_not_ok can be resized to the extreme : the QPushButton follows this resize, so it shrinks until complete vanishing.

I can't explain this behaviour. Anyone has an idea on why I can resize my QTabWidget to the extreme ? Is it mandatory to put a QTabWidget in a QWidget to get a sensible resize policy ?

Thank you very much !

resize_ok.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Form</class>
 <widget class="QWidget" name="Form">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>184</width>
    <height>136</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Form</string>
  </property>
  <layout class="QVBoxLayout" name="verticalLayout_2">
   <item>
    <widget class="QTabWidget" name="tabWidget">
     <widget class="QWidget" name="tab">
      <attribute name="title">
       <string>Tab 1</string>
      </attribute>
      <layout class="QVBoxLayout" name="verticalLayout">
       <item>
        <widget class="QPushButton" name="pushButton">
         <property name="text">
          <string>PushButton</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>57</height>
          </size>
         </property>
        </spacer>
       </item>
      </layout>
     </widget>
     <widget class="QWidget" name="tab_2">
      <attribute name="title">
       <string>Tab 2</string>
      </attribute>
     </widget>
    </widget>
   </item>
  </layout>
 </widget>
 <resources/>
 <connections/>
</ui>

resize_not_ok.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>TabWidget</class>
 <widget class="QTabWidget" name="TabWidget">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>336</width>
    <height>245</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>TabWidget</string>
  </property>
  <property name="currentIndex">
   <number>0</number>
  </property>
  <widget class="QWidget" name="tab">
   <attribute name="title">
    <string>Tab 1</string>
   </attribute>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
     <widget class="QPushButton" name="pushButton">
      <property name="text">
       <string>PushButton</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>174</height>
       </size>
      </property>
     </spacer>
    </item>
   </layout>
  </widget>
  <widget class="QWidget" name="tab">
   <attribute name="title">
    <string>Tab 2</string>
   </attribute>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>