PyQt 应用程序:恢复原始外观&改变一些QSS元素后的感受 [英] PyQt application: Restore the original look & feel after changing some QSS elements

查看:55
本文介绍了PyQt 应用程序:恢复原始外观&改变一些QSS元素后的感受的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 QSS 样式表更改 pyQt 应用程序中某些元素的外观.这也会覆盖这些元素的许多其他属性(如文档和许多教程中所述).

I'm changing the look of some elements in my pyQt application using a QSS style sheet. This has the effect of overriding many other properties of those elements as well (as noted in the documentation and many tutorials).

现在,我想恢复这些被覆盖的属性,但我没有在我的系统上找到定义默认主题的原始"样式表.使用这些样式表中的信息,我可以恢复原始外观的其余部分.

Now, I would like to restore these overridden properties, but I haven't managed to find the "original" style sheets on my system where the default themes are defined. Using the information from these style sheets I could restore the rest of the original look.

有人能给我提示在哪里可以找到这些样式表吗?或者有没有更优雅的方式来实现我的目标?

Could somebody give me hint where to find these style sheets? Or is there a more elegant way to achieve my goals?

推荐答案

没有默认样式表.所有默认样式均由 样式插件 完成.

There are no default stylesheets. All the default styling is done by style plugins.

设置样式表后,它会创建一个 QStyleSheetStyle(它是 QWindowsStyle 的子类)的实例,并将其传递给当前样式的引用.QStyleSheetStyle 将尝试在当前样式之上应用 QSS 规则,但如果这是不可能的,它将回退到 QWindowsStyle.

When a stylesheet is set, it creates an instance of QStyleSheetStyle (which is a subclass of QWindowsStyle) and passes it a reference to the current style. The QStyleSheetStyle will try to apply the QSS rules on top of the current style, but where this is not possible, it will fall back to the QWindowsStyle.

这就是问题开始的地方,因为没有简单的方法来确定特定的 QSS 规则会做什么.有时它会产生非常精确的效果,有时它会完全破坏正常的造型.此外,确切的结果取决于当前的风格是什么.因此,QSS 规则在您自己的系统上可能看起来不错,但不能保证在其他系统上也能如此.

And this is where the problems start, because there is no simple way to determine what a particular QSS rule will do. Sometimes it will have a very precise effect, and other times it will completely clobber the normal styling. In addition, the exact outcome depends on what the current style is. So a QSS rule might look good on your own system, but there's no guarantee it will do so on others.

因此,使用样式表总是一种妥协.创建一个自定义的 QStyle 会给你更多的控制,但样式表通常更容易编写和维护.所以这是方便和精确之间的权衡.

Using stylesheets is therefore always a compromise. Creating a custom QStyle would give you much more control, but stylesheets will usually be much easier to write and maintain. So it's a trade-off between convenience and precision.

但是,还有第三种选择.没做什么.尊重用户对小部件样式的选择 - 或者至少不要强迫他们接受您的样式.

However, there is a third option available. Do nothing. Respect the user's choice of widget styling - or at the very least, don't force them to accept yours.

这篇关于PyQt 应用程序:恢复原始外观&改变一些QSS元素后的感受的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆