PDA

View Full Version : How to use rich text in a QComboBox?



aarunt1
19th March 2010, 12:12
I am trying to use rich text in a QComboBox but it does not support it. Perhaps I should write a subclass? But I am unsure on what I would need to override as I have never done anything like this before. Please help. Thanks!

Lykurg
19th March 2010, 12:27
Well, you have just to write your own item delegate with a proper paint method. For drawing rich text see QTextDocument. Then set the delegate to your box using QComboBox::setItemDelegate().

aarunt1
19th March 2010, 20:06
Thanks for the reply! I am unsure what you mean by delegate and wouldn't know how to add rich text using the QTextDocument. Could you please elaborate. Thank you.

Lykurg
19th March 2010, 20:20
For delegate see QComboBox::setItemDelegate() and read about Qt's Model/View Programming.
For rich text: Use QTextDocument read in the docs about Rich Text Document Structure. After you set your document up use QTextDocument::drawContents() to draw the content in your QAbstractItemDelegate::paint() method.