Qt 6.11 is out! See what's new in the release
blog
Failed to change background color of table widget by QItemDelegate derived class
-
void MyTableItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem myOption = option; // not work myOption.palette.setColor(QPalette::All, QPalette::Background, Qt::red); drawBackground(painter, myOption, index); // works myOption.palette.setColor(QPalette::All, QPalette::Text, Qt::red); drawDisplay(painter, myOption, myOption.rect, "Hello"); }The text color can be changed, but the background color can't be changed.
How to change the background color? (Better in the paint function.)
Thanks. -
QPainter ::fillRect get it done, still confused why QItemDelegate ::drawBackground not work as expected.
-
instead of QPalette::All which doesn't exist in enum QPalette::ColorGroup
you can choose between :QPalette::Disabled QPalette::Active QPalette::Inactive QPalette::Normalwhat errors did you get?
-
I see in your code you use
QItemDelegate
and
QStyleOptionViewItemAFAIR they don't mix well.
Why are you not using QStyledItemDelegate?
-
@jronald
QStyledItemDelegate uses Qt::BackgroundRole