QSvgGenerator

The QSvgGenerator class provides a paint device that is used to create SVG drawings. More

Inheritance diagram of PySide6.QtSvg.QSvgGenerator

Synopsis

Functions

Detailed Description

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 fileName or 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 title, description and resolution properties.

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 begin() and 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.

See also

QSvgRenderer QSvgWidget Qt SVG C++ Classes

class PySide6.QtSvg.QSvgGenerator

Constructs a new generator.

PySide6.QtSvg.QSvgGenerator.description()
Return type

str

See also

setDescription()

PySide6.QtSvg.QSvgGenerator.fileName()
Return type

str

See also

setFileName()

PySide6.QtSvg.QSvgGenerator.outputDevice()
Return type

PySide6.QtCore.QIODevice

PySide6.QtSvg.QSvgGenerator.resolution()
Return type

int

See also

setResolution()

PySide6.QtSvg.QSvgGenerator.setDescription(description)
Parameters

description – str

See also

description()

PySide6.QtSvg.QSvgGenerator.setFileName(fileName)
Parameters

fileName – str

See also

fileName()

PySide6.QtSvg.QSvgGenerator.setOutputDevice(outputDevice)
Parameters

outputDevicePySide6.QtCore.QIODevice

See also

outputDevice()

PySide6.QtSvg.QSvgGenerator.setResolution(dpi)
Parameters

dpi – int

See also

resolution()

PySide6.QtSvg.QSvgGenerator.setSize(size)
Parameters

sizePySide6.QtCore.QSize

See also

size()

PySide6.QtSvg.QSvgGenerator.setTitle(title)
Parameters

title – str

See also

title()

PySide6.QtSvg.QSvgGenerator.setViewBox(viewBox)
Parameters

viewBoxPySide6.QtCore.QRect

PySide6.QtSvg.QSvgGenerator.setViewBox(viewBox)
Parameters

viewBoxPySide6.QtCore.QRectF

PySide6.QtSvg.QSvgGenerator.size()
Return type

PySide6.QtCore.QSize

See also

setSize()

PySide6.QtSvg.QSvgGenerator.title()
Return type

str

See also

setTitle()

PySide6.QtSvg.QSvgGenerator.viewBox()
Return type

PySide6.QtCore.QRect

Returns viewBoxF() .toRect().

PySide6.QtSvg.QSvgGenerator.viewBoxF()
Return type

PySide6.QtCore.QRectF