PDA

View Full Version : Different text block colours in QListView (QListWidget)



rippa
1st July 2008, 08:53
Is it possible to set different colours for text blocks in one list widget item in QListWidget (or any other widget not inherited from QTextDocument)?
I think its possible do this by redefining paint method in QListWidget(any other widget) but maybe there is a simpler way like using QSyntaxHighlighter in QTextDocument?

aamer4yu
1st July 2008, 10:13
Its possible using delegates. You need to use setItemDelegate() function and handle the coloring in delegate.

You can override drawDisplay() method of the delegate for ur rendering. And you can use syntax highlighter in your delegate :)

rippa
1st July 2008, 16:34
But is it possible to higlight blocks of text(single characters) in cases when i cant use delegates, for example in QLabel or QLineEdit?

jpn
1st July 2008, 16:56
But is it possible to higlight blocks of text(single characters) in cases when i cant use delegates, for example in QLabel or QLineEdit?
QLabel supports rich text, QLineEdit doesn't.

jgoday
1st July 2008, 17:01
But is it possible to higlight blocks of text(single characters) in cases when i cant use delegates, for example in QLabel or QLineEdit?

instead of qlineedit you can use QTextEdit if you want rich text

rippa
1st July 2008, 17:21
So the idea is to delegate(use ditrectly) QTextDocument (QTextEdit) if its possible and use QSyntaxHighlighter with it and it is impossible without overriding paint method to highlight text blocks in objects that dont inhererit from QTextDocument?

rippa
1st July 2008, 20:34
Thanks to all. Done it with delegating QTextEdit to my ListWidget.