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 = 0,
                  const QWidget *widget = 0, QStyleHintReturn *returnData = 0) 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 QProxyStyle([style=None])

QProxyStyle(key)

param style

QStyle

param key

unicode

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

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

styleQStyle

Sets the base style that should be proxied.

Ownership of style is transferred to QProxyStyle .

If style is zero, a desktop-dependant style will be assigned automatically.

See also

baseStyle()