c – QTabWidget拒绝自动调整大小

我试图在qtcreator中有以下布局:

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

具有sizePolicy的每个控件都设置为“扩展”.尽管如此,标签小部件和我放在该页面小部件上的任何其他内容都不会被自动调整.

我是Qt的新手,请原谅我,如果这是一个明显的解决方案.谢谢.

解决方法:

这是重复的
How to make a Qt Widget grow with the window size?

我认为它是重复的,因为如果你的小部件树中的每个项目都有一个布局,我在Qt 4.7上的测试给出了以下输出,右边是我的对象检查器.
我刚刚放入小部件并对它们进行了布局,我没有改变任何尺寸的东西来扩展,因为这绝对没必要!

左边是正在运行的exe,右边是Creator截图.
这是我的用户界面:

    <?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>
上一篇:python – 如何选择选项卡小部件时连接事件?


下一篇:c – 未检测到QTabWidget的信号