How Paint a background section in a QHeaderView?
Solved
General and Desktop
-
wrote on 4 Apr 2023, 15:44 last edited by leonardo M B 4 Apr 2023, 15:45
So I was trying to color the background of certain cells based on the data on them, will implement the logic later. The problem Now Is that in the code below fillrect paints everything and erases the text of the header section. How Can I paint the text and the background color?
void ResizableVerticalHeader::paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const { painter->save(); QHeaderView::paintSection(painter, rect, logicalIndex); painter->restore(); painter->fillRect(rect, QBrush(QColor(0xE1, 0xFF, 0x3C))); }
-
So I was trying to color the background of certain cells based on the data on them, will implement the logic later. The problem Now Is that in the code below fillrect paints everything and erases the text of the header section. How Can I paint the text and the background color?
void ResizableVerticalHeader::paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const { painter->save(); QHeaderView::paintSection(painter, rect, logicalIndex); painter->restore(); painter->fillRect(rect, QBrush(QColor(0xE1, 0xFF, 0x3C))); }
Lifetime Qt Championwrote on 4 Apr 2023, 15:47 last edited by Christian Ehrlicher 4 Apr 2023, 15:49Since you don't call the base class impl - what do you expect?
Overrride initStyleOption() and set the desired color for QPalette::Window or even better override initStyleOptionForIndex()
-
-
2/2