qtresizeqt-designerqtablewidget

Qt Designer | Stretch column of table to fullest


I am creating a simple GUI using Qt4 Designer. I added a QTableWidget to my Dialog . I need only one column in my table and I want this column to stretch itself to the maximum width. But it seems to be of fixed width.

I tried setting setting property horizontalHeaderStretchLastSection to true from the editor but its not helping. Can anyone please advise me which property should I be editing ?

Below is the screenshot .enter image description here

Below are rest of the properties of QTableWidget that I am using.

  <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>

Solution

  • You are confusing the vertical header with the first column. If you want a table with just one column that fills the whole width, hide the vertical header and stretch the last column of the horizontal header:

    screenshot

    Then you should edit the table items, adding one column (say, called "First Column") and however many rows you need (it doesn't matter what you call those). This will enable the Items tab, where you can add the actual table contents. With that done, your table should look like this:

    screenshot

    I think it's worth pointing out here, though, that a one-column table with no headers is more or less equivalent to a ListWidget. So, given that a ListWidget has a much simpler API, maybe you should consider using that instead.