1 /****************************************************************************
3 ** Copyright (C) 2012 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 documentation of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 ** the names of its contributors may be used to endorse or promote
23 ** products derived from this software without specific prior written
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
42 void SimpleExampleWidget::paintEvent(QPaintEvent *)
44 QPainter painter(this);
45 painter.setPen(Qt::blue);
46 painter.setFont(QFont("Arial", 30));
47 painter.drawText(rect(), Qt::AlignCenter, "Qt");
53 void MyWidget::paintEvent(QPaintEvent *)
57 p.drawLine(...); // drawing code
64 void MyWidget::paintEvent(QPaintEvent *)
67 p.drawLine(...); // drawing code
73 painter->begin(0); // impossible - paint device cannot be 0
76 painter->begin(&image); // impossible - image.isNull() == true;
78 painter->begin(myWidget);
79 painter2->begin(myWidget); // impossible - only one painter at a time
84 void QPainter::rotate(qreal angle)
88 setWorldMatrix(matrix, true);
97 path.cubicTo(80, 0, 50, 50, 80, 80);
99 QPainter painter(this);
100 painter.drawPath(path);
105 QLineF line(10.0, 80.0, 90.0, 20.0);
108 painter.drawLine(line);
113 QRectF rectangle(10.0, 20.0, 80.0, 60.0);
115 QPainter painter(this);
116 painter.drawRect(rectangle);
121 QRectF rectangle(10.0, 20.0, 80.0, 60.0);
123 QPainter painter(this);
124 painter.drawRoundedRect(rectangle, 20.0, 15.0);
129 QRectF rectangle(10.0, 20.0, 80.0, 60.0);
131 QPainter painter(this);
132 painter.drawEllipse(rectangle);
137 QRectF rectangle(10.0, 20.0, 80.0, 60.0);
138 int startAngle = 30 * 16;
139 int spanAngle = 120 * 16;
141 QPainter painter(this);
142 painter.drawArc(rectangle, startAngle, spanAngle);
147 QRectF rectangle(10.0, 20.0, 80.0, 60.0);
148 int startAngle = 30 * 16;
149 int spanAngle = 120 * 16;
151 QPainter painter(this);
152 painter.drawPie(rectangle, startAngle, spanAngle);
157 QRectF rectangle(10.0, 20.0, 80.0, 60.0);
158 int startAngle = 30 * 16;
159 int spanAngle = 120 * 16;
161 QPainter painter(this);
162 painter.drawChord(rect, startAngle, spanAngle);
167 static const QPointF points[3] = {
173 QPainter painter(this);
174 painter.drawPolyline(points, 3);
179 static const QPointF points[4] = {
186 QPainter painter(this);
187 painter.drawPolygon(points, 4);
192 static const QPointF points[4] = {
199 QPainter painter(this);
200 painter.drawConvexPolygon(points, 4);
205 QRectF target(10.0, 20.0, 80.0, 60.0);
206 QRectF source(0.0, 0.0, 70.0, 40.0);
207 QPixmap pixmap(":myPixmap.png");
210 painter.drawPixmap(target, image, source);
215 QPainter painter(this);
216 painter.drawText(rect, Qt::AlignCenter, tr("Qt by\nNokia"));
222 QPointF point(10.0, 20.0)
223 picture.load("drawing.pic");
225 QPainter painter(this);
226 painter.drawPicture(0, 0, picture);
231 fillRect(rectangle, background()).
236 QRectF target(10.0, 20.0, 80.0, 60.0);
237 QRectF source(0.0, 0.0, 70.0, 40.0);
238 QImage image(":/images/myImage.png");
240 QPainter painter(this);
241 painter.drawImage(target, image, source);
246 QPainter painter(this);
247 painter.fillRect(0, 0, 128, 128, Qt::green);
248 painter.beginNativePainting();
250 glEnable(GL_SCISSOR_TEST);
251 glScissor(0, 0, 64, 64);
253 glClearColor(1, 0, 0, 1);
254 glClear(GL_COLOR_BUFFER_BIT);
256 glDisable(GL_SCISSOR_TEST);
258 painter.endNativePainting();