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.
-
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>");
-
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.
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;}");
-
@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>");
-
@o6a6r9v1p Works for me
-
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;}");
-
@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; ";
-
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; ";