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
qstylepainter.h
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#ifndef QSTYLEPAINTER_H
5#define QSTYLEPAINTER_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtGui/qpainter.h>
9#include <QtWidgets/qstyle.h>
10#include <QtWidgets/qwidget.h>
11
13
14
15class QStylePainter : public QPainter
16{
17public:
18 inline QStylePainter() : QPainter(), widget(nullptr), wstyle(nullptr) {}
19 inline explicit QStylePainter(QWidget *w) { begin(w, w); }
20 inline QStylePainter(QPaintDevice *pd, QWidget *w) { begin(pd, w); }
21 inline bool begin(QWidget *w) { return begin(w, w); }
22 inline bool begin(QPaintDevice *pd, QWidget *w) {
23 Q_ASSERT_X(w, "QStylePainter::QStylePainter", "Widget must be non-zero");
24 widget = w;
25 wstyle = w->style();
26 const bool res = QPainter::begin(pd);
28 return res;
29 }
31 inline void drawControl(QStyle::ControlElement ce, const QStyleOption &opt);
33 inline void drawItemText(const QRect &r, int flags, const QPalette &pal, bool enabled,
35 inline void drawItemPixmap(const QRect &r, int flags, const QPixmap &pixmap);
36 inline QStyle *style() const { return wstyle; }
37
38private:
39 QWidget *widget;
40 QStyle *wstyle;
41 Q_DISABLE_COPY(QStylePainter)
42};
43
45{
46 wstyle->drawPrimitive(pe, &opt, this, widget);
47}
48
50{
51 wstyle->drawControl(ce, &opt, this, widget);
52}
53
58
59void QStylePainter::drawItemText(const QRect &r, int flags, const QPalette &pal, bool enabled,
60 const QString &text, QPalette::ColorRole textRole)
61{
62 wstyle->drawItemText(this, r, flags, pal, enabled, text, textRole);
63}
64
66{
67 wstyle->drawItemPixmap(this, r, flags, pixmap);
68}
69
71
72#endif // QSTYLEPAINTER_H
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
bool begin(QPaintDevice *)
Begins painting the paint device and returns true if successful; otherwise returns false.
@ SmoothPixmapTransform
Definition qpainter.h:54
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint.
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 qrect.h:30
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\variable QStyleOptionMenuItem::menuItemType
The QStyleOption class stores the parameters used by QStyle functions.
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget.
QStylePainter(QPaintDevice *pd, QWidget *w)
Construct a QStylePainter using pd for its paint device, and attributes from widget.
bool begin(QPaintDevice *pd, QWidget *w)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool begin(QWidget *w)
Begin painting operations on the specified widget.
void drawControl(QStyle::ControlElement ce, const QStyleOption &opt)
Use the widget's style to draw a control element ce specified by QStyleOption option.
void drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption &opt)
Use the widget's style to draw a primitive element pe specified by QStyleOption option.
QStylePainter()
Constructs a QStylePainter.
void drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex &opt)
Use the widget's style to draw a complex control cc specified by the QStyleOptionComplex option.
void drawItemText(const QRect &r, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole)
Draws the text in rectangle rect and palette pal.
QStyle * style() const
Return the current style used by the QStylePainter.
void drawItemPixmap(const QRect &r, int flags, const QPixmap &pixmap)
Draws the pixmap in rectangle rect.
QStylePainter(QWidget *w)
Construct a QStylePainter using widget widget for its paint device.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
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 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,...
Definition qstyle.cpp:612
ControlElement
This enum represents a control element.
Definition qstyle.h:170
ComplexControl
This enum describes the available complex controls.
Definition qstyle.h:331
PrimitiveElement
This enum describes the various primitive elements.
Definition qstyle.h:102
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 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.
Definition qstyle.cpp:574
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 opti...
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QString text
QStyleOptionButton opt
Combined button and popup list for selecting options.
GLfloat GLfloat GLfloat w
[0]
GLboolean r
[2]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLbitfield flags
GLuint res
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
QObject::connect nullptr
widget render & pixmap