问题
Qt QSS is propagated to children, if one parent set its stylesheet to color: red
, all its children will apply this stylesheet. If you set explicitely QLabel {color: red}
, then only QLabel children will be concerned.
It is possible to overwrite the stylesheet on children, if they set their own values children->setStyleSheet("color: blue");
but I could not find a way to reset the property to the default value. The value set by the system or Qt, if we had not set this property in any parent's stylesheet.
How could I achieve something like children->setStyleSheet("color: default");
?
回答1:
You don't need to, normally. Parent widget can have some complex stylesheet, so that it won't affect children widgets in any undesired way. I prefer storing those styles in resource files, it's a common way.
But AFAIK you can always set stylesheet to an empty string, like:
children->setStyleSheet("");
Sometimes, on some platforms (mostly Windows) widgets do reset their appearance, but don't get all of system styling (on Windows they become gray, cornered and dull), not always, but happenes.
And if some stylesheets are applied dynamically and you don't get the result, "official crutchy style update" helps, like:
someWidget->style()->unpolish(someWidget);
someWidget->style()->polish(someWidget);
来源:https://stackoverflow.com/questions/54403698/how-can-i-restore-default-system-value-of-a-qss-property