Custom colors in Qt Designer stylesheets

I'm trying to apply a custom color to several parts of a Qt GUI, using Qt designer and the main stylesheet.

One solution would be using this:

#MainWindow{ background-color: #334422; }
#first_label{ background-color: #334422; }
#second_label{ background-color: #334422; }

But it is not scalable, what if I want to change that color again? So I tried to use this, that I think it'd work with web .css files:

.bg_color{ background-color: #334422; }
#MainWindow{ .bg_color }
#first_label{ .bg_color }
#second_label{ .bg_color }

But I get an Invalid stylesheet message.

enter image description here

Any ideas?

Upvotes: 3

Views: 5141

Answers (1)

ymoreau
ymoreau

Reputation: 3996

This is not possible with Qt stylesheet syntax.

As explained in this question/answers : Using variables in qt StyleSheets
You can parse+replace yourself some strings in the QSS to insert hex-color-values and then apply it again on your application. But this is not possible in Qt Designer, only through the code.

Upvotes: 2

Related Questions