{
painter->save();
painter->translate(option.rect.topLeft());
const QRect line
(0,
0, option.
rect.
width(), option.
rect.
height());
painter->setClipRect(line);
if(option.
state & QStyle::State_Selected) { painter
->fillRect
(option.
rect, option.
palette.
color(QPalette::Highlight));
}
QString txt
= index.
data(Qt
::DisplayRole).
toString();
QRect r
= QRect(PADDING,
0, option.
rect.
width() - PADDING, option.
rect.
height() - PADDING
);
r = painter->boundingRect(r, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, txt);
painter->drawText(r, Qt::AlignVCenter|Qt::AlignLeft|Qt::TextWordWrap, txt);
QImage ic
= QImage(qvariant_cast<QImage>
(index.
data(Qt
::DecorationRole)));
r
= QRect(0, PADDING
*2, PIC_WIDTH, PIC_HEIGHT
);
painter->drawImage(r, ic);
painter->restore();
}
void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter );
painter->save();
painter->translate(option.rect.topLeft());
const QRect line(0, 0, option.rect.width(), option.rect.height());
painter->setClipRect(line);
if(option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.color(QPalette::Highlight));
}
QString txt = index.data(Qt::DisplayRole).toString();
QRect r = QRect(PADDING, 0, option.rect.width() - PADDING, option.rect.height() - PADDING);
r = painter->boundingRect(r, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, txt);
painter->drawText(r, Qt::AlignVCenter|Qt::AlignLeft|Qt::TextWordWrap, txt);
QImage ic = QImage(qvariant_cast<QImage>(index.data(Qt::DecorationRole)));
r = QRect(0, PADDING*2, PIC_WIDTH, PIC_HEIGHT);
painter->drawImage(r, ic);
painter->restore();
}
To copy to clipboard, switch view to plain text mode
Bookmarks