PDA

View Full Version : QTreeWidgetItem + richtext



pfid
7th July 2009, 09:38
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 (http://www.qtcentre.org/forum/f-qt-programming-2/t-displaying-richtext-on-itemwidgets-15591.html/?highlight=richtext)



class RichDelegate : public QItemDelegate
{
public:

void 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->setClipRect( option.rect );
painter->translate(option.rect.x(), option.rect.y());
doc.documentLayout()->draw(painter, context);
painter->restore();
}
};


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

pfid
8th July 2009, 17:50
anyone? i just found out that setting the delegate on a QTreeView doesnt work neither, while with QTableView it works perfectly. whats wrong?