Search code examples
c++qtuser-interfaceqtablewidget

QTableWidget vertical and horizontal headers becoming invisible


I've added a table widget to a form and set the vertical and horizontal headers as visible in the property editor. However, they are sometimes invisible during actual execution. If I actually look at the UI file, it shows that the verticalHeaderVisible and horizontalHeaderVisible attributes are set to false, even though these attributes are set as true in the property editor. Is there another property that's conflicting with them?

Property Editor:

Property Editor

Result:

Result

UI File:

UI File


Solution

  • It seems you're affected by this bug. There is a response:

    Won't fix. When saving, Designer correctly queries QHeaderView::isVisible() which at that moments returns false although the (header) widget is visible due to some QWidget::isVisible() idiosyncrasy.

    So, if your headers somehow become invisible at the moment you save the file, 'false' values will be recorded. I don't know if it really happens in your ui file, but I think it's better not to rely on this strange behaviour. Add these lines to your form class constructor to make headers visible:

    ui->setupUi(this); // automatically generated
    ui->tableWidget->horizontalHeader()->setVisible(true);
    ui->tableWidget->verticalHeader()->setVisible(true);