Вам также необходимо переопределить делегат элемента.
class ColoredItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit ColoredItemDelegate(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
void ColoredItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
if (option.state.testFlag(QStyle::State_Selected))
{
QStyleOptionViewItem newOption(option);
newOption.palette.setBrush(QPalette::Normal, QPalette::Highlight,
index.data(Qt::BackgroundRole).value<QBrush>());
QStyledItemDelegate::paint(painter, newOption, index);
return;
}
QStyledItemDelegate::paint(painter, option, index);
}