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:
- This code executes after all of the data has been (successfully) populated in the tableModel.
- The tableView is a bog standard QTableView
- The TeamTableHeaderView is a custom type inherited from QHeaderView which only implements sizeHint(). Currently it just returns QHeaderView::sizeHint(). There is nothing special about this class yet.
- The entitlementLicenseModelMap is a bit strange, but irrelevent to this question I believe. That whole for loop you can treat as just setting a table model. That table model is a QStandardItemModel.
- Earlier in the code, a custom delegate is set to the model. However this delegate is not yet implemented. It is only set in order to later do some painting stuff. It inherits from QStyledItemDelegate, and only implements the paint function, which currently only saves the painter, calls QStyledItemDelegate::paint(...) and then restores the painter. I don't believe this delegate is relevant, but happy to be corrected.