Solved Qt How to prevent child QDialogs or QWidgets from inheriting parent StyleSheet
-
I am having trouble with style inheriting in Qt. It makes me a lot of problems and it really is a very headache.
I have QWidet which I set the background 30% transparent black inside has a button which when clicked will open a custom QDialog or QMessageBox, but when the dialog opens, it is all black and very ugly, it has inherited the parent style. And also when I make a parent QWidget border to a custom one, then all the components inside this QWidget get the same border style even CheckBoxes or QButtons, and so on. It is something very big problem which while you want to give a custom style to the QWidgets.How to solve! Thanks!
-
You can narrow down style definition to a single class (or even a single object)
- https://doc.qt.io/qt-5/stylesheet-syntax.html#conflict-resolution
- additional options listed in https://doc.qt.io/qt-5/stylesheet-reference.html
If you want to stop subwidgets from inheriting the style, call
setStyleSheet("")
on widgets which should have default style sheet. -
Thanks, the narrowing down works. But setStyleSheet("") still not working.