Killian
10th October 2016, 09:54
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.
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(0, 0, 255));
if(option.state & QStyle::State_MouseOver)
{
painter->setBrush(QColor(255, 0, 0));
}
painter->drawRect(option.rect);
painter->setPen(fontColor);
painter->drawText(option.rect.left() + 5, option.rect.top() + option.rect.height() / 2 + 4, qvariant_cast<QString>(index.data()));
The item's text is drawn correctly at the desired position. But the background is drawn over both items.
The sizeHint() return this:
return QSize(option.rect.width(), 20);
I'm sure I'm missing something or am doing something wrong.
Could anybody please shed some light? :-)
Thanks in advance.
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.
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(0, 0, 255));
if(option.state & QStyle::State_MouseOver)
{
painter->setBrush(QColor(255, 0, 0));
}
painter->drawRect(option.rect);
painter->setPen(fontColor);
painter->drawText(option.rect.left() + 5, option.rect.top() + option.rect.height() / 2 + 4, qvariant_cast<QString>(index.data()));
The item's text is drawn correctly at the desired position. But the background is drawn over both items.
The sizeHint() return this:
return QSize(option.rect.width(), 20);
I'm sure I'm missing something or am doing something wrong.
Could anybody please shed some light? :-)
Thanks in advance.