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