How to stop child widgets from inheriting parent's StyleSheet and use system default?
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?
Re: How to stop child widgets from inheriting parent's StyleSheet and use system defa
Try ".QDialog" instead of "QDialog". If you have a subclass of QDialog, just use its name instead of QDialog.
Re: How to stop child widgets from inheriting parent's StyleSheet and use system defa
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.
Re: How to stop child widgets from inheriting parent's StyleSheet and use system defa
Thanks guys. I ended up using the name of my widget for the stylesheet and that worked OK.
How to stop child widgets inheriting parent's StyleSheet and use system default
How to do the same in DESIGN MODE?
Re: How to stop child widgets inheriting parent's StyleSheet and use system default
What do you mean?
The style sheet is not aware in which "mode" you are.
Re: How to stop child widgets inheriting parent's StyleSheet and use system default
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.
Re: How to stop child widgets inheriting parent's StyleSheet and use system default
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:
Code:
.QFrame { border-style: solid; border-width: 5px; }
... or ...
Code:
#myFrameName { border-style: solid; border-width: 5px; }