QstackedWidget在垂直排列时为箭头添加空间

时间:2013-02-27 13:40:32

标签: qt qt-designer

我有一个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>377</width>
    <height>600</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
     <widget class="QStackedWidget" name="top_pages">
      <property name="currentIndex">
       <number>0</number>
      </property>
      <widget class="QFrame" name="page">
       <layout class="QVBoxLayout" name="verticalLayout_2">
        <item>
         <widget class="QStackedWidget" name="stackedWidget_2">
          <property name="currentIndex">
           <number>1</number>
          </property>
          <widget class="QWidget" name="page_3">
           <layout class="QVBoxLayout" name="verticalLayout_3">
            <item>
             <widget class="QGroupBox" name="groupBox">
              <property name="title">
               <string>GroupBox</string>
              </property>
              <property name="alignment">
               <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
              </property>
              <layout class="QVBoxLayout" name="verticalLayout_4"/>
             </widget>
            </item>
           </layout>
          </widget>
          <widget class="QWidget" name="page_4">
           <layout class="QVBoxLayout" name="verticalLayout_5">
            <item>
             <widget class="QGroupBox" name="groupBox_2">
              <property name="sizePolicy">
               <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
                <horstretch>0</horstretch>
                <verstretch>0</verstretch>
               </sizepolicy>
              </property>
              <property name="title">
               <string>GroupBox</string>
              </property>
              <layout class="QVBoxLayout" name="verticalLayout_6"/>
             </widget>
            </item>
           </layout>
          </widget>
         </widget>
        </item>
       </layout>
      </widget>
      <widget class="QFrame" name="page_2"/>
     </widget>
    </item>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>377</width>
     <height>19</height>
    </rect>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

我希望组合框显示在整个窗口中(组合框文本位于菜单下方。当我在应用程序中构建它并在qt设计器预览中查看时,它在顶部留下了一个空格箭头top_pages的位置。如何让组合框扩展到这个空间?我可以打破布局并将其扩展到这个空间但我认为这需要对stackedWidget_2的每一页执行此操作。

2 个答案:

答案 0 :(得分:1)

<?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>676</width>
    <height>595</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QHBoxLayout" name="horizontalLayout">
    <item>
     <widget class="QGroupBox" name="groupBox">
      <property name="title">
       <string>GroupBox</string>
      </property>
      <layout class="QVBoxLayout" name="verticalLayout">
       <item>
        <widget class="QLabel" name="label">
         <property name="frameShape">
          <enum>QFrame::NoFrame</enum>
         </property>
         <property name="text">
          <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;Some text &lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
         </property>
        </widget>
       </item>
       <item>
        <widget class="QStackedWidget" name="top_pages">
         <property name="frameShape">
          <enum>QFrame::Panel</enum>
         </property>
         <property name="currentIndex">
          <number>1</number>
         </property>
         <widget class="QFrame" name="page">
          <layout class="QVBoxLayout" name="verticalLayout_2"/>
         </widget>
         <widget class="QFrame" name="page_2"/>
        </widget>
       </item>
      </layout>
     </widget>
    </item>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>676</width>
     <height>18</height>
    </rect>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

我认为这就是你想要创造的东西。有几个堆栈小部件。我做了一个。只是为了指示我已经在堆叠小部件周围添加了框架。它可以很容易地从属性中删除

答案 1 :(得分:1)

这是否会产生您想要实现的布局?

<?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>377</width>
    <height>600</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QVBoxLayout" name="verticalLayout">
    <property name="topMargin">
     <number>0</number>
    </property>
    <item>
     <widget class="QStackedWidget" name="top_pages">
      <property name="currentIndex">
       <number>0</number>
      </property>
      <widget class="QFrame" name="page">
       <layout class="QVBoxLayout" name="verticalLayout_2">
        <property name="topMargin">
         <number>0</number>
        </property>
        <item>
         <widget class="QStackedWidget" name="stackedWidget_2">
          <property name="currentIndex">
           <number>1</number>
          </property>
          <widget class="QWidget" name="page_3">
           <layout class="QVBoxLayout" name="verticalLayout_3">
            <property name="topMargin">
             <number>0</number>
            </property>
            <item>
             <widget class="QGroupBox" name="groupBox">
              <property name="title">
               <string>GroupBox</string>
              </property>
              <property name="alignment">
               <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
              </property>
              <layout class="QVBoxLayout" name="verticalLayout_4"/>
             </widget>
            </item>
           </layout>
          </widget>
          <widget class="QWidget" name="page_4">
           <layout class="QVBoxLayout" name="verticalLayout_5">
            <item>
             <widget class="QGroupBox" name="groupBox_2">
              <property name="sizePolicy">
               <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
                <horstretch>0</horstretch>
                <verstretch>0</verstretch>
               </sizepolicy>
              </property>
              <property name="title">
               <string>GroupBox</string>
              </property>
              <layout class="QVBoxLayout" name="verticalLayout_6">
               <property name="topMargin">
                <number>0</number>
               </property>
              </layout>
             </widget>
            </item>
           </layout>
          </widget>
         </widget>
        </item>
       </layout>
      </widget>
      <widget class="QFrame" name="page_2"/>
     </widget>
    </item>
   </layout>
  </widget><?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>377</width>
    <height>600</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QVBoxLayout" name="verticalLayout">
    <property name="topMargin">
     <number>0</number>
    </property>
    <item>
     <widget class="QStackedWidget" name="top_pages">
      <property name="currentIndex">
       <number>0</number>
      </property>
      <widget class="QFrame" name="page">
       <layout class="QVBoxLayout" name="verticalLayout_2">
        <property name="topMargin">
         <number>0</number>
        </property>
        <item>
         <widget class="QStackedWidget" name="stackedWidget_2">
          <property name="currentIndex">
           <number>1</number>
          </property>
          <widget class="QWidget" name="page_3">
           <layout class="QVBoxLayout" name="verticalLayout_3">
            <property name="topMargin">
             <number>0</number>
            </property>
            <item>
             <widget class="QGroupBox" name="groupBox">
              <property name="title">
               <string>GroupBox</string>
              </property>
              <property name="alignment">
               <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
              </property>
              <layout class="QVBoxLayout" name="verticalLayout_4"/>
             </widget>
            </item>
           </layout>
          </widget>
          <widget class="QWidget" name="page_4">
           <layout class="QVBoxLayout" name="verticalLayout_5">
            <item>
             <widget class="QGroupBox" name="groupBox_2">
              <property name="sizePolicy">
               <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
                <horstretch>0</horstretch>
                <verstretch>0</verstretch>
               </sizepolicy>
              </property>
              <property name="title">
               <string>GroupBox</string>
              </property>
              <layout class="QVBoxLayout" name="verticalLayout_6">
               <property name="topMargin">
                <number>0</number>
               </property>
              </layout>
             </widget>
            </item>
           </layout>
          </widget>
         </widget>
        </item>
       </layout>
      </widget>
      <widget class="QFrame" name="page_2"/>
     </widget>
    </item>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>377</width>
     <height>23</height>
    </rect>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>377</width>
     <height>23</height>
    </rect>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

我所做的只是浏览所有小部件,并通过在对象编辑器中选择它们将其布局的上边距缩小为0(centralWidgetpagepage_3,{{1} }),并在属性编辑器中修改其布局属性。不需要布局。