Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qproxystyle.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <qstyle.h>
5#include <private/qproxystyle_p.h>
6#include <private/qapplication_p.h>
7#include "qproxystyle.h"
8#include "qstylefactory.h"
9#include <private/qstyle_p.h>
10
11#if !defined(QT_NO_STYLE_PROXY) || defined(QT_PLUGIN)
12
14
15using namespace Qt::StringLiterals;
16
52{
53 Q_Q(const QProxyStyle);
54
55 if (baseStyle)
56 return;
57
58 if (!baseStyle && !QApplicationPrivate::styleOverride.isEmpty()) {
60 if (baseStyle) {
61 // If baseStyle is an instance of the same proxyStyle
62 // we destroy it and fall back to the desktop style
63 if (qstrcmp(baseStyle->metaObject()->className(),
64 q->metaObject()->className()) == 0) {
65 delete baseStyle;
66 baseStyle = nullptr;
67 }
68 }
69 }
70
71 if (!baseStyle) // Use application desktop style
73
74 if (!baseStyle) // Fallback to windows style
75 baseStyle = QStyleFactory::create("windows"_L1);
76
77 baseStyle->setProxy(const_cast<QProxyStyle*>(q));
78 baseStyle->setParent(const_cast<QProxyStyle*>(q)); // Take ownership
79}
80
90{
91 Q_D(QProxyStyle);
92 if (style) {
93 d->baseStyle = style;
94 style->setProxy(this);
95 style->setParent(this); // Take ownership
96 }
97}
98
111
118
127{
128 Q_D (const QProxyStyle);
129 d->ensureBaseStyle();
130 return d->baseStyle;
131}
132
142{
143 Q_D (QProxyStyle);
144
145 if (d->baseStyle && d->baseStyle->parent() == this)
146 d->baseStyle->deleteLater();
147
148 d->baseStyle = style;
149
150 if (d->baseStyle) {
151 d->baseStyle->setProxy(this);
152 d->baseStyle->setParent(this);
153 }
154}
155
159{
160 Q_D (const QProxyStyle);
161 d->ensureBaseStyle();
162 d->baseStyle->drawPrimitive(element, option, painter, widget);
163}
164
169{
170 Q_D (const QProxyStyle);
171 d->ensureBaseStyle();
172 d->baseStyle->drawControl(element, option, painter, widget);
173}
174
178{
179 Q_D (const QProxyStyle);
180 d->ensureBaseStyle();
181 d->baseStyle->drawComplexControl(control, option, painter, widget);
182}
183
187 const QString &text, QPalette::ColorRole textRole) const
188{
189 Q_D (const QProxyStyle);
190 d->ensureBaseStyle();
191 d->baseStyle->drawItemText(painter, rect, flags, pal, enabled, text, textRole);
192}
193
197{
198 Q_D (const QProxyStyle);
199 d->ensureBaseStyle();
200 d->baseStyle->drawItemPixmap(painter, rect, alignment, pixmap);
201}
202
206{
207 Q_D (const QProxyStyle);
208 d->ensureBaseStyle();
209 return d->baseStyle->sizeFromContents(type, option, size, widget);
210}
211
215{
216 Q_D (const QProxyStyle);
217 d->ensureBaseStyle();
218 return d->baseStyle->subElementRect(element, option, widget);
219}
220
224{
225 Q_D (const QProxyStyle);
226 d->ensureBaseStyle();
227 return d->baseStyle->subControlRect(cc, option, sc, widget);
228}
229
232QRect QProxyStyle::itemTextRect(const QFontMetrics &fm, const QRect &r, int flags, bool enabled, const QString &text) const
233{
234 Q_D (const QProxyStyle);
235 d->ensureBaseStyle();
236 return d->baseStyle->itemTextRect(fm, r, flags, enabled, text);
237}
238
242{
243 Q_D (const QProxyStyle);
244 d->ensureBaseStyle();
245 return d->baseStyle->itemPixmapRect(r, flags, pixmap);
246}
247
251{
252 Q_D (const QProxyStyle);
253 d->ensureBaseStyle();
254 return d->baseStyle->hitTestComplexControl(control, option, pos, widget);
255}
256
260{
261 Q_D (const QProxyStyle);
262 d->ensureBaseStyle();
263 return d->baseStyle->styleHint(hint, option, widget, returnData);
264}
265
269{
270 Q_D (const QProxyStyle);
271 d->ensureBaseStyle();
272 return d->baseStyle->pixelMetric(metric, option, widget);
273}
274
278{
279 Q_D (const QProxyStyle);
280 d->ensureBaseStyle();
281 return d->baseStyle->standardPixmap(standardPixmap, opt, widget);
282}
283
287{
288 Q_D (const QProxyStyle);
289 d->ensureBaseStyle();
290 return d->baseStyle->generatedIconPixmap(iconMode, pixmap, opt);
291}
292
296{
297 Q_D (const QProxyStyle);
298 d->ensureBaseStyle();
299 return d->baseStyle->standardPalette();
300}
301
305{
306 Q_D (QProxyStyle);
307 d->ensureBaseStyle();
308 d->baseStyle->polish(widget);
309}
310
314{
315 Q_D (QProxyStyle);
316 d->ensureBaseStyle();
317 d->baseStyle->polish(pal);
318}
319
323{
324 Q_D (QProxyStyle);
325 d->ensureBaseStyle();
326 d->baseStyle->polish(app);
327}
328
332{
333 Q_D (QProxyStyle);
334 d->ensureBaseStyle();
335 d->baseStyle->unpolish(widget);
336}
337
341{
342 Q_D (QProxyStyle);
343 d->ensureBaseStyle();
344 d->baseStyle->unpolish(app);
345}
346
350{
351 Q_D (QProxyStyle);
352
353 switch (e->type()) {
354 // The Mac style relies on these events in order to set the focus frame
355 case QEvent::FocusIn:
356 case QEvent::FocusOut:
357 d->ensureBaseStyle();
358 return QApplication::sendEvent(d->baseStyle, e);
359 default:
360 break;
361 }
362
363 return QCommonStyle::event(e);
364}
365
375 const QStyleOption *option,
376 const QWidget *widget) const
377{
378 Q_D (const QProxyStyle);
379 d->ensureBaseStyle();
380 return d->baseStyle->standardIcon(standardIcon, option, widget);
381}
382
397 Qt::Orientation orientation,
398 const QStyleOption *option,
399 const QWidget *widget) const
400{
401 Q_D (const QProxyStyle);
402 d->ensureBaseStyle();
403 return d->baseStyle->layoutSpacing(control1, control2, orientation, option, widget);
404}
405
407
408#include "moc_qproxystyle.cpp"
409
410#endif // QT_NO_STYLE_PROXY
static QString desktopStyleKey()
The QApplication class manages the GUI application's control flow and main settings.
The QCommonStyle class encapsulates the common Look and Feel of a GUI.
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
\inmodule QtCore
Definition qcoreevent.h:45
@ FocusOut
Definition qcoreevent.h:67
@ FocusIn
Definition qcoreevent.h:66
Type type() const
Returns the event type.
Definition qcoreevent.h:304
\reentrant \inmodule QtGui
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
Mode
This enum type describes the mode for which a pixmap is intended to be used.
Definition qicon.h:22
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition qobject.cpp:1389
void setParent(QObject *parent)
Makes the object a child of parent.
Definition qobject.cpp:2195
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
\inmodule QtCore\reentrant
Definition qpoint.h:25
void ensureBaseStyle() const
The QProxyStyle class is a convenience class that simplifies dynamically overriding QStyle elements.
Definition qproxystyle.h:17
bool event(QEvent *e) override
\reimp
QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const override
\reimp
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget=nullptr) const override
\reimp
QPalette standardPalette() const override
\reimp
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, 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
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) 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
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 ...
void unpolish(QWidget *widget) override
\reimp
QRect itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const override
\reimp
int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override
\reimp
void polish(QWidget *widget) override
\reimp
QSize sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const override
\reimp
QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget=nullptr) const override
\reimp
QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const override
\reimp
void setBaseStyle(QStyle *style)
Sets the base style that should be proxied.
SubControl hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option, const QPoint &pos, const QWidget *widget=nullptr) const override
\reimp
void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget=nullptr) const override
\reimp
virtual void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const override
\reimp
QStyle * baseStyle() const
Returns the proxy base style object.
QRect itemTextRect(const QFontMetrics &fm, const QRect &r, int flags, bool enabled, const QString &text) const override
\reimp
~QProxyStyle()
Destroys the QProxyStyle object.
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override
Returns an icon for the given standardIcon.
\inmodule QtCore\reentrant
Definition qrect.h:30
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QStyleFactory class creates QStyle objects.
static QStyle * create(const QString &)
\variable QStyleOptionGraphicsItem::exposedRect
\variable QStyleOptionMenuItem::menuItemType
The QStyleOption class stores the parameters used by QStyle functions.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
ContentsType
This enum describes the available contents types.
Definition qstyle.h:546
StyleHint
This enum describes the available style hints.
Definition qstyle.h:584
StandardPixmap
This enum describes the available standard pixmaps.
Definition qstyle.h:716
ControlElement
This enum represents a control element.
Definition qstyle.h:170
PixelMetric
This enum describes the various available pixel metrics.
Definition qstyle.h:413
ComplexControl
This enum describes the available complex controls.
Definition qstyle.h:331
PrimitiveElement
This enum describes the various primitive elements.
Definition qstyle.h:102
friend class QProxyStyle
Definition qstyle.h:840
SubElement
This enum represents a sub-area of a widget.
Definition qstyle.h:242
SubControl
This enum describes the available sub controls.
Definition qstyle.h:347
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QOpenGLWidget * widget
[1]
QString text
rect
[4]
uint alignment
QStyleOptionButton opt
Combined button and popup list for selecting options.
Orientation
Definition qnamespace.h:98
Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2)
GLuint64 key
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLboolean r
[2]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLenum type
GLbitfield flags
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLuint GLenum option
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
QApplication app(argc, argv)
[0]
widget render & pixmap
QPainter painter(this)
[7]
view create()