|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the documentation of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 //! [0] |
|
43 QLinearGradient gradient(0, 0, 100, 100); |
|
44 gradient.setColorAt(0, Qt::red); |
|
45 gradient.setColorAt(0.5, Qt::green); |
|
46 gradient.setColorAt(1, Qt::blue); |
|
47 painter.setBrush(gradient); |
|
48 painter.drawRect(0, 0, 100, 100); |
|
49 //! [0] |
|
50 |
|
51 |
|
52 //! [1] |
|
53 QRadialGradient gradient(50, 50, 50, 30, 30); |
|
54 gradient.setColorAt(0.2, Qt::white); |
|
55 gradient.setColorAt(0.8, Qt::green); |
|
56 gradient.setColorAt(1, Qt::black); |
|
57 painter.setBrush(gradient); |
|
58 painter.drawEllipse(0, 0, 100, 100); |
|
59 //! [1] |
|
60 |
|
61 |
|
62 //! [2] |
|
63 QConicalGradient gradient(60, 40, 0); |
|
64 gradient.setColorAt(0, Qt::black); |
|
65 gradient.setColorAt(0.4, Qt::green); |
|
66 gradient.setColorAt(0.6, Qt::white); |
|
67 gradient.setColorAt(1, Qt::black); |
|
68 painter.setBrush(gradient); |
|
69 painter.drawEllipse(0, 0, 100, 100); |
|
70 //! [2] |
|
71 |
|
72 |
|
73 //! [3] |
|
74 // Specfiy semi-transparent red |
|
75 painter.setBrush(QColor(255, 0, 0, 127)); |
|
76 painter.drawRect(0, 0, width()/2, height()); |
|
77 |
|
78 // Specify semi-transparend blue |
|
79 painter.setBrush(QColor(0, 0, 255, 127)); |
|
80 painter.drawRect(0, 0, width(), height()/2); |
|
81 //! [3] |
|
82 |
|
83 |
|
84 //! [4] |
|
85 // One line without anti-aliasing |
|
86 painter.drawLine(0, 0, width()/2, height()); |
|
87 |
|
88 // One line with anti-aliasing |
|
89 painter.setRenderHint(QPainter::Antialiasing); |
|
90 painter.drawLine(width()/2, 0, width()/2, height()); |
|
91 //! [4] |
|
92 |
|
93 |
|
94 //! [5] |
|
95 QPainterPath path; |
|
96 path.addRect(20, 20, 60, 60); |
|
97 path.addBezier(0, 0, 99, 0, 50, 50, 99, 99); |
|
98 path.addBezier(99, 99, 0, 99, 50, 50, 0, 0); |
|
99 painter.drawPath(path); |
|
100 //! [5] |
|
101 |
|
102 |
|
103 //! [6] |
|
104 QPixmap buffer(size()); |
|
105 QPainter painter(&buffer); |
|
106 |
|
107 // Paint code here |
|
108 |
|
109 painter.end(); |
|
110 bitBlt(this, 0, 0, &buffer); |
|
111 //! [6] |
|
112 |
|
113 |
|
114 //! [7] |
|
115 QPainter painter(this); |
|
116 |
|
117 // Paint code here |
|
118 |
|
119 painter.end(); |
|
120 //! [7] |
|
121 |
|
122 |
|
123 //! [8] |
|
124 unbufferedWidget->setAttribute(Qt::WA_PaintOnScreen); |
|
125 //! [8] |
|
126 |
|
127 |
|
128 //! [9] |
|
129 QLinearGradient gradient(0, 0, 100, 100); |
|
130 gradient.setColorAt(0, Qt::blue); |
|
131 gradient.setColorAt(1, Qt::red); |
|
132 painter.setPen(QPen(gradient, 0)); |
|
133 for (int y=fontSize; y<100; y+=fontSize) |
|
134 drawText(0, y, text); |
|
135 //! [9] |
|
136 |
|
137 |
|
138 //! [10] |
|
139 QImage image(100, 100, 32); |
|
140 QPainter painter(&image); |
|
141 |
|
142 // painter commands. |
|
143 |
|
144 painter.end(); |
|
145 //! [10] |