Qt 设计师 |将表格的列拉伸到最大

问题描述 投票:0回答:1

我正在使用 Qt4 Designer 创建一个简单的 GUI。 我在 Dialog 中添加了一个 QTableWidget 。我的表格中只需要一列,并且我希望该列将自身拉伸到最大宽度。但它似乎是固定宽度的。

我尝试从编辑器中将属性

horizontalHeaderStretchLastSection
设置为
true
,但没有帮助。 谁能告诉我应该编辑哪个属性?

以下是截图。

下面是我正在使用的 QTableWidget 的其余属性。

  <widget class="QDialogButtonBox" name="buttonBox">
   <property name="geometry">
    <rect>
     <x>180</x>
     <y>460</y>
     <width>341</width>
     <height>32</height>
    </rect>
   </property>
   <property name="orientation">
    <enum>Qt::Horizontal</enum>
   </property>
   <property name="standardButtons">
    <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
   </property>
  </widget>
  <widget class="QTableWidget" name="tableWidget">
   <property name="geometry">
    <rect>
     <x>40</x>
     <y>70</y>
     <width>256</width>
     <height>192</height>
    </rect>
   </property>
   <property name="sizePolicy">
    <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
     <horstretch>0</horstretch>
     <verstretch>0</verstretch>
    </sizepolicy>
   </property>
   <property name="frameShadow">
    <enum>QFrame::Plain</enum>
   </property>
   <property name="midLineWidth">
    <number>1</number>
   </property>
   <attribute name="horizontalHeaderVisible">
    <bool>false</bool>
   </attribute>
   <attribute name="horizontalHeaderDefaultSectionSize">
    <number>107</number>
   </attribute>
   <attribute name="horizontalHeaderHighlightSections">
    <bool>true</bool>
   </attribute>
   <attribute name="horizontalHeaderStretchLastSection">
    <bool>true</bool>
   </attribute>
   <attribute name="verticalHeaderVisible">
    <bool>true</bool>
   </attribute>
   <attribute name="verticalHeaderShowSortIndicator" stdset="0">
    <bool>false</bool>
   </attribute>
   <attribute name="verticalHeaderStretchLastSection">
    <bool>false</bool>
   </attribute>
   <row>
    <property name="text">
     <string>New Row</string>
    </property>
   </row>
   <row>
    <property name="text">
     <string>rrr</string>
    </property>
   </row>
   <row>
    <property name="text">
     <string>gggg</string>
    </property>
   </row>
  </widget>
qt resize qt-designer qtablewidget
1个回答
2
投票

您将垂直标题与第一列混淆了。如果您想要一个只有一列填满整个宽度的表格,请隐藏垂直标题并拉伸水平标题的最后一列:

然后您应该编辑表格项目,添加一列(例如,称为“第一列”)以及您需要的任意多行(无论您如何称呼这些行)。这将启用 Items 选项卡,您可以在其中添加实际的表格内容。完成后,您的表格应如下所示:

不过,我认为这里值得指出的是,没有标题的单列表或多或少相当于 ListWidget。因此,考虑到 ListWidget 具有更简单的 API,也许您应该考虑使用它。

© www.soinside.com 2019 - 2024. All rights reserved.