Guilo
30th June 2010, 14:43
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();
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();
}
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
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();
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();
}
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