title: In a QStyledItemDelegate for a QListWidget, how do I paint the selected item to match the standard list?
body: <p>I have a QStyledItemDelegate for my QList widget:</p>
  
  <pre><code>class MappingDisplayWidgetDelegate: public QStyledItemDelegate
  {
      Q_OBJECT
  public:
      MappingDisplayWidgetDelegate(QObject *parent=NULL);
      virtual void paint ( QPainter * painter, const QStyleOptionViewItem &amp; option, const QModelIndex &amp; index ) const;
      virtual QSize sizeHint ( const QStyleOptionViewItem &amp; option, const QModelIndex &amp; index ) const;
  };
  </code></pre>
  
  <p>and it's paint method looks like:</p>
  
  <pre><code>void MappingDisplayWidgetDelegate::paint ( QPainter * painter,
                                             const QStyleOptionViewItem &amp; option,
                                             const QModelIndex &amp; index ) const
  {
      if (option.state &amp; QStyle::State_Selected)
          painter-&gt;fillRect(option.rect, option.palette.highlight());
      else if (option.state &amp; QStyle::State_MouseOver)
          painter-&gt;fillRect(option.rect, option.palette.midlight());
  
  
      QFontMetrics fm(option.font);
  
      QString filename = index.data(Qt::DisplayRole).toString();
  
      QRect outline = option.rect;
      int outmid = outline.center().y();
  
      QRect fnBound = fm.boundingRect(filename);
      int fnBoundMid = fnBound.center().y();
      fnBound.moveLeft(outline.left());
      fnBound.translate(0, outmid - fnBoundMid);
  
      painter-&gt;drawText(fnBound, Qt::AlignVCenter | Qt::AlignLeft, filename);
  
  }
  </code></pre>
  
  <p>Now this works, BUT the handling of the State_Selected and State_MouseOver doesn't produce the same results as the default lists. Here's a screen shot (I'm running on a Win7 system) of the code above on the left, and a standard QListWidget on the right. You can see that the QListWidget has nice gradients, while my items have only simple colors.</p>
  
  <p><img src="https://i.stack.imgur.com/YBn8S.png" alt="enter image description here"> </p>
  
  <p>I want to paint my items to properly match the standard widgets, but I can't quite figure out how. I'm not seeing anything in the options that would give me the info I need.</p>
  
  <p>Edited to add:
  Note that this is a somewhat toy example. The real code has a bunch of other stuff besides the one string, and has an appropriate (and working) sizeHint function. This is just a toy to demonstrate the problem.</p>