PyQt application: Restore the original look & feel after changing some QSS elements

后端 未结 1 1516
梦如初夏
梦如初夏 2021-01-24 16:32

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 not

相关标签:
1条回答
  • 2021-01-24 17:23

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

    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.

    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.

    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.

    0 讨论(0)
提交回复
热议问题