View Full Version : System stylesheet

22nd June 2009, 23:24
I am very new to the subject of stylesheets. Mainly I was just changing some background colors on the frames and that's all. I hit the problem that discussed here several times, namely - how to specify default (or system) color?

I have a custom stylesheet for a tab widget and want to keep all buttons "grey", as they were before applying the stylesheet on a tab. Reading previous discussions did not help me much, so I am asking this question again - is therea command for a style sheet that reverts the background color to be a system color, something like: background-color: system?

23rd June 2009, 06:15
what do u mean system color ? By default the widgets appear as normal window color only, isnt it ?

23rd June 2009, 09:56
Hi QPlace!

So your problem is , that you've changed the background color of a frame, and it changed the color of all its children's background?
If all you want to do, is to revert the changes on the children try this:
"QAbstractButton { background-color: palette(button); }".
You can use any other color from the widgets palette (http://doc.trolltech.com/4.5/qpalette.html#ColorRole-enum).

23rd June 2009, 15:51
Hi guys, thanks for the replies.

I have attached a screenshot to illustrate the problem. Screenshots were taken in the Qt designer.

Fig. 1 shows part of the dialog where I changed the root QWidget's stylesheet to the one shown. As you can see the buttons are now using this yellowish stylesheet (although Qt designer's visible stylesheet property for these buttons is an empty strings).

Fig. 2 shows part of the same dialog where I applied gsmico's advise to one of the buttons. Indeed the button is now "grey".

Fig. 3 shows part of different dialog where the default buttons are visible. Please notice the difference in looks between Fig.3 and Fig.2 buttons. Specifically, Fig.3 has vertical gradient and Fig.2 does not.

I am sure that there is a possibility to construct a stylesheet for a button that will mimic the appearance of the default button. What I want to have is, when specifying stylesheet for a central Widget, somehow tell him - "leave the buttons (or other widgets to that matter) alone, don't change it, so they retain the system look."

Any help/advise is greatly appreciated.


23rd June 2009, 16:45
Thanks for the screen shots. I finally understood what's your problem.
One of the solutions would be to explicitly specify the widget. For example if you want to change the stylesheet of a widget called "MyWidget", and if you don't want it to affect the appearance of it's children, then do this:
Another solution would be to specify a single widget type, in your stylesheet, and deny it to affect the widget's children.
I suggest to read the style sheet syntax documentation.
The Style Sheet Syntax (http://doc.trolltech.com/4.5/stylesheet-syntax.html)

8th July 2009, 15:42
Thanks guys

example of stylesheet inside the mainwindow.cpp

void MainWindow::testStyleSheet1(){
this->setStyleSheet(" QPushButton:hover { color: rgb(53, 201, 255) }QPushButton , QLineEdit, QComboBox, QLabel, QMenuBar { color: blue }");

I also use to revert to the default:

void MainWindow::testStyleSheetdefault(){
this->setStyleSheet(" default");

hope this help

8th July 2009, 20:46
Buttons and most of the GUI controls are derived from QWidget. If you apply the stylesheet to parent the child also takes the property. To avoid this child inheriting the stylesheet property
use "." beside the parent class name.

For ex:

QWidget {
background-color: #ffffff;

use like this,

.QWidget {
background-color: #ffffff;