Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
TableView Header problem
Qt 5.6. All working OK except for one small thing. In the headerData function I have:
if (role == Qt::BackgroundRole) return QBrush(Qt::lightGray);
but it doesn't happen. Everything else works fine. Anyone know why?
What do you mean by it doesn't happen ? The role is never
Qt::BackgroundRole? Or your brush has no effect ?
BrianE last edited by BrianE
I quote from QT 5.6 QHeaderView Class, section on appearance:
"Not all ItemDataRoles will have an effect on a QHeaderView. If you need to draw other roles, you can subclass QHeaderView and reimplement paintEvent(). QHeaderView respects the following item data roles: TextAlignmentRole, DisplayRole, FontRole, DecorationRole, ForegroundRole, and BackgroundRole."
So, BackgroundRole should give background colour to the headerview but mine stay white. I can change the font and I can change the foreground colour (text colour).
What OS are you running ?
I don't have such a machine at hand. Can you test that again using the fusion style ? You have an example here
Did that. It works! What is going on? Before I scream and pull what little hair I have left out could you offer a quick explanation. Other stuff looks different, too.
Setting the background role will modify the QPalette used for the painting and from the QPalette documentation, styles using native theme engines may not use the palette for all drawings.
OK. Thanks for that. Sanity has returned and I'll now go away and investigate palettes and styles and stuff.