This paint device represents a Scalable Vector Graphics (SVG) drawing. Like
QPrinter , it is designed as a write-only device that generates output in a specific format.
To write an SVG file, you first need to configure the output by setting the
outputDevice properties. It is usually necessary to specify the size of the drawing by setting the
size property, and in some cases where the drawing will be included in another, the
viewBox property also needs to be set.
QSvgGenerator generator; generator.setFileName(path); generator.setSize(QSize(200, 200)); generator.setViewBox(QRect(0, 0, 200, 200)); generator.setTitle(tr("SVG Generator Example Drawing")); generator.setDescription(tr("An SVG drawing created by the SVG Generator " "Example provided with Qt."));
Other meta-data can be specified by setting the
As with other
QPaintDevice subclasses, a
QPainter object is used to paint onto an instance of this class:
QPainter painter; painter.begin(&generator); ... painter.end();
Painting is performed in the same way as for any other paint device. However, it is necessary to use the
end() to explicitly begin and end painting on the device.
The SVG Generator Example shows how the same painting commands can be used for painting a widget and writing an SVG file.
- class PySide6.QtSvg.QSvgGenerator¶
Constructs a new generator.
- Return type
description – str
© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.