QProxyStyle#

The QProxyStyle class is a convenience class that simplifies dynamically overriding QStyle elements. More

Inheritance diagram of PySide6.QtWidgets.QProxyStyle

Synopsis#

Functions#

Note

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

Detailed Description#

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

A 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()
    #...

Warning: The 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)
...

See also

QStyle

class PySide6.QtWidgets.QProxyStyle([style=None])#

PySide6.QtWidgets.QProxyStyle(key)

Parameters:

Constructs a QProxyStyle object for overriding behavior in the specified style, or in the default native style if style is not specified.

Ownership of style is transferred to QProxyStyle .

Constructs a 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.

See also

create()

PySide6.QtWidgets.QProxyStyle.baseStyle()#
Return type:

PySide6.QtWidgets.QStyle

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.

PySide6.QtWidgets.QProxyStyle.setBaseStyle(style)#
Parameters:

stylePySide6.QtWidgets.QStyle

Sets the base style that should be proxied.

Ownership of style is transferred to QProxyStyle .

If style is None, a desktop-dependent style will be assigned automatically.

See also

baseStyle()