PDA

View Full Version : How to stop child widgets from inheriting parent's StyleSheet and use system default?



will49
10th June 2008, 06:13
I have a QDialog that I use a stylesheet to set the background color to black.
e.g.
QDialog {background-color: black; }

However when I display a QMessageBox called from that dialog it inherits the stylesheet from the parent.

I would like to be able to revert to the default stylesheet of the QMessageBox to get the background color back to normal for the QMessageBox, but can't find a way to do so. I've tried setting the stylesheet to:
QDialog { }
and
QMessageBox {}
and that doesn't work. I can set the background to another color implicitly, e.g.:
"QDialog { background-color: white;}"
, but want to use the default for the platform.

Any suggestions on how to do this? Is there a way to reset a particular style back to the default instead of what it inherited from it's parent?

wysota
10th June 2008, 07:34
Try ".QDialog" instead of "QDialog". If you have a subclass of QDialog, just use its name instead of QDialog.

benacler
12th June 2008, 23:33
Just name your object with ->setObjectName("myObjectName") then use object name selector # in the css.

#myObjectName {

}

This has to be done on the parent dialog to prevent css inheritance, from what I know, there's no way to reset the css properties from an object that implicit inherit them.

will49
13th June 2008, 00:50
Thanks guys. I ended up using the name of my widget for the stylesheet and that worked OK.

Chiz
12th January 2011, 12:58
How to do the same in DESIGN MODE?

high_flyer
12th January 2011, 13:03
What do you mean?
The style sheet is not aware in which "mode" you are.

Chiz
12th January 2011, 13:25
I have Frame. I drop Button on it.
Now I want Frame to have border-style: solid und border-width: 5px. I click on Frame->Change styleSheet... and write it there. I have what I want. Frame have solid border with 5px width. BUT, button have the same.
Ok.
Now I want button to have it's DEFAULT values for border-style and border-width. I want for this button to switch off StyleSheet inheritance.

wysota
12th January 2011, 22:01
No, you don't. You want the stylesheet to apply to one particular widget. Use a selector that will apply to this widget and not to the button, for example:
.QFrame { border-style: solid; border-width: 5px; }
... or ...
#myFrameName { border-style: solid; border-width: 5px; }