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

Last change on this file since 5 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 2.0 KB
Line 
1//! [0]
2QLinearGradient gradient(0, 0, 100, 100);
3gradient.setColorAt(0, Qt::red);
4gradient.setColorAt(0.5, Qt::green);
5gradient.setColorAt(1, Qt::blue);
6painter.setBrush(gradient);
7painter.drawRect(0, 0, 100, 100);
8//! [0]
9
10
11//! [1]
12QRadialGradient gradient(50, 50, 50, 30, 30);
13gradient.setColorAt(0.2, Qt::white);
14gradient.setColorAt(0.8, Qt::green);
15gradient.setColorAt(1, Qt::black);
16painter.setBrush(gradient);
17painter.drawEllipse(0, 0, 100, 100);
18//! [1]
19
20
21//! [2]
22QConicalGradient gradient(60, 40, 0);
23gradient.setColorAt(0, Qt::black);
24gradient.setColorAt(0.4, Qt::green);
25gradient.setColorAt(0.6, Qt::white);
26gradient.setColorAt(1, Qt::black);
27painter.setBrush(gradient);
28painter.drawEllipse(0, 0, 100, 100);
29//! [2]
30
31
32//! [3]
33// Specfiy semi-transparent red
34painter.setBrush(QColor(255, 0, 0, 127));
35painter.drawRect(0, 0, width()/2, height());
36
37// Specify semi-transparend blue
38painter.setBrush(QColor(0, 0, 255, 127));
39painter.drawRect(0, 0, width(), height()/2);
40//! [3]
41
42
43//! [4]
44// One line without anti-aliasing
45painter.drawLine(0, 0, width()/2, height());
46
47// One line with anti-aliasing
48painter.setRenderHint(QPainter::Antialiasing);
49painter.drawLine(width()/2, 0, width()/2, height());
50//! [4]
51
52
53//! [5]
54QPainterPath path;
55path.addRect(20, 20, 60, 60);
56path.addBezier(0, 0, 99, 0, 50, 50, 99, 99);
57path.addBezier(99, 99, 0, 99, 50, 50, 0, 0);
58painter.drawPath(path);
59//! [5]
60
61
62//! [6]
63QPixmap buffer(size());
64QPainter painter(&buffer);
65
66// Paint code here
67
68painter.end();
69bitBlt(this, 0, 0, &buffer);
70//! [6]
71
72
73//! [7]
74QPainter painter(this);
75
76// Paint code here
77
78painter.end();
79//! [7]
80
81
82//! [8]
83unbufferedWidget->setAttribute(Qt::WA_PaintOnScreen);
84//! [8]
85
86
87//! [9]
88QLinearGradient gradient(0, 0, 100, 100);
89gradient.setColorAt(0, Qt::blue);
90gradient.setColorAt(1, Qt::red);
91painter.setPen(QPen(gradient, 0));
92for (int y=fontSize; y<100; y+=fontSize)
93 drawText(0, y, text);
94//! [9]
95
96
97//! [10]
98QImage image(100, 100, 32);
99QPainter painter(&image);
100
101// painter commands.
102
103painter.end();
104//! [10]
Note: See TracBrowser for help on using the repository browser.