Hi,
have used the code of marcel creating a qtrewidget with word-wrap function and it works nice. The next step should be display html text instead of plain text like now. I have used the following code in overridden paint():

Qt Code:
  1. painter->save();
  2. doc.setHtml(index.data().toString());
  3. QAbstractTextDocumentLayout::PaintContext context;
  4. doc.setPageSize(option.rect.size());
  5. painter->translate(option.rect.x(), option.rect.y());
  6. doc.documentLayout()->draw(painter, context);
  7. painter->restore();
To copy to clipboard, switch view to plain text mode 

( instead of painter->drawText() ) but with no luck: the treeWidget is illegible.

Any hint?

Some code:
delegate.cpp
Qt Code:
  1. void delegate::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. // painter->drawText(option.rect, Qt::AlignLeft | Qt::TextWordWrap, index.data().toString());
  11. }
  12.  
  13. QSize delegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
  14. {
  15. QTreeWidget *p = (QTreeWidget*)parent();
  16. QFontMetrics fm(p->font());
  17.  
  18. float rw = float(p->viewport()->size().width());
  19. float tw = fm.width(index.data().toString());
  20. float ratio = tw/rw;
  21. int lines = int(ratio) + 1;
  22. return QSize(rw,lines*fm.height());
  23. }
To copy to clipboard, switch view to plain text mode 

Thanks