my icons are in different columns too so I would say this is exactly the same problem I had.
I solved it by deriving my own delegate class from QItemDelegate and reimplemented the paint() function. If you have a look at the paint function (qitemdelegate.cpp) you can see that the drawing of the text (drawDisplay) and icons (drawDecoration) is done in the last lines.
I replaced this code by mine.
[Edit] But when looking at it closer this works only for columns with just an icon.
When it worked I hadn't looked at it closer. The text will be printed below the icon in this case.[/Edit]
[Edit2] I removed the not complete working code but this should work better now:
//paint()
// draw the item
drawCheck(painter, opt, checkRect, checkState);
newRect.setTop(textRect.top());
newRect.setBottom(textRect.bottom());
newRect.setLeft(pixmapRect.left() );
newRect.setRight(textRect.left());
drawDecoration(painter, opt, pixmapRect, pixmap, newRect);
drawDisplay(painter, opt, textRect, text);
drawFocus(painter, opt, textRect);
//paint()
// draw the item
drawCheck(painter, opt, checkRect, checkState);
QRect newRect;
newRect.setTop(textRect.top());
newRect.setBottom(textRect.bottom());
newRect.setLeft(pixmapRect.left() );
newRect.setRight(textRect.left());
drawDecoration(painter, opt, pixmapRect, pixmap, newRect);
drawDisplay(painter, opt, textRect, text);
drawFocus(painter, opt, textRect);
To copy to clipboard, switch view to plain text mode
//new drawDecoration
{
if(!pixmap.isNull() && !rect.isEmpty())
{
if(option.
state & QStyle::State_Selected) {
bool enabled
= option.
state & QStyle::State_Enabled;
QPixmap *pm
= selected
(pixmap, option.
palette, enabled
);
painter
->fillRect
(newRect, option.
palette.
brush(cg,
QPalette::Highlight));
painter->drawPixmap(rect.topLeft(), *pm);
}
else
{
painter->drawPixmap(rect.topLeft(), pixmap);
}
}
}
//new drawDecoration
void ServerDelegate::drawDecoration(QPainter *painter, const QStyleOptionViewItem &option,
const QRect &rect, const QPixmap &pixmap, const QRect &newRect) const
{
if(!pixmap.isNull() && !rect.isEmpty())
{
if(option.state & QStyle::State_Selected)
{
bool enabled = option.state & QStyle::State_Enabled;
QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
QPixmap *pm = selected(pixmap, option.palette, enabled);
painter->fillRect(newRect, option.palette.brush(cg, QPalette::Highlight));
painter->drawPixmap(rect.topLeft(), *pm);
}
else
{
painter->drawPixmap(rect.topLeft(), pixmap);
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks