PDA

View Full Version : Style Sheet Syntax background



Tondog
27th April 2010, 14:19
I want to have the background only from a QWidget black. The background from the QPushbuttons, QSliders etc. shoud be normal.
I use the Style-Syntax:

QWidget {
background-color:rgb(20, 20, 20);
}

I read in the Qt Assistant (Stylesheet-Syntax) that i must make bevore the QWidget a point:

.QWidget {
background-color:rgb(20, 20, 20);
}

I have now the problam that this didn't work.

Thanks for help.

Lykurg
27th April 2010, 14:25
well it works, but only for QWidgets! No subclass, even not your own if they only inherit QWidget.

maybe you provide a small executable example showing your problem.

Tondog
27th April 2010, 14:31
I had this code and it didn't work, the background from the QWidget wouldn't be darker:


QColor bgColor = palette().color(QPalette::Window).darker(110);
QString styleSheet = ".QWidget { background-color:rgb(%1, %2 ,%3);}";
styleSheet = styleSheet.arg(bgColor.red()).arg(bgColor.green()) .arg(bgColor.blue());
setStyleSheet(styleSheet);

Lykurg
27th April 2010, 15:23
Well your are setting the style sheet on what kind of object? I seems that is is a subclass, which, as told, wont work. But you can use ".NAMEOFYOURCLASS" and then it should work.

Tondog
28th April 2010, 06:21
Yes, it's a own subclass from QWidget. I use:
QString styleSheet = ".myOwnClass {background-color:rgb(%1, %2, %3)}"; but it didnt' work. I think it's a problem of the syntax, because
QString styleSheet = "QWidget {background-color:rgb(%1, %2, %3)}"; works and
QString styleSheet = ".QWidget {background-color:rgb(%1, %2, %3)}"; didn't work.

Tondog
28th April 2010, 07:21
I solved the problem:


QString styleSheet = "QWidget#MyOwnClass {background-color:rgb(%1, %2, %3)}";

Now it works.
But I don't now why the other syntax don't work.

Thanks for your efforts