How to apply stylesheet only to parent?
-
-
set style sheet with object name of the parent for example groupBoxSettings
QString settingStyle = " QGroupBox#groupBoxSettings {
background-color: rgb(248,248,248);
border: 1px solid rgb(170, 170, 255);
border-radius: 3px;
border-color:rgb(170, 170, 255);
}"; -
@Roberrt
Other than the#objectName
selector the only other way I see is the.ClassName
one. For that you would need to make your desired target widget(s) be of a derived class namedClassName
you would need to create. See https://doc.qt.io/qt-6/stylesheet-syntax.html#selector-typesClass Selector .QPushButton Matches instances of QPushButton, but not of its subclasses.
This is equivalent to *[class~="QPushButton"].Having said this: it only talks about not applying to subclasses, not children. So I don't know that this is the right approach. Mind, I do not actually see where the documentation states that
#objectName
selectors only apply to that widget and not its children, so it's guesswork.