We have a very complicated custom coloring scheme for a delegate in a QTableWidget. We do need the SelectionModel though, so setSelectionMode(QAbstractItemView::NoSelection) is not an option.

I tried to overwrite the paint function like this:

Qt Code:
  1. void LineEditDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
  2. {
  3. QStyleOptionViewItemV4 noSelectionOption(option);
  4. initStyleOption(&noSelectionOption, index);
  5. noSelectionOption.showDecorationSelected = false;
  6.  
  7. QStyledItemDelegate::paint(painter, noSelectionOption, index);
  8. }
To copy to clipboard, switch view to plain text mode 

But the Texts in the cells are still drawn with blue background and white foreground.

How can I fix this?