1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
// Copyright (C) 2026 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
import QtQuick
import QtQuick.Shapes
/*!
\qmltype SvgPathItem
\inqmlmodule QtQuick.Studio.Components
\since QtQuick.Studio.Components 1.0
\inherits Shape
\brief A path defined using an SVG path data string.
The SvgPathItem type uses an SVG path data string to draw a path as a line.
The \l strokeColor, \l strokeWidth, and \l strokeStyle, properties specify the appearance of the
path. The \l dashPattern and \l dashOffset properties specify the appearance of dashed lines.
The \l capStyle property specifies whether line ends are square or rounded.
The \l joinStyle property specifies how to connect two path segments. If the path segments
enclose areas, they can be painted using either a solid fill color, specified using the
\l fillColor property, or a gradient, defined using one of the \l ShapeGradient subtypes and set
using the \l gradient property. If both a color and a gradient are specified, the gradient is
used.
If the path has curves, it may be appropriate to set the \c antialiasing property that is
inherited from \l Item to improve its appearance.
\section2 Example Usage
\image studio-svgpathitem.webp
The QML code looks as follows:
\code
SvgPathItem {
id: sVGPathItem
x: 2
y: 3
width: 152
height: 154
strokeWidth: 4
strokeColor: "black"
path: "M127.99,0 L150.061,124.052 L22.0704,146.823 L0,22.7711 L127.99,0"
fillColor: "transparent"
}
SvgPathItem {
id: sVGPathItem1
x: 56.32
y: 44.32
width: 150.06
height: 146.82
strokeWidth: 4
strokeColor: "black"
path: "M127.99,0 L150.061,124.052 L22.0704,146.823 L0,22.7711 L127.99,0"
fillColor: "transparent"
}
SvgPathItem {
id: sVGPathItem2
x: 3.18
y: 27.38
width: 55
height: 40
strokeWidth: 4
strokeColor: "black"
path: "M0,0 L55,40"
fillColor: "transparent"
}
SvgPathItem {
id: sVGPathItem3
x: 130.21
y: 2.41
width: 55
height: 42
strokeWidth: 4
strokeColor: "black"
path: "M0,0 L55,42"
fillColor: "transparent"
}
SvgPathItem {
id: sVGPathItem4
x: 22
y: 148
width: 56
height: 43
strokeWidth: 4
strokeColor: "black"
path: "M0,0 L54,40"
fillColor: "transparent"
}
SvgPathItem {
id: sVGPathItem5
x: 151.21
y: 126.41
width: 55
height: 42
strokeWidth: 4
strokeColor: "black"
path: "M0,0 L55,42"
fillColor: "transparent"
}
clip: false
\endcode
*/
Shape {
id: root
width: 200
height: 200
/*!
\include CommonItemDescriptions.qdocinc {component-gradient} {SVG Path Item}
*/
property alias gradient: shape.fillGradient
/*!
\include CommonItemDescriptions.qdocinc component-joinStyle
*/
//property alias joinStyle: path.joinStyle
property int joinStyle: ShapePath.MiterJoin //workaround for regression in Qt 6.6.1 (QDS-11845)
/*!
\include CommonItemDescriptions.qdocinc component-capStyle
*/
//property alias capStyle: path.capStyle
property int capStyle: ShapePath.SquareCap //workaround for regression in Qt 6.6.1 (QDS-11845)
/*!
\include CommonItemDescriptions.qdocinc {component-strokeStyle} {SVG Path Item}
*/
//property alias strokeStyle: path.strokeStyle
property int strokeStyle: ShapePath.SolidLine //workaround for regression in Qt 6.6.1 (QDS-11845)
/*!
\include CommonItemDescriptions.qdocinc {component-strokeWidth} {SVG Path Item}
*/
property alias strokeWidth: shape.strokeWidth
/*!
\include CommonItemDescriptions.qdocinc {component-strokeColor} {SVG Path Item}
*/
property alias strokeColor: shape.strokeColor
/*!
\include CommonItemDescriptions.qdocinc {component-dashPattern} {SVG Path Item}
*/
property alias dashPattern: shape.dashPattern
/*!
\include CommonItemDescriptions.qdocinc {component-fillColor} {SVG Path Item}
*/
property alias fillColor: shape.fillColor
/*!
\qmlproperty string SvgPathItem::path
The SVG path data string specifying the path.
For more information, see \l{https://www.w3.org/TR/SVG/paths.html#PathData} {W3C SVG Path Data}.
*/
property alias path: pathSvg.path
/*!
\include CommonItemDescriptions.qdocinc {component-dashOffset} {SVG Path Item}
*/
property alias dashOffset: shape.dashOffset
property bool __preferredRendererTypeAvailable: root.preferredRendererType !== undefined
property bool __curveRendererActive: root.__preferredRendererTypeAvailable
&& root.rendererType === Shape.CurveRenderer
layer.enabled: root.antialiasing && !root.__curveRendererActive
layer.smooth: root.antialiasing && !root.__curveRendererActive
layer.samples: root.antialiasing && !root.__curveRendererActive ? 4 : 0
ShapePath {
id: shape
strokeWidth: 4
strokeColor: "red"
capStyle: root.capStyle
strokeStyle: root.strokeStyle
joinStyle: root.joinStyle
PathSvg {
id: pathSvg
path: "M91,70.6c4.6,0,8.6,2.4,10.9,6.3l19.8,34.2c2.3,3.9,2.3,8.7,0,12.6c-2.3,3.9-6.4,6.3-10.9,6.3H71.2 c-4.6,0-8.6-2.4-10.9-6.3c-2.3-3.9-2.3-8.7,0-12.6l19.8-34.2C82.4,72.9,86.4,70.6,91,70.6z"
}
}
Component.onCompleted: {
// If preferredRendererType wasn't set initially make CurveRenderer the default
if (root.__preferredRendererTypeAvailable && root.preferredRendererType === Shape.UnknownRenderer)
root.preferredRendererType = Shape.CurveRenderer
}
}
|