PDA

View Full Version : coloring the QString



riarioriu3
27th September 2012, 07:28
QString text("<FONT COLOR=red>%1</FONT>");
text.arg(strMat);
QDomNode text_node
text_node.setNodeValue(text);

i have the above code . what i want is text color shall be red and that text value shall be decided during the run time .

ChrisW67
27th September 2012, 09:18
what i want is text color shall be red and that text value shall be decided during the run time .

You should make an effort to describe the problem and analyse what each step of your code is doing (or not doing). Do this quite often leads to seeing your own mistake.

You are discarding the result of the function call at line 2. The value of 'text' at line 4 is the same as line 1.

pradeepreddyg95
27th September 2012, 10:21
QString pmsg;
pmsg = tr("<font color = red >Hello qt ..!!.\n"" </font size = 11 >");
ui->label->setText(pmsg);

above code will print the text in red colour

ChrisW67
27th September 2012, 23:20
above code will print the text in red colour
Yes. So?

If you are going to use HTML fragments to do rich text at least try to feed Qt valid HTML. What do you expect the attribute on the element end tag are going to do?