Josh Viggiani
Josh Viggiani

Reputation: 131

C++ QT tableView not displaying header labels after setting a custom header

I am working with a tableView and trying to implement some size styling.

The code:

    // Setup table header items 
Views::TeamTableHeaderView *header = new Views::TeamTableHeaderView(Qt::Horizontal);
ui->tableView->setHorizontalHeader(header);
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui->tableView->horizontalHeader()->setStretchLastSection(true);
ui->tableView->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter | (Qt::Alignment)Qt::TextWordWrap);
for(auto& tableModel : entitlementLicenseModelMap)
{
    tableModel->setHorizontalHeaderLabels({"PRODUCT", "TOTAL SEATS", "VALID UNTIL"});
}

This does not display any header on the table at all. When the call to setHorizontalHeader(header) is removed, the header displays fine. However, the header is too thin to render the text without cutting it off, hence I require a custom header (TeamTableHeaderView) to implement the sizeHint() to make it taller.

I have tried moving the setting of the header labels before and after, but the issue is that the header is just mot displaying at all, not even with the default "1" "2" "3" labels.

Some information:

Upvotes: 0

Views: 791

Answers (1)

Josh Viggiani
Josh Viggiani

Reputation: 131

To anyone else encountering this you just need to manually call:

header->setVisible(true)

Why this is the case when the header is normally visible by default when not otherwise specified.

Upvotes: 1

Related Questions