If you want custom painting then you have to do the work to honour selections and the like and adjust the colours accordingly. You use the data in the QStyleOptionViewItem to achieve that, e.g:
// something like this
painter->save();
if (option.
state & QStyle::State_Selected) { painter->fillRect(option.rect, option.palette.highlight());
painter->setPen(...); // use option.palette.highlightedText()
painter->drawText(...);
}
else {
painter->fillRect(option.rect, option.palette.base());
painter->setPen(...); // use option.palette.text()
painter->drawText(...);
}
painter->restore();
// something like this
painter->save();
if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.highlight());
painter->setPen(...); // use option.palette.highlightedText()
painter->drawText(...);
}
else {
painter->fillRect(option.rect, option.palette.base());
painter->setPen(...); // use option.palette.text()
painter->drawText(...);
}
painter->restore();
To copy to clipboard, switch view to plain text mode
That's why I suggested just overriding QStyledItemDelegate::displayText() to change just the text that the default delegate painting then renders.
Bookmarks