Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtqml-tooling-svgtoqml.qdoc
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\page qtqml-tooling-svgtoqml.html
6\title svgtoqml
7\brief The SVG to QML converter tool
8\ingroup qtqml-tooling
9
10\c svgtoqml is a command line tool shipped with Qt that converts an SVG document
11to a QML file. This QML file can then be used as a component in Qt Quick
12applications. The \l{Weather Forecast Example} includes multiple QML files that have been generated
13using this tool.
14
15\section1 Overview
16The \c svgtoqml will convert an SVG file to a QML file which uses Qt Quick primitives. Since
17Qt Quick supports scalable vector graphics, the resulting item will be smoothly transformable as far
18as this is possible. As a baseline, the tool supports most of the static features of the SVG Tiny 1.2
19profile. Certain additional features are supported, determined on a case-by-case basis. Interactive
20features and animations are not supported.
21
22\section1 Usage
23The basic usage of \c svgtoqml is to provide an input file and an output file:
24\c{svgtoqml input.svg output.qml}. This will read the \c{input.svg} file and convert it into the
25corresponding Qt Quick scene in \c{output.qml}, which can then be used as part of a Qt Quick
26application.
27
28In addition, it supports the following options:
29
30\table
31\header
32 \li Option
33 \li Description
34\row
35 \li --copyright-statement <string>
36 \li Adds <string> as a comment at the beginning of the generated file.
37\row
38 \li --curve-renderer
39 \li Enables the curve renderer backend for \l{Qt Quick Shapes}. This enables smooth, antialiased
40 shapes in the scene without multi-sampling, but at some extra cost.
41\row
42 \li --optimize-paths
43 \li Enables optimization of paths before committing them to the QML file, potentially making
44 them faster to load and render later.
45\row
46 \li --outline-stroke-mode
47 \li Stroke the outline (contour) of the filled shape instead of the original path.
48\row
49 \li -t, --type-name <string>
50 \li In place of \l{Shape}, the output will use the type name <string> instead. This is
51 enables using a custom item to override the default behavior of \l{Shape} items.
52\row
53 \li -v, --view
54 \li Display a preview of the Qt Quick item as it will be generated.
55\endtable
56
57\section1 Comparison to other options
58There are multiple options for including SVG content in Qt Quick. The following will give an
59overview of where \c svgtoqml fits into the story.
60
61\section2 Comparison to Qt Svg
62\l{Qt Svg} is a module which provides a parser and software renderer for SVG files. In addition, it
63includes an image loader plugin, so that SVG files can be loaded directly by the \l{Image} element
64in Qt Quick. The SVG will then be rasterized and cached at a specified size and redrawing it will
65be quite cheap. But zooming into the image without pixelation will involve reloading it at a
66different size, which in turn can be expensive.
67
68\c svgtoqml (and the \l{VectorImage} component) are alternative ways of rendering the same content.
69Once loaded into Qt Quick, transforms can be changed while retaining the geometry data needed to
70render the scene in GPU memory. Thus, the vector image can be redrawn at different scales with very
71little overhead.
72
73If the image size will not change during the life time of the application, however, loading the
74SVG as an \l{Image} will be more efficient. In this case, if the SVG is always rendered at a
75small subset of possible sizes, consider pre-rasterizing it to an image format which is more
76efficient to load, such as \c PNG.
77
78\section2 Comparison to VectorImage
79The \l{VectorImage} component provides the same basic functionality as \c svgtoqml, but instead of
80pregenerating the Qt Quick scene as a QML file, it creates the scene at runtime. This allows loading
81SVG files that are not provided at build time and thus allows for more flexibility. Pregenerating
82the scenes with \c svgtoqml allows optimizing the scene before it is loaded. Thus, for files that
83are available at build time, \c svgtoqml is the preferred option.
84
85\section2 Comparison to PathSvg
86The \l{PathSvg} component is part of the \l{Qt Quick Shapes} module. It provides a way to define
87paths with the syntax used by SVG, where the control points of a path are specified as a string. It
88does not support loading SVG files, so it is not a direct alternative to \c svgtoqml. If a complex
89SVG contains a specific shape needed by the application, then copying this path description into
90\l{PathSvg} may be more convenient than generating the full file.
91
92*/