Results 1 to 4 of 4

Thread: How to use rich text in a QComboBox?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default How to use rich text in a QComboBox?

    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to use rich text in a QComboBox?

    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().

  3. #3
    Join Date
    Mar 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to use rich text in a QComboBox?

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to use rich text in a QComboBox?

    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.

Similar Threads

  1. Rich text in QGraphicsTextItem
    By maverick_pol in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2008, 20:08
  2. Rich Text in QTableWidgetItem
    By joshuajcarson in forum Qt Programming
    Replies: 9
    Last Post: 2nd September 2008, 15:49
  3. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 16:45
  4. Rich Text Format
    By Kapil in forum Newbie
    Replies: 1
    Last Post: 4th October 2006, 10:53
  5. Painting Rich Text
    By xanthine in forum Qt Programming
    Replies: 7
    Last Post: 15th April 2006, 23:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.