QProxyStyle class is a convenience class that simplifies dynamically overriding
QStyle elements. More…
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
QProxyStyle wraps a
QStyle (usually the default system style) for the purpose of dynamically overriding painting or other specific style behavior.
The following example shows how to override the shortcut underline behavior on any platform:
from textedit import * from PySide6.QtWidgets import QApplication from PySide6.QtWidgets import QProxyStyle class MyProxyStyle(QProxyStyle): # public int styleHint(StyleHint hint, QStyleOption option = None, widget = None, QStyleHintReturn returnData = None) override() if hint == QStyle.SH_UnderlineShortcut: return 0 return QProxyStyle.styleHint(hint, option, widget, returnData) if __name__ == "__main__": Q_INIT_RESOURCE(textedit) a = QApplication(argc, argv) a.setStyle(MyProxyStyle()) mw = TextEdit() mw.resize(700, 800) mw.show() #...
common styles provided by Qt will respect this hint, because they call
proxy() , but there is no guarantee that
proxy() will be called for user defined or system controlled styles. It would not work on a Mac, for example, where menus are handled by the operating system.
When a proxy style should be set on a specific widget only, you have to make sure to not set the proxy on the global application style which is returned by
style() . You have to create a separate custom style for the widget similar to:
... proxy = MyProxyStyle(QApplication.style().name()) proxy.setParent(widget) # take ownership to avoid memleak widget.setStyle(proxy) ...
- class PySide6.QtWidgets.QProxyStyle([style=None])#
key – str
QProxyStyle object for overriding behavior in the specified
style, or in the default native
style is not specified.
style is transferred to
QProxyStyle object for overriding behavior in the base style specified by style
key, or in the current
application style if the specified style
key is unrecognized.
- Return type:
Returns the proxy base style object. If no base style is set on the proxy style,
QProxyStyle will create an instance of the application style instead.
Sets the base style that should be proxied.
style is transferred to
If style is
None, a desktop-dependent style will be assigned automatically.