![]() |
Qt 6.x
The Qt SDK
|
The QProxyStyle class is a convenience class that simplifies dynamically overriding QStyle elements. More...
#include <qproxystyle.h>
Public Member Functions | |
QProxyStyle (QStyle *style=nullptr) | |
Constructs a QProxyStyle object for overriding behavior in the specified style, or in the default native \l{QApplication::style()} {style} if style is not specified. | |
QProxyStyle (const QString &key) | |
Constructs a QProxyStyle object for overriding behavior in the base style specified by style key, or in the current \l{QApplication::style()}{application style} if the specified style key is unrecognized. | |
~QProxyStyle () | |
Destroys the QProxyStyle object. | |
QStyle * | baseStyle () const |
Returns the proxy base style object. | |
void | setBaseStyle (QStyle *style) |
Sets the base style that should be proxied. | |
void | drawPrimitive (PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget=nullptr) const override |
\reimp | |
void | drawControl (ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget=nullptr) const override |
\reimp | |
void | drawComplexControl (ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget=nullptr) const override |
\reimp | |
void | drawItemText (QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const override |
\reimp | |
virtual void | drawItemPixmap (QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const override |
\reimp | |
QSize | sizeFromContents (ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const override |
\reimp | |
QRect | subElementRect (SubElement element, const QStyleOption *option, const QWidget *widget) const override |
\reimp | |
QRect | subControlRect (ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const override |
\reimp | |
QRect | itemTextRect (const QFontMetrics &fm, const QRect &r, int flags, bool enabled, const QString &text) const override |
\reimp | |
QRect | itemPixmapRect (const QRect &r, int flags, const QPixmap &pixmap) const override |
\reimp | |
SubControl | hitTestComplexControl (ComplexControl control, const QStyleOptionComplex *option, const QPoint &pos, const QWidget *widget=nullptr) const override |
\reimp | |
int | styleHint (StyleHint hint, const QStyleOption *option=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const override |
\reimp | |
int | pixelMetric (PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override |
\reimp | |
int | layoutSpacing (QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override |
This slot is called by layoutSpacing() to determine the spacing that should be used between control1 and control2 in a layout. | |
QIcon | standardIcon (StandardPixmap standardIcon, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override |
Returns an icon for the given standardIcon. | |
QPixmap | standardPixmap (StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget=nullptr) const override |
\reimp | |
QPixmap | generatedIconPixmap (QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const override |
\reimp | |
QPalette | standardPalette () const override |
\reimp | |
void | polish (QWidget *widget) override |
\reimp | |
void | polish (QPalette &pal) override |
\reimp | |
void | polish (QApplication *app) override |
\reimp | |
void | unpolish (QWidget *widget) override |
\reimp | |
void | unpolish (QApplication *app) override |
\reimp | |
![]() | |
QCommonStyle () | |
Constructs a QCommonStyle. | |
~QCommonStyle () | |
Destroys the style. | |
void | drawPrimitive (PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const override |
\reimp | |
void | drawControl (ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const override |
\reimp | |
QRect | subElementRect (SubElement r, const QStyleOption *opt, const QWidget *widget=nullptr) const override |
\reimp | |
void | drawComplexControl (ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *w=nullptr) const override |
\reimp | |
SubControl | hitTestComplexControl (ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *w=nullptr) const override |
\reimp | |
QRect | subControlRect (ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *w=nullptr) const override |
\reimp | |
QSize | sizeFromContents (ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *widget=nullptr) const override |
\reimp | |
int | pixelMetric (PixelMetric m, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr) const override |
\reimp | |
int | styleHint (StyleHint sh, const QStyleOption *opt=nullptr, const QWidget *w=nullptr, QStyleHintReturn *shret=nullptr) const override |
\reimp | |
QIcon | standardIcon (StandardPixmap standardIcon, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr) const override |
QPixmap | standardPixmap (StandardPixmap sp, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr) const override |
\reimp | |
QPixmap | generatedIconPixmap (QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const override |
\reimp | |
int | layoutSpacing (QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override |
\reimp | |
void | polish (QPalette &) override |
\reimp | |
void | polish (QApplication *app) override |
\reimp | |
void | polish (QWidget *widget) override |
\reimp | |
void | unpolish (QWidget *widget) override |
\reimp | |
void | unpolish (QApplication *application) override |
\reimp | |
![]() | |
QStyle () | |
Constructs a style object. | |
virtual | ~QStyle () |
Destroys the style object. | |
QString | name () const |
Returns the name of the style. | |
virtual void | polish (QWidget *widget) |
Initializes the appearance of the given widget. | |
virtual void | unpolish (QWidget *widget) |
Uninitialize the given {widget}'s appearance. | |
virtual void | polish (QApplication *application) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Late initialization of the given application object. | |
virtual void | unpolish (QApplication *application) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Uninitialize the given application. | |
virtual void | polish (QPalette &palette) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Changes the palette according to style specific requirements for color palettes (if any). | |
virtual QRect | itemTextRect (const QFontMetrics &fm, const QRect &r, int flags, bool enabled, const QString &text) const |
Returns the area within the given rectangle in which to draw the provided text according to the specified font metrics and alignment. | |
virtual QRect | itemPixmapRect (const QRect &r, int flags, const QPixmap &pixmap) const |
Returns the area within the given rectangle in which to draw the specified pixmap according to the defined alignment. | |
virtual void | drawItemText (QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const |
Draws the given text in the specified rectangle using the provided painter and palette. | |
virtual void | drawItemPixmap (QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const |
Draws the given pixmap in the specified rectangle, according to the specified alignment, using the provided painter. | |
virtual QPalette | standardPalette () const |
Returns the style's standard palette. | |
virtual void | drawPrimitive (PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const =0 |
Draws the given primitive element with the provided painter using the style options specified by option. | |
virtual void | drawControl (ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const =0 |
Draws the given element with the provided painter with the style options specified by option. | |
virtual QRect | subElementRect (SubElement subElement, const QStyleOption *option, const QWidget *widget=nullptr) const =0 |
Returns the sub-area for the given element as described in the provided style option. | |
virtual void | drawComplexControl (ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget=nullptr) const =0 |
Draws the given control using the provided painter with the style options specified by option. | |
virtual SubControl | hitTestComplexControl (ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *widget=nullptr) const =0 |
Returns the sub control at the given position in the given complex control (with the style options specified by option). | |
virtual QRect | subControlRect (ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget=nullptr) const =0 |
Returns the rectangle containing the specified subControl of the given complex control (with the style specified by option). | |
virtual int | pixelMetric (PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0 |
Returns the value of the given pixel metric. | |
virtual QSize | sizeFromContents (ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=nullptr) const =0 |
Returns the size of the element described by the specified option and type, based on the provided contentsSize. | |
virtual int | styleHint (StyleHint stylehint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const =0 |
Returns an integer representing the specified style hint for the given widget described by the provided style option. | |
virtual QPixmap | standardPixmap (StandardPixmap standardPixmap, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr) const =0 |
virtual QIcon | standardIcon (StandardPixmap standardIcon, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0 |
virtual QPixmap | generatedIconPixmap (QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const =0 |
Returns a copy of the given pixmap, styled to conform to the specified iconMode and taking into account the palette specified by option. | |
virtual int | layoutSpacing (QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0 |
int | combinedLayoutSpacing (QSizePolicy::ControlTypes controls1, QSizePolicy::ControlTypes controls2, Qt::Orientation orientation, QStyleOption *option=nullptr, QWidget *widget=nullptr) const |
const QStyle * | proxy () const |
![]() | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | event (QEvent *event) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
template<typename T > | |
T | findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T > | |
QList< T > | findChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T > | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const |
bool | disconnect (const QObject *receiver, const char *member=nullptr) const |
void | dumpObjectTree () const |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . | |
Protected Member Functions | |
bool | event (QEvent *e) override |
\reimp | |
![]() | |
QCommonStyle (QCommonStylePrivate &dd) | |
![]() | |
QStyle (QStylePrivate &dd) | |
![]() | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
The QProxyStyle class is a convenience class that simplifies dynamically overriding QStyle elements.
\inmodule QtWidgets
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:
Warning: The \l {QCommonStyle} {common styles} provided by Qt will respect this hint, because they call QStyle::proxy(), but there is no guarantee that QStyle::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 QWidget::style(). You have to create a separate custom style for the widget similar to:
Definition at line 16 of file qproxystyle.h.
Constructs a QProxyStyle object for overriding behavior in the specified style, or in the default native \l{QApplication::style()} {style} if style is not specified.
Ownership of style is transferred to QProxyStyle.
Definition at line 88 of file qproxystyle.cpp.
References d, and QObject::setParent().
QProxyStyle::QProxyStyle | ( | const QString & | key | ) |
Constructs a QProxyStyle object for overriding behavior in the base style specified by style key, or in the current \l{QApplication::style()}{application style} if the specified style key is unrecognized.
Definition at line 107 of file qproxystyle.cpp.
QProxyStyle::~QProxyStyle | ( | ) |
Destroys the QProxyStyle object.
Definition at line 115 of file qproxystyle.cpp.
QStyle * QProxyStyle::baseStyle | ( | ) | const |
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.
Definition at line 126 of file qproxystyle.cpp.
References d.
Referenced by isWindowsStyle().
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
\reimp
Reimplemented from QCommonStyle.
Definition at line 158 of file qproxystyle.cpp.
References d, painter, and widget.
Referenced by CustomStyle::drawPrimitive().
|
overrideprotectedvirtual |
\reimp
Reimplemented from QObject.
Definition at line 349 of file qproxystyle.cpp.
References d, e, QObject::event(), QEvent::FocusIn, QEvent::FocusOut, and QCoreApplication::sendEvent().
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
This slot is called by layoutSpacing() to determine the spacing that should be used between control1 and control2 in a layout.
orientation specifies whether the controls are laid out side by side or stacked vertically. The option parameter can be used to pass extra information about the parent widget. The widget parameter is optional and can also be used if option is \nullptr.
The default implementation returns -1.
Reimplemented from QCommonStyle.
Definition at line 395 of file qproxystyle.cpp.
|
overridevirtual |
|
overridevirtual |
\reimp
Reimplemented from QCommonStyle.
Definition at line 313 of file qproxystyle.cpp.
References d.
Sets the base style that should be proxied.
Ownership of style is transferred to QProxyStyle.
If style is \nullptr, a desktop-dependent style will be assigned automatically.
Definition at line 141 of file qproxystyle.cpp.
References d.
|
overridevirtual |
|
overridevirtual |
Returns an icon for the given standardIcon.
Reimplement this slot to provide your own icons in a QStyle subclass. The option argument can be used to pass extra information required to find the appropriate icon. The widget argument is optional and can also be used to help find the icon.
Reimplemented from QCommonStyle.
Definition at line 374 of file qproxystyle.cpp.
References d, standardIcon(), and widget.
Referenced by standardIcon().
|
overridevirtual |
|
overridevirtual |
\reimp
Reimplemented from QCommonStyle.
Definition at line 277 of file qproxystyle.cpp.
References d, opt, standardPixmap(), and widget.
Referenced by standardPixmap().
|
overridevirtual |
\reimp
Reimplemented from QCommonStyle.
Definition at line 259 of file qproxystyle.cpp.
References d, hint(), and widget.
Referenced by MyProxyStyle::styleHint().
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |