Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_gui_painting_qpainterpath.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3#include <QLinearGradient>
4#include <QPainter>
5#include <QPainterPath>
6#include <QPen>
7
10{
12
13 void wrapper0();
14 void wrapper1();
15 void wrapper2();
16 void wrapper3();
17 void wrapper4();
18 void wrapper5();
19 void wrapper6();
20 void wrapper7();
21};
22
24
25//! [0]
26QPainterPath path;
27path.addRect(20, 20, 60, 60);
28
29path.moveTo(0, 0);
30path.cubicTo(99, 0, 50, 50, 99, 99);
31path.cubicTo(0, 99, 50, 50, 0, 0);
32
33QPainter painter(this);
34painter.fillRect(0, 0, 100, 100, Qt::white);
35painter.setPen(QPen(QColor(79, 106, 25), 1, Qt::SolidLine,
36 Qt::FlatCap, Qt::MiterJoin));
37painter.setBrush(QColor(122, 163, 39));
38
39painter.drawPath(path);
40//! [0]
41
42} // Wrapper::wrapper0
43
44
46const QPointF c1;
47const QPointF c2;
48const QPointF endPoint;
49
50//! [1]
51QLinearGradient myGradient;
52QPen myPen;
53
54QPainterPath myPath;
55myPath.cubicTo(c1, c2, endPoint);
56
57QPainter painter(this);
58painter.setBrush(myGradient);
59painter.setPen(myPen);
60painter.drawPath(myPath);
61//! [1]
62
63} // Wrapper::wrapper1
64
65
67const QRectF boundingRect;
68qreal startAngle = 0;
69qreal sweepLength = 0;
70QPointF center;
71QLinearGradient myGradient;
72QPen myPen;
73//! [2]
74QPainterPath myPath;
75myPath.moveTo(center);
76myPath.arcTo(boundingRect, startAngle,
77 sweepLength);
78
79QPainter painter(this);
80painter.setBrush(myGradient);
81painter.setPen(myPen);
82painter.drawPath(myPath);
83//! [2]
84
85} // Wrapper::wrapper2
86
87
89
90//! [3]
91QLinearGradient myGradient;
92QPen myPen;
93QRectF myRectangle;
94
95QPainterPath myPath;
96myPath.addRect(myRectangle);
97
98QPainter painter(this);
99painter.setBrush(myGradient);
100painter.setPen(myPen);
101painter.drawPath(myPath);
102//! [3]
103
104} // Wrapper::wrapper3
105
106
108
109//! [4]
110QLinearGradient myGradient;
111QPen myPen;
112QPolygonF myPolygon;
113
114QPainterPath myPath;
115myPath.addPolygon(myPolygon);
116
117QPainter painter(this);
118painter.setBrush(myGradient);
119painter.setPen(myPen);
120painter.drawPath(myPath);
121//! [4]
122
123} // Wrapper::wrapper4
124
125
127
128//! [5]
129QLinearGradient myGradient;
130QPen myPen;
131QRectF boundingRectangle;
132
133QPainterPath myPath;
134myPath.addEllipse(boundingRectangle);
135
136QPainter painter(this);
137painter.setBrush(myGradient);
138painter.setPen(myPen);
139painter.drawPath(myPath);
140//! [5]
141
142} // Wrapper::wrapper5
143
144
146qreal x = 0;
147qreal y = 0;
148
149//! [6]
150QLinearGradient myGradient;
151QPen myPen;
152QFont myFont;
153QPointF baseline(x, y);
154
155QPainterPath myPath;
156myPath.addText(baseline, myFont, tr("Qt"));
157
158QPainter painter(this);
159painter.setBrush(myGradient);
160painter.setPen(myPen);
161painter.drawPath(myPath);
162//! [6]
163
164
165} // Wrapper::wrapper6
166} // src_gui_painting_qpainterpath