我在Centralwidget中并排有一个QGroupBox和QTabWidget,并且希望QGroupBox具有固定的宽度和扩展的高度,并且希望QTabWidget具有扩展的宽度和高度。
当我为中央部件设置水平布局时,出现了问题。一切正常,但我的QGroupBox宽度缩小。
如何在保持小部件的可扩展性的同时防止这种缩小的发生?
带有最小的.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>640</width>
<height>313</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="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>GroupBox</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>140</y>
<width>231</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>This text is supposed to be visible in its entirety.</string>
</property>
</widget>
</widget>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Tab 1</string>
</attribute>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Tab 2</string>
</attribute>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
要解决您的问题,请为组框设置一个布局,它将自动调整大小以正确显示其内容:确保
至少组框中存在一个小部件,右键单击该组的空白区域框,然后在“布局”子菜单中选择一个布局管理器。