I'm trying to add color to the checkboxes in a QTreeView
, like so
I switched from a QStyledItemDelegate
to a QItemDelegate
to have a better control on the drawing process, mostly for the drawCheck
method. I can't get the painter to draw the colors I want though. Using css, I succeeded in changing the color of all checkboxes, but I need to choose the colors depending on some properties (unimportant here). Modifying the QStyle of the QTreeView may work but I will have the same "unique color" problem.
Modifying the painter or the option parameters do nothing.
painter->setPen(aRandomColor);
auto coloredOption = option;
coloredOption.backgroundBrush.setColor(aRandomColor);
QItemDelegate::drawCheck(painter, coloredOption, rect, state);
I understand that I can handle the complete drawing process in my own drawCheck
without calling QItemDelegate::drawCheck
const auto color = wathever;
draw square outline using color
draw filled square using color
// Do NOT call QItemDelegate::drawCheck(...)
but this will force an uniform feel on all OSes. Is there no way to ask for a background color? Like... paint what you were going to paint, but do it using {color}"?