PDA

View Full Version : Change text color of one word in QMessageBox message



dennisvz
13th September 2019, 16:50
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>




box.setText("*************************************************"
"\n A FREE update is available."
"\n************************************************ *"

Thanks

d_stranz
13th September 2019, 17:35
Read up on Qt's Rich Text format (https://doc.qt.io/qt-5/richtext.html) and the subset of HTML it supports. But you do have to write correct HTML:



<font color="red">blah, blah, blah</font>


Qt widgets that support Rich Text usually will auto-detect it, but you can force it by setting the textFormat() to Qt:: RichText.