How can I restore default system value of a QSS property?

最后都变了- 提交于 2019-12-10 20:43:57

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!