source: trunk/doc/src/snippets/code/doc_src_qt4-arthur.qdoc@ 728

Last change on this file since 728 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 3.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42//! [0]
43QLinearGradient gradient(0, 0, 100, 100);
44gradient.setColorAt(0, Qt::red);
45gradient.setColorAt(0.5, Qt::green);
46gradient.setColorAt(1, Qt::blue);
47painter.setBrush(gradient);
48painter.drawRect(0, 0, 100, 100);
49//! [0]
50
51
52//! [1]
53QRadialGradient gradient(50, 50, 50, 30, 30);
54gradient.setColorAt(0.2, Qt::white);
55gradient.setColorAt(0.8, Qt::green);
56gradient.setColorAt(1, Qt::black);
57painter.setBrush(gradient);
58painter.drawEllipse(0, 0, 100, 100);
59//! [1]
60
61
62//! [2]
63QConicalGradient gradient(60, 40, 0);
64gradient.setColorAt(0, Qt::black);
65gradient.setColorAt(0.4, Qt::green);
66gradient.setColorAt(0.6, Qt::white);
67gradient.setColorAt(1, Qt::black);
68painter.setBrush(gradient);
69painter.drawEllipse(0, 0, 100, 100);
70//! [2]
71
72
73//! [3]
74// Specfiy semi-transparent red
75painter.setBrush(QColor(255, 0, 0, 127));
76painter.drawRect(0, 0, width()/2, height());
77
78// Specify semi-transparend blue
79painter.setBrush(QColor(0, 0, 255, 127));
80painter.drawRect(0, 0, width(), height()/2);
81//! [3]
82
83
84//! [4]
85// One line without anti-aliasing
86painter.drawLine(0, 0, width()/2, height());
87
88// One line with anti-aliasing
89painter.setRenderHint(QPainter::Antialiasing);
90painter.drawLine(width()/2, 0, width()/2, height());
91//! [4]
92
93
94//! [5]
95QPainterPath path;
96path.addRect(20, 20, 60, 60);
97path.addBezier(0, 0, 99, 0, 50, 50, 99, 99);
98path.addBezier(99, 99, 0, 99, 50, 50, 0, 0);
99painter.drawPath(path);
100//! [5]
101
102
103//! [6]
104QPixmap buffer(size());
105QPainter painter(&buffer);
106
107// Paint code here
108
109painter.end();
110bitBlt(this, 0, 0, &buffer);
111//! [6]
112
113
114//! [7]
115QPainter painter(this);
116
117// Paint code here
118
119painter.end();
120//! [7]
121
122
123//! [8]
124unbufferedWidget->setAttribute(Qt::WA_PaintOnScreen);
125//! [8]
126
127
128//! [9]
129QLinearGradient gradient(0, 0, 100, 100);
130gradient.setColorAt(0, Qt::blue);
131gradient.setColorAt(1, Qt::red);
132painter.setPen(QPen(gradient, 0));
133for (int y=fontSize; y<100; y+=fontSize)
134 drawText(0, y, text);
135//! [9]
136
137
138//! [10]
139QImage image(100, 100, 32);
140QPainter painter(&image);
141
142// painter commands.
143
144painter.end();
145//! [10]
Note: See TracBrowser for help on using the repository browser.