[Qt-interest] How to render basic HTML in QTreeView cells?

Josiah Bryan jbryan at productiveconcepts.com
Tue Sep 29 02:56:24 CEST 2009


Paul Colby wrote:
> Hi,
>
> I want to use Qt's basic HTML support within some QTreeView cells, and
> I'm trying to figure out the best / right way to do it.
>
> I've worked out that using QTreeView:setIndexWidget() with a widget
> that supports HTML text (eg QLabel, QTextEdit, etc) works - albeit
> with a number of issues (that are hopefully solvable).
>
> However, I'm also thinking that it might be better to simply override
> QStyledItemDelegate::paint() to paint HTML text directly, but I can't
> see how to paint HTML text there.
>   
Paul,

I'm not sure of QTextView specific paiting, but I am familiar with 
painting HTML - see QTextDocument::drawContents(QPainter*,const QRectF&).

Something like:

QTextDocument doc;
doc.setHTML("<b>Hello</b> <i>World</i>!");
doc.drawContents(painter);

HTH.

Regards,
-josiah




More information about the Qt-interest-old mailing list