This question is further development of this post and is different, though may seem similar as this one.
I am trying to reimplement QHeaderView::paintSection
, so that the background returned from the model would be honored. I tried to do this
void Header::paintSection(QPainter * painter, const QRect & rect, int logicalIndex) const
{
QVariant bg = model()->headerData(logicalIndex, Qt::Horizontal, Qt::BackgroundRole);
// try before
if(bg.isValid()) // workaround for Qt bug https://bugreports.qt.io/browse/QTBUG-46216
painter->fillRect(rect, bg.value<QBrush>());
QHeaderView::paintSection(painter, rect, logicalIndex);
// try after
if(bg.isValid()) // workaround for Qt bug https://bugreports.qt.io/browse/QTBUG-46216
painter->fillRect(rect, bg.value<QBrush>());
}
However, it didn't work - if I make QHeaderView::paintSection
call, nothing I draw with the painter is visible (I also tried drawing a diagonal line). If I remove QHeaderView::paintSection
call, the line and the background will be visible.
Making the fillRect
call before vs. after the QHeaderView::paintSection
doesn't make any difference.
I wonder, what is it that QHeaderView::paintSection
does that makes it impossible for me to draw something on top of it.
And whether there is a way to overcome it without reimplementing everythning what QHeaderView::paintSection
does?
All I need to do is to add a certain shade to a certain cell - I still want everything in the cell (text, icons, gradient background etc.) to be painted as it is now...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…