【问题标题】:QTabWidget Content Not ExpandingQTabWidget 内容未扩展
【发布时间】:2014-12-12 14:47:43
【问题描述】:

附件是与我的问题有关的 QT 设计器示例。我的目标是让里面的任何内容(特别是 lineEdit)扩展到 QTabWidget 的最右边

如果您注意到我在图片中选择了选项卡,并且显示当前没有布局(如其上的红色禁止吸烟符号所示)。 当我尝试使用选项卡上方的按钮向其添加布局时(对于水平、垂直、网格、表单等),无论我做什么都不会更改选项卡布局,但更改最顶层的小部件布局,而不是,这是我不想要的,因为这使 QTabWidget 能够承受任何大小的窗口。

我尝试为选项卡中的元素提供水平和垂直布局,认为这可能有效,但正如我的下一张附加图片所示,它也不起作用。我的预感是因为选项卡没有布局,里面的任何布局都不会被尊重。

感谢任何帮助。我已经花了好几个小时,但我这辈子都想不通......!

以下是 UI XML:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>xMarket</class>
 <widget class="QWidget" name="xMarket">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>737</width>
    <height>421</height>
   </rect>
  </property>
  <property name="sizePolicy">
   <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
    <horstretch>0</horstretch>
    <verstretch>0</verstretch>
   </sizepolicy>
  </property>
  <property name="windowTitle">
   <string>Form</string>
  </property>
  <property name="layoutDirection">
   <enum>Qt::LeftToRight</enum>
  </property>
  <layout class="QHBoxLayout" name="horizontalLayout">
   <item>
    <widget class="QTabWidget" name="xMarketTabWidget">
     <property name="layoutDirection">
      <enum>Qt::LeftToRight</enum>
     </property>
     <widget class="QWidget" name="tab">
      <attribute name="title">
       <string>Tab 1</string>
      </attribute>
      <widget class="QLineEdit" name="lineEdit">
       <property name="geometry">
        <rect>
         <x>240</x>
         <y>30</y>
         <width>113</width>
         <height>21</height>
        </rect>
       </property>
      </widget>
      <widget class="QLabel" name="label">
       <property name="geometry">
        <rect>
         <x>150</x>
         <y>30</y>
         <width>59</width>
         <height>16</height>
        </rect>
       </property>
       <property name="text">
        <string>Search:</string>
       </property>
      </widget>
     </widget>
     <widget class="QWidget" name="tab_2">
      <attribute name="title">
       <string>Tab 2</string>
      </attribute>
     </widget>
    </widget>
   </item>
  </layout>
 </widget>
 <resources/>
 <connections/>
</ui>

【问题讨论】:

    标签: c++ xml user-interface qt5 qt-designer


    【解决方案1】:

    要设置选项卡上的布局,您首先需要选择其父选项卡小部件。

    您可以通过在对象检查器中按名称选择它(即通过单击您的示例中的xMarketTabWidget或单击其选项卡条中的相应选项卡来执行此操作。父选项卡小部件必须在其周围有一个选择矩形,然后您才能在其中一个选项卡上设置布局。

    完成后,您可以单击设计器工具栏上的水平布局或在网格中布局按钮为您的选项卡设置适当的布局。但请注意,一个选项卡必须至少有一个子窗口小部件,然后才能在其上设置布局 - 对于空选项卡,布局按钮将全部禁用。

    【讨论】:

    • 这行得通,我发誓我以前试过这个,但这样做确实让我可以正确设置布局。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-05
    • 2017-02-24
    相关资源
    最近更新 更多