Hi there

For a list in my application I use a delegate that is derived from QStyledItemDelegate. In the paint method I'd like to handle the selection of the items in the list.

Now I'm doing it like this:
Qt Code:
  1. void MembersListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
  2. if(!index.isValid())
  3. return;
  4.  
  5. painter->save();
  6. painter->setRenderHint(QPainter::Antialiasing);
  7.  
  8. QStyleOptionViewItemV4 opt = option;
  9. QStyledItemDelegate::initStyleOption(&opt, index);
  10. QRect rect = opt.rect;
  11.  
  12. // handle selection
  13. if(option.state & QStyle::State_Selected){
  14. painter->save();
  15.  
  16. QBrush selectionBrush(Qt::green);
  17. painter->setBrush(selectionBrush);
  18. painter->drawRoundedRect(rect.adjusted(1,1,-1,-1), 5, 5);
  19.  
  20. painter->restore();
  21. }
  22.  
  23. // ...
  24. painter->restore();
  25. }
To copy to clipboard, switch view to plain text mode 

But the selection doesn't look exactly the same as the default one which is used when no delegate is set. How can I use the standard selection in my delegate.

Btw: I'm using Qt on Symbian (Nokia N8) where the background of the list has black color and the selection is a green rounded rect with some kind of gradient.

Thanks!