Solved Change Label text color not working
-
I have gone through Qt forums and used different examples given for changing the color of Label text, unsuccessfully.
The following is One snippet found in one Qt forum, but giving error.
@
QColor colour = "red";
QString text;
text = "abcd";
QString format("<font color="%1">%2</font>");
Labelname->setText(format.arg(colour.name(), text));
@Error is "Invalid operand types " in
QString format("<font color="%1">%2</font>");
program line.another question is : is it possible to change background color of Label.
-
@o6a6r9v1p said in Change Label text color not working:
QString format("<font color="%1">%2</font>");
You need to escape ":
QString format("<font color=\"%1\">%2</font>");
-
you should look into QStyleSheet
for example this makes it a blue background with red letters:
ui->label->setStyleSheet("QLabel {background-color: blue; color: red;}");
-
@jsulm
I did, But no change in text color, it is black only -
@o6a6r9v1p Works for me
-
@J.Hilk
what is default background color in Windows OS. I mean if we want to revert back to default color, what shall we do? -
iirc its white,
but you can also set a new StyelSheet where you leave the color unspecified
style1: "background-color: blue; color: red;"; style2: "background-color: blue; ";
-
@J.Hilk
Got it working with your code.
jsulm's method didnot work in my code.
Thanks to both of you.