QTabWidget refusing to auto-resize

Reinderien picture Reinderien · Jun 3, 2011 · Viewed 8.8k times · Source

I'm attempting to have the following layout in qtcreator:

QWidget
  QSplitter
    QStackedWidget
      ...
    QStackedWidget
      QWidget (page)
        QTabWidget

Every single control that has a sizePolicy is set to Expanding. Despite this, neither the tab widget nor anything else I drop on that page widget gets autosized.

I'm new to Qt, so forgive me if this is an obvious fix. Thanks.

Answer

Jens picture Jens · Jun 3, 2011

Is this a duplicate of How to make a Qt Widget grow with the window size? ?

I think it is a duplicate, cause if every item in your tree of widgets has a layout, my test on Qt 4.7 gave the following output, on the right side is my object inspector. I did just put in the widgets and layouted them, i did not change any size things to expanding, as this is absolutely unnecessary!

Image with exe and creator screenshot

On the left is the running exe, on the right is the Creator screenshot. And here is my UI:

    <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>545</width>
    <height>441</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralWidget">
   <layout class="QHBoxLayout" name="horizontalLayout">
    <item>
     <widget class="QSplitter" name="splitter">
      <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
      <widget class="QStackedWidget" name="stackedWidget">
       <property name="currentIndex">
        <number>0</number>
       </property>
       <widget class="QWidget" name="page_1_1">
        <property name="layoutDirection">
         <enum>Qt::LeftToRight</enum>
        </property>
        <layout class="QGridLayout" name="gridLayout_2">
         <item row="0" column="0">
          <widget class="QTabWidget" name="tabWidget_1">
           <property name="currentIndex">
            <number>0</number>
           </property>
           <widget class="QWidget" name="tab_3">
            <attribute name="title">
             <string>Tab 1</string>
            </attribute>
            <layout class="QGridLayout" name="gridLayout_4">
             <item row="0" column="0">
              <widget class="QDateTimeEdit" name="dateTimeEdit_2"/>
             </item>
             <item row="1" column="0">
              <widget class="QDateTimeEdit" name="dateTimeEdit"/>
             </item>
            </layout>
           </widget>
           <widget class="QWidget" name="tab_4">
            <attribute name="title">
             <string>Tab 2</string>
            </attribute>
            <layout class="QGridLayout" name="gridLayout_5">
             <item row="0" column="0">
              <widget class="QCheckBox" name="checkBox_2">
               <property name="text">
                <string>CheckBox</string>
               </property>
              </widget>
             </item>
             <item row="1" column="0">
              <widget class="QCheckBox" name="checkBox">
               <property name="text">
                <string>CheckBox</string>
               </property>
              </widget>
             </item>
            </layout>
           </widget>
          </widget>
         </item>
        </layout>
       </widget>
      </widget>
      <widget class="QStackedWidget" name="stackedWidget_2">
       <widget class="QWidget" name="page_2_1">
        <layout class="QGridLayout" name="gridLayout_3">
         <item row="0" column="0">
          <widget class="QTabWidget" name="tabWidget_2">
           <widget class="QWidget" name="tab">
            <attribute name="title">
             <string>Tab 1</string>
            </attribute>
            <layout class="QGridLayout" name="gridLayout">
             <item row="0" column="0">
              <widget class="QDateEdit" name="dateEdit"/>
             </item>
             <item row="1" column="0">
              <widget class="QDateEdit" name="dateEdit_2"/>
             </item>
            </layout>
           </widget>
           <widget class="QWidget" name="tab_2">
            <attribute name="title">
             <string>Tab 2</string>
            </attribute>
            <layout class="QGridLayout" name="gridLayout_6">
             <item row="0" column="0">
              <widget class="QCheckBox" name="checkBox_4">
               <property name="text">
                <string>CheckBox</string>
               </property>
              </widget>
             </item>
             <item row="1" column="0">
              <widget class="QCheckBox" name="checkBox_3">
               <property name="text">
                <string>CheckBox</string>
               </property>
              </widget>
             </item>
            </layout>
           </widget>
          </widget>
         </item>
        </layout>
       </widget>
      </widget>
     </widget>
    </item>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menuBar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>545</width>
     <height>22</height>
    </rect>
   </property>
  </widget>
  <widget class="QToolBar" name="mainToolBar">
   <attribute name="toolBarArea">
    <enum>TopToolBarArea</enum>
   </attribute>
   <attribute name="toolBarBreak">
    <bool>false</bool>
   </attribute>
  </widget>
  <widget class="QStatusBar" name="statusBar"/>
 </widget>
 <layoutdefault spacing="6" margin="11"/>
 <resources/>
 <connections/>
</ui>