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