Results 1 to 2 of 2

Thread: QTreeWidgetItem + richtext

  1. #1
    Join Date
    Jul 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTreeWidgetItem + richtext

    Hi all,

    i already spent some time googling & searching the forums, but somehow i failed to come up with a working solution. what i'm trying to do is, to simply give a QTreeWidgetItem the ability to display richtext.

    However, i have some semi-working code i took from here: Link

    Qt Code:
    1. class RichDelegate : public QItemDelegate
    2. {
    3. public:
    4.  
    5. void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
    6. {
    7. painter->save();
    8. doc.setHtml( index.data().toString() );
    9. QAbstractTextDocumentLayout::PaintContext context;
    10. doc.setPageSize( option.rect.size());
    11. painter->setClipRect( option.rect );
    12. painter->translate(option.rect.x(), option.rect.y());
    13. doc.documentLayout()->draw(painter, context);
    14. painter->restore();
    15. }
    16. };
    To copy to clipboard, switch view to plain text mode 

    I think it might have some problems still with sizes, since i dont reimplement the sizeHint() method (i read about that in some of the various other richtext-delegate threads).
    this, however, is not my problem. the above code works for a QTableView, and the rows display richtext/html nicely. however, once i put

    treeWidget->setItemDelegateForColumn(2, new RichDelegate());

    my column in the treewidget wont display anything at all and will remain blank.
    what am i doing wrong? i could switch to QTreeView/model in case thats the only solution, but i would prefer sticking to my QTreeWidget if possible.

    any help appreciated

  2. #2
    Join Date
    Jul 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidgetItem + richtext

    anyone? i just found out that setting the delegate on a QTreeView doesnt work neither, while with QTableView it works perfectly. whats wrong?

Similar Threads

  1. Custom QTreeWidgetItem context menu?
    By AaronMK in forum Qt Programming
    Replies: 4
    Last Post: 1st February 2010, 04:42
  2. PyQt remove the current QTreeWidgetItem
    By koenux in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2009, 23:08
  3. Replies: 3
    Last Post: 26th April 2008, 18:42
  4. Replies: 4
    Last Post: 19th October 2007, 19:47
  5. QTreeWidgetItem swap or move up one level problem
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 24th September 2006, 18:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.