Hi !
I am using a custom delegate to display my qlistview. Indeed, I want each of the items to be written on two lines and using html syntax to highlight it. No need for editing the items so I have just reimplemented the painter method :
void AlertDelegate
::paint (QPainter *painter,
const QStyleOptionViewItem
& option,
const QModelIndex
& index
) const {
painter->save();
doc.setHtml( index.data().toString() );
doc.setPageSize(option.rect.size());
painter->translate(option.rect.x(), option.rect.y());
doc.documentLayout()->draw(painter, context);
painter->restore();
}
void AlertDelegate::paint (QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const {
painter->save();
QTextDocument doc;
doc.setHtml( index.data().toString() );
QAbstractTextDocumentLayout::PaintContext context;
doc.setPageSize(option.rect.size());
painter->translate(option.rect.x(), option.rect.y());
doc.documentLayout()->draw(painter, context);
painter->restore();
}
To copy to clipboard, switch view to plain text mode
But the problem is that the first line of the second item is written on the second line of the first item. Where is the problem ?
Thanks
Bookmarks