1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qstylepainter.h"
49 \brief The QStylePainter class is a convenience class for drawing QStyle
50 elements inside a widget.
55 QStylePainter extends QPainter with a set of high-level \c
56 draw...() functions implemented on top of QStyle's API. The
57 advantage of using QStylePainter is that the parameter lists get
58 considerably shorter. Whereas a QStyle object must be able to
59 draw on any widget using any painter (because the application
60 normally has one QStyle object shared by all widget), a
61 QStylePainter is initialized with a widget, eliminating the need
62 to specify the QWidget, the QPainter, and the QStyle for every
65 Example using QStyle directly:
67 \snippet doc/src/snippets/styles/styles.cpp 1
69 Example using QStylePainter:
71 \snippet doc/src/snippets/styles/styles.cpp 0
72 \snippet doc/src/snippets/styles/styles.cpp 4
73 \snippet doc/src/snippets/styles/styles.cpp 6
75 \sa QStyle, QStyleOption
79 \fn QStylePainter::QStylePainter()
81 Constructs a QStylePainter.
85 \fn QStylePainter::QStylePainter(QWidget *widget)
87 Construct a QStylePainter using widget \a widget for its paint device.
91 \fn QStylePainter::QStylePainter(QPaintDevice *pd, QWidget *widget)
93 Construct a QStylePainter using \a pd for its paint device, and
94 attributes from \a widget.
99 \fn bool QStylePainter::begin(QWidget *widget)
101 Begin painting operations on the specified \a widget.
102 Returns true if the painter is ready to use; otherwise returns false.
104 This is automatically called by the constructor that takes a QWidget.
108 \fn bool QStylePainter::begin(QPaintDevice *pd, QWidget *widget)
111 Begin painting operations on paint device \a pd as if it was \a
114 This is automatically called by the constructor that
115 takes a QPaintDevice and a QWidget.
120 \fn void QStylePainter::drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption &option)
122 Use the widget's style to draw a primitive element \a pe specified by QStyleOption \a option.
124 \sa QStyle::drawPrimitive()
128 \fn void QStylePainter::drawControl(QStyle::ControlElement ce, const QStyleOption &option)
130 Use the widget's style to draw a control element \a ce specified by QStyleOption \a option.
132 \sa QStyle::drawControl()
136 \fn void QStylePainter::drawComplexControl(QStyle::ComplexControl cc,
137 const QStyleOptionComplex &option)
139 Use the widget's style to draw a complex control \a cc specified by the
140 QStyleOptionComplex \a option.
142 \sa QStyle::drawComplexControl()
146 \fn void QStylePainter::drawItemText(const QRect &rect, int flags, const QPalette &pal,
147 bool enabled, const QString &text,
148 QPalette::ColorRole textRole = QPalette::NoRole)
150 Draws the \a text in rectangle \a rect and palette \a pal.
151 The text is aligned and wrapped according to \a
154 The pen color is specified with \a textRole. The \a enabled bool
155 indicates whether or not the item is enabled; when reimplementing
156 this bool should influence how the item is drawn.
158 \sa QStyle::drawItemText(), Qt::Alignment
162 \fn void QStylePainter::drawItemPixmap(const QRect &rect, int flags, const QPixmap &pixmap)
164 Draws the \a pixmap in rectangle \a rect.
165 The pixmap is aligned according to \a flags.
167 \sa QStyle::drawItemPixmap(), Qt::Alignment
171 \fn QStyle *QStylePainter::style() const
173 Return the current style used by the QStylePainter.