PDA

View Full Version : Rich text in QListView



Fenix Voltres
2nd August 2010, 17:44
Hello, I've got a model with two columns of strings and I want to have them displayed in QListView as one rich formatted text - what is the simpliest solution? Do I have to extend QStyledItemDelegate in order to do that? Or insert QLabel into QListView?

Lykurg
2nd August 2010, 17:55
the easiest and best way would be a delegate as you mentioned. With it data function you can access both columns and paint them. If you want rich text support use a QTextDocument to render it (only when really needed).

Fenix Voltres
2nd August 2010, 21:27
OK, let's say that I did it - got my own delegate and it displays text as I wanted, BUT - do I have to rewrite whole painting? Is there any possibility to use it from QItemDelegate instead? (I mean selection rects etc., now my text disappears when has mouse over it.)

Lykurg
2nd August 2010, 21:36
(I mean selection rects etc., now my text disappears when has mouse over it.)Then first call the base class function and then do your painting. But better do all "yourself": See QStylePainter to get the job easier done.

Fenix Voltres
2nd August 2010, 23:16
Then first call the base class function and then do your painting.
Then I would have text rendered two times - as plain and rich at the same time. Thanks for the info, I'll check the QStylePainter class out.

Fenix Voltres
4th August 2010, 22:32
I found great solution here:
http://stackoverflow.com/questions/1956542/how-to-make-item-view-render-rich-html-text-in-qt