Re: QColor with style sheets
So you want to dynamically specify colors... Well, you can't do it like that.
You can do it with a QString and placeholders:
Code:
QString style
= "color: rgb(%1, %2, %3);";
label->setStyleSheet(style.arg(myColor.red()).arg(myColor.green()).arg(myColor.blue()));
Re: QColor with style sheets
Thanks Marcel,
I got your code to work but I don't know what the syntax is to combine what you suggested into the same style sheet with the other style declarations. For example both of the style sheet declarations below work but I can't put them together into one. What is the syntax? Thanks a lot!
Code:
mycolor
= QColor(100,
200,
200);
QString style
= "background: rgb(%1, %2, %3);";
drawButton->setStyleSheet(style.arg(mycolor.red()).arg(mycolor.green()).arg(mycolor.blue()));
drawButton->setStyleSheet(
"color:black; font-size:12px;"
"font-weight:bold;"
);
Re: QColor with style sheets
With the label colour it would be much simpler to use the palette...
Code:
palette.
setColor(QPalette::Foreground, mycolor
);
label.setPalette(palette);
Re: QColor with style sheets
Quote:
I got your code to work but I don't know what the syntax is to combine what you suggested into the same style sheet with the other style declarations. For example both of the style sheet declarations below work but I can't put them together into one. What is the syntax? Thanks a lot!
Because the style sheet parameter is a QString, you can use all QString features, like the "+" and "+=" operators:
Code:
mycolor
= QColor(100,
200,
200);
QString style
= "background: rgb(%1, %2, %3);";
style = style.arg(mycolor.red()).arg(mycolor.green()).arg(mycolor.blue());
style += "color:black; font-size:12px;";
style += "font-weight:bold;";
drawButton->setStyleSheet(style);