PySide6.QtWidgets.QProxyStyle¶
- class QProxyStyle¶
The
QProxyStyle
class is a convenience class that simplifies dynamically overridingQStyle
elements. More…Synopsis¶
Methods¶
def
__init__()
def
baseStyle()
def
setBaseStyle()
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 aQStyle
(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 callproxy()
, but there is no guarantee thatproxy()
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
Constructs a
QProxyStyle
object for overriding behavior in the specifiedstyle
, or in the default nativestyle
ifstyle
is not specified.Ownership of
style
is transferred toQProxyStyle
.- __init__(key)
- Parameters:
key – str
Constructs a
QProxyStyle
object for overriding behavior in the base style specified by stylekey
, or in the currentapplication style
if the specified stylekey
is unrecognized.See also
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.See also
Sets the base style that should be proxied.
Ownership of
style
is transferred toQProxyStyle
.If style is
None
, a desktop-dependent style will be assigned automatically.See also