3

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?

Víctor Martínez
  • 854
  • 2
  • 11
  • 29

1 Answers1

2

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.

ymoreau
  • 3,402
  • 1
  • 22
  • 60