Solved QTablewidget in QTabwidget strange behaviour
-
Hi,
I have a tab widget with one only tab which contains a table, whose horizontal header I edited in the designer. After adding a new tab to the tabwidget, the vertical header of the table from the previous tab disappears. I recorder the strange behaviour to make myself clear :
https://youtu.be/RpqEpQmbJa8. -
Does look strange indeed, but I can't reproduce it.
Are you doing anything with the header from code? Can you provide the .ui file that you created? -
I also tried to reproduce it, but couldn't. I'm not doing anything with the header from code, and the constructor only has the setupUi line.
This is the .ui before adding new tab:<?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>791</width> <height>538</height> </rect> </property> <property name="minimumSize"> <size> <width>690</width> <height>0</height> </size> </property> <property name="windowTitle"> <string>MainWindow</string> </property> <property name="tabShape"> <enum>QTabWidget::Rounded</enum> </property> <widget class="QWidget" name="centralWidget"> <layout class="QFormLayout" name="formLayout_2"> <item row="0" column="0"> <layout class="QFormLayout" name="formLayout"> <property name="sizeConstraint"> <enum>QLayout::SetMinimumSize</enum> </property> <item row="0" column="0"> <widget class="QLabel" name="label"> <property name="text"> <string>Username</string> </property> <property name="buddy"> <cstring>userEdit</cstring> </property> </widget> </item> <item row="0" column="1"> <widget class="QLineEdit" name="userEdit"> <property name="text"> <string>guzfraba</string> </property> </widget> </item> <item row="1" column="0"> <widget class="QLabel" name="label_2"> <property name="text"> <string>Password</string> </property> <property name="buddy"> <cstring>passEdit</cstring> </property> </widget> </item> <item row="1" column="1"> <widget class="QLineEdit" name="passEdit"> <property name="text"> <string>nevermind</string> </property> <property name="echoMode"> <enum>QLineEdit::PasswordEchoOnEdit</enum> </property> </widget> </item> <item row="2" column="0"> <widget class="QPushButton" name="loginButton"> <property name="text"> <string>Login</string> </property> <property name="checkable"> <bool>true</bool> </property> </widget> </item> </layout> </item> <item row="0" column="1"> <widget class="QTabWidget" name="tabWidget"> <property name="minimumSize"> <size> <width>0</width> <height>500</height> </size> </property> <property name="styleSheet"> <string notr="true"/> </property> <property name="tabShape"> <enum>QTabWidget::Rounded</enum> </property> <property name="currentIndex"> <number>0</number> </property> <property name="elideMode"> <enum>Qt::ElideNone</enum> </property> <property name="tabsClosable"> <bool>false</bool> </property> <widget class="QWidget" name="tab"> <attribute name="title"> <string>Ressources</string> </attribute> <layout class="QVBoxLayout" name="verticalLayout"> <property name="spacing"> <number>0</number> </property> <property name="leftMargin"> <number>0</number> </property> <property name="topMargin"> <number>0</number> </property> <property name="rightMargin"> <number>0</number> </property> <property name="bottomMargin"> <number>0</number> </property> <item> <widget class="QTableWidget" name="ressTable"> <property name="enabled"> <bool>true</bool> </property> <property name="sizePolicy"> <sizepolicy hsizetype="Minimum" vsizetype="Expanding"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="focusPolicy"> <enum>Qt::NoFocus</enum> </property> <property name="contextMenuPolicy"> <enum>Qt::NoContextMenu</enum> </property> <property name="autoFillBackground"> <bool>false</bool> </property> <property name="styleSheet"> <string notr="true"/> </property> <property name="frameShape"> <enum>QFrame::WinPanel</enum> </property> <property name="frameShadow"> <enum>QFrame::Raised</enum> </property> <property name="lineWidth"> <number>0</number> </property> <property name="autoScroll"> <bool>true</bool> </property> <property name="showDropIndicator" stdset="0"> <bool>false</bool> </property> <property name="dragEnabled"> <bool>false</bool> </property> <property name="alternatingRowColors"> <bool>true</bool> </property> <property name="selectionMode"> <enum>QAbstractItemView::NoSelection</enum> </property> <property name="horizontalScrollMode"> <enum>QAbstractItemView::ScrollPerItem</enum> </property> <property name="gridStyle"> <enum>Qt::SolidLine</enum> </property> <property name="cornerButtonEnabled"> <bool>false</bool> </property> <property name="rowCount"> <number>20</number> </property> <property name="columnCount"> <number>5</number> </property> <attribute name="horizontalHeaderVisible"> <bool>true</bool> </attribute> <attribute name="horizontalHeaderCascadingSectionResizes"> <bool>false</bool> </attribute> <attribute name="horizontalHeaderShowSortIndicator" stdset="0"> <bool>false</bool> </attribute> <attribute name="horizontalHeaderStretchLastSection"> <bool>true</bool> </attribute> <attribute name="verticalHeaderVisible"> <bool>false</bool> </attribute> <attribute name="verticalHeaderDefaultSectionSize"> <number>22</number> </attribute> <attribute name="verticalHeaderStretchLastSection"> <bool>false</bool> </attribute> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <column> <property name="text"> <string>Village</string> </property> </column> <column> <property name="text"> <string>Wood</string> </property> </column> <column> <property name="text"> <string>Clay</string> </property> </column> <column> <property name="text"> <string>Iron</string> </property> </column> <column> <property name="text"> <string>Crop</string> </property> </column> </widget> </item> </layout> </widget> </widget> </item> </layout> </widget> <widget class="QStatusBar" name="statusBar"/> </widget> <layoutdefault spacing="6" margin="11"/> <resources/> <connections/> </ui>
Here the .ui after adding a new tab:
<?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>791</width> <height>538</height> </rect> </property> <property name="minimumSize"> <size> <width>690</width> <height>0</height> </size> </property> <property name="windowTitle"> <string>MainWindow</string> </property> <property name="tabShape"> <enum>QTabWidget::Rounded</enum> </property> <widget class="QWidget" name="centralWidget"> <layout class="QFormLayout" name="formLayout_2"> <item row="0" column="0"> <layout class="QFormLayout" name="formLayout"> <property name="sizeConstraint"> <enum>QLayout::SetMinimumSize</enum> </property> <item row="0" column="0"> <widget class="QLabel" name="label"> <property name="text"> <string>Username</string> </property> <property name="buddy"> <cstring>userEdit</cstring> </property> </widget> </item> <item row="0" column="1"> <widget class="QLineEdit" name="userEdit"> <property name="text"> <string>guzfraba</string> </property> </widget> </item> <item row="1" column="0"> <widget class="QLabel" name="label_2"> <property name="text"> <string>Password</string> </property> <property name="buddy"> <cstring>passEdit</cstring> </property> </widget> </item> <item row="1" column="1"> <widget class="QLineEdit" name="passEdit"> <property name="text"> <string>nevermind</string> </property> <property name="echoMode"> <enum>QLineEdit::PasswordEchoOnEdit</enum> </property> </widget> </item> <item row="2" column="0"> <widget class="QPushButton" name="loginButton"> <property name="text"> <string>Login</string> </property> <property name="checkable"> <bool>true</bool> </property> </widget> </item> </layout> </item> <item row="0" column="1"> <widget class="QTabWidget" name="tabWidget"> <property name="minimumSize"> <size> <width>0</width> <height>500</height> </size> </property> <property name="styleSheet"> <string notr="true"/> </property> <property name="tabShape"> <enum>QTabWidget::Rounded</enum> </property> <property name="currentIndex"> <number>1</number> </property> <property name="elideMode"> <enum>Qt::ElideNone</enum> </property> <property name="tabsClosable"> <bool>false</bool> </property> <widget class="QWidget" name="tab"> <attribute name="title"> <string>Ressources</string> </attribute> <layout class="QVBoxLayout" name="verticalLayout"> <property name="spacing"> <number>0</number> </property> <property name="leftMargin"> <number>0</number> </property> <property name="topMargin"> <number>0</number> </property> <property name="rightMargin"> <number>0</number> </property> <property name="bottomMargin"> <number>0</number> </property> <item> <widget class="QTableWidget" name="ressTable"> <property name="enabled"> <bool>true</bool> </property> <property name="sizePolicy"> <sizepolicy hsizetype="Minimum" vsizetype="Expanding"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="focusPolicy"> <enum>Qt::NoFocus</enum> </property> <property name="contextMenuPolicy"> <enum>Qt::NoContextMenu</enum> </property> <property name="autoFillBackground"> <bool>false</bool> </property> <property name="styleSheet"> <string notr="true"/> </property> <property name="frameShape"> <enum>QFrame::WinPanel</enum> </property> <property name="frameShadow"> <enum>QFrame::Raised</enum> </property> <property name="lineWidth"> <number>0</number> </property> <property name="autoScroll"> <bool>true</bool> </property> <property name="showDropIndicator" stdset="0"> <bool>false</bool> </property> <property name="dragEnabled"> <bool>false</bool> </property> <property name="alternatingRowColors"> <bool>true</bool> </property> <property name="selectionMode"> <enum>QAbstractItemView::NoSelection</enum> </property> <property name="horizontalScrollMode"> <enum>QAbstractItemView::ScrollPerItem</enum> </property> <property name="gridStyle"> <enum>Qt::SolidLine</enum> </property> <property name="cornerButtonEnabled"> <bool>false</bool> </property> <property name="rowCount"> <number>20</number> </property> <property name="columnCount"> <number>5</number> </property> <attribute name="horizontalHeaderVisible"> <bool>false</bool> </attribute> <attribute name="horizontalHeaderCascadingSectionResizes"> <bool>false</bool> </attribute> <attribute name="horizontalHeaderShowSortIndicator" stdset="0"> <bool>false</bool> </attribute> <attribute name="horizontalHeaderStretchLastSection"> <bool>true</bool> </attribute> <attribute name="verticalHeaderVisible"> <bool>false</bool> </attribute> <attribute name="verticalHeaderDefaultSectionSize"> <number>22</number> </attribute> <attribute name="verticalHeaderStretchLastSection"> <bool>false</bool> </attribute> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <row/> <column> <property name="text"> <string>Village</string> </property> </column> <column> <property name="text"> <string>Wood</string> </property> </column> <column> <property name="text"> <string>Clay</string> </property> </column> <column> <property name="text"> <string>Iron</string> </property> </column> <column> <property name="text"> <string>Crop</string> </property> </column> </widget> </item> </layout> </widget> <widget class="QWidget" name="tab_2"> <attribute name="title"> <string>Page</string> </attribute> </widget> </widget> </item> </layout> </widget> <widget class="QStatusBar" name="statusBar"/> </widget> <layoutdefault spacing="6" margin="11"/> <resources/> <connections/> </ui>
-
Huh, that's a weird one. It seems that switching tabs sets the
horizontaHeaderVisible
property to false, but only if the value was manually set earlier (i.e. displays in bold in the properties panel). Please report a designer bug at bugreports.qt.io
As a workaround you can set thehorizontaHeaderVisible
property to the default value (click on the property and then press the red arrow button that appears on the right side). The default istrue
so the header should stay visible. -
Thanks Chris. Reseting horizontaHeaderVisible to the default value solved the program.