Results 1 to 2 of 2

Thread: Change text color of one word in QMessageBox message

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2017
    Posts
    54
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Change text color of one word in QMessageBox message

    Below is a few lines of code from a QMessageBox message. I want ONLY the word FREE to appear in red. Possible?

    I tried: <font color = red> just before FREE and then </font> just after the word FREE, but it did not work (it just printed the words <font color = red> and </font>


    Qt Code:
    1. box.setText("*************************************************"
    2. "\n A FREE update is available."
    3. "\n*************************************************"
    To copy to clipboard, switch view to plain text mode 
    Thanks

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Change text color of one word in QMessageBox message

    Read up on Qt's Rich Text format and the subset of HTML it supports. But you do have to write correct HTML:

    Qt Code:
    1. <font color="red">blah, blah, blah</font>
    To copy to clipboard, switch view to plain text mode 

    Qt widgets that support Rich Text usually will auto-detect it, but you can force it by setting the textFormat() to Qt:: RichText.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 4
    Last Post: 19th July 2016, 20:10
  2. Replies: 3
    Last Post: 22nd January 2010, 17:46
  3. SETTING THE TEXT COLOR FOR QMessageBox
    By vinkakarun in forum Newbie
    Replies: 2
    Last Post: 5th November 2009, 17:32
  4. statusBar() message color change
    By mclark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2007, 00:20
  5. Replies: 2
    Last Post: 10th March 2007, 00:19

Tags for this Thread

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.