Hi guys,

I'm trying to polish a small tool I wrote and therefore want to implement an item delegate for my list view.

Scenario:
There's a QStandardItemModel which is assigned to the list view. The view also has a delegate.
I just added to items to the model which are shown without any problem.

Issue:
There's something wrong with the hovering background color. Please see my code below.

Qt Code:
  1. painter->setPen(Qt::NoPen);
  2. painter->setBrush(QColor(0, 0, 255));
  3.  
  4. if(option.state & QStyle::State_MouseOver)
  5. {
  6. painter->setBrush(QColor(255, 0, 0));
  7. }
  8.  
  9. painter->drawRect(option.rect);
  10.  
  11. painter->setPen(fontColor);
  12. painter->drawText(option.rect.left() + 5, option.rect.top() + option.rect.height() / 2 + 4, qvariant_cast<QString>(index.data()));
To copy to clipboard, switch view to plain text mode 

The item's text is drawn correctly at the desired position. But the background is drawn over both items.

The sizeHint() return this:
Qt Code:
  1. return QSize(option.rect.width(), 20);
To copy to clipboard, switch view to plain text mode 

I'm sure I'm missing something or am doing something wrong.
Could anybody please shed some light? :-)

Thanks in advance.