I’m using a custom table model derived from QAbstractTableModel.
I’ve overwritter headerData() and I can change the font color for individual row-headers (or column-header, but I’m all about rows here) by returning the color on Qt::ForegroundRole
if(role == Qt::ForegroundRole)
return Qt::green;
But if I go for Qt::BackgroundRole to set the background color of the header cells, nothing happens.
if(role == Qt::BackgroundRole)
return Qt::red;
I set a breakpoint on the return and it is reached. But nothing happens 🙁
Any ideas on where I’m wrong?
AFAIK the role colours are equivalent to setting a palette colour, the
QStyledrawing the header cells is free to ignore it.I’ve had trouble using
QPaletteor style sheets to set arbitrary colours on widgets. Text tends to work, as do ‘window’ coloured backgrounds (aQPushButtonbackground for example), but text entry field backgrounds don’t (QLineEditfor example). But AFAIK it’s down to the particularQStyleimplementation, so will vary not only across widgets, but also across platforms. The only certain way to get things exactly how you want is to reimplementQStyle(a big job), or paint it manually inpaintEvent(..)(difficult to follow the currentQStyleand still lots of code).