I am currently developing a GUI application using Qt 4.8. I have a label that displays text in white (the stylesheet has already been set up for this) and I want to change the color of the word "UPDATE" to red.
Here is my initial code:
//all text in white
QString text(QString::fromUtf8(" Are you sure you want to UPDATE this?\n Something will happen."));
myLabel->setText(text);
To change the color of the word, I know that it can be done with CSS like this:
//all text in white except UPDATE that will be in red
QString text(QString::fromUtf8(" Are you sure you want to<font color=\"#f00\">UPDATE</font> this?\n Something will happen."));
myLabel->setText(text);
Yes, it works... but there is a problem: after the word "this?" there is a "\n" which divides the line into two parts. In the first case, it works perfectly, but when applying the CSS in the second case, the program seems to ignore the '\n' causing me to manually add the separation in the label (as I cannot use two labels).
I have attempted to separate it by:
QString text(QString::fromUtf8("Are you sure you want to"));
text.append(QString::fromUtf8("<font color=\"#f00\">UPDATE</font>"));
text.append(QString::fromUtf8("this?\n Something will happen."));
However, I encountered the same issue...
Any suggestions on what I may be doing wrong, what I might be missing, or how to solve this problem?
Thank you for your help!