A sorry, I didn't notice that he wants different colors for different nodes of tree (my fault).
So he have to deliver own delegate like you said.
anyway it still quite simple. Subclass QStyledItemDelegate and override paint method like that:
{
if (index.
data(someRole
).
toInt()==1 && option.
state.
testFlag(QStyle::State_Selected)) { newOption.
palette.
setBrush(QPalette::Normal,
QPalette::Highlight , someOtherBrush
);
QStyledItemDelegate::paint(painter, newOption, index);
return;
}
QStyledItemDelegate::paint(painter, option, index);
}
void QStyledItemDelegate::paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
if (index.data(someRole).toInt()==1 && option.state.testFlag(QStyle::State_Selected)) {
QStyleOptionViewItem newOption(option);
newOption.palette.setBrush(QPalette::Normal, QPalette::Highlight , someOtherBrush);
QStyledItemDelegate::paint(painter, newOption, index);
return;
}
QStyledItemDelegate::paint(painter, option, index);
}
To copy to clipboard, switch view to plain text mode
Bookmarks