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 :

Qt Code:
  1. void AlertDelegate::paint (QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const {
  2.  
  3. painter->save();
  4. doc.setHtml( index.data().toString() );
  5. QAbstractTextDocumentLayout::PaintContext context;
  6. doc.setPageSize(option.rect.size());
  7. painter->translate(option.rect.x(), option.rect.y());
  8. doc.documentLayout()->draw(painter, context);
  9. painter->restore();
  10. }
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