QProxyStyle

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

Inheritance diagram of PySide2.QtWidgets.QProxyStyle

Synopsis

Functions

Detailed Description

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:

#include "textedit.h"
#include <QApplication>
#include <QProxyStyle>

class MyProxyStyle : public QProxyStyle
{
  public:
    int styleHint(StyleHint hint, const QStyleOption *option = nullptr,
                  const QWidget *widget = nullptr, QStyleHintReturn *returnData = nullptr) const override
    {
        if (hint == QStyle::SH_UnderlineShortcut)
            return 0;
        return QProxyStyle::styleHint(hint, option, widget, returnData);
    }
};

int main(int argc, char **argv)
{
    Q_INIT_RESOURCE(textedit);

    QApplication a(argc, argv);
    a.setStyle(new MyProxyStyle);
    TextEdit mw;
    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.

See also

QStyle

class PySide2.QtWidgets.QProxyStyle([style=None])

PySide2.QtWidgets.QProxyStyle(key)

param style:

PySide2.QtWidgets.QStyle

param key:

str

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 .

PySide2.QtWidgets.QProxyStyle.baseStyle()
Return type:

PySide2.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.

PySide2.QtWidgets.QProxyStyle.setBaseStyle(style)
Parameters:

stylePySide2.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()