QSvgGenerator#
The QSvgGenerator
class provides a paint device that is used to create SVG drawings. More…
Synopsis#
Properties#
description
- The description of the generated SVG drawingfileName
- The target filename for the generated SVG drawingoutputDevice
- The output device for the generated SVG drawingresolution
- The resolution of the generated outputsize
- The size of the generated SVG drawingtitle
- The title of the generated SVG drawingviewBox
- The viewBox of the generated SVG drawing
Functions#
def
description
()def
fileName
()def
outputDevice
()def
resolution
()def
setDescription
(description)def
setFileName
(fileName)def
setOutputDevice
(outputDevice)def
setResolution
(dpi)def
setSize
(size)def
setTitle
(title)def
setViewBox
(viewBox)def
setViewBox
(viewBox)def
size
()def
svgVersion
()def
title
()def
viewBox
()def
viewBoxF
()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description#
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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.
generator = QSvgGenerator() 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:
painter = QPainter() 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#
PySide6.QtSvg.QSvgGenerator(version)
- Parameters:
version –
SvgVersion
Constructs a new generator using the SVG Tiny 1.2 profile.
Constructs a new generator that uses the SVG version version
.
Note
Properties can be used directly when from __feature__ import true_property
is used or via accessor functions otherwise.
- property PᅟySide6.QtSvg.QSvgGenerator.description: str#
This property holds the description of the generated SVG drawing.
See also
- Access functions:
description
()setDescription
(description)
- property PᅟySide6.QtSvg.QSvgGenerator.fileName: str#
This property holds the target filename for the generated SVG drawing.
See also
- Access functions:
fileName
()setFileName
(fileName)
- property PᅟySide6.QtSvg.QSvgGenerator.outputDevice: PySide6.QtCore.QIODevice#
This property holds the output device for the generated SVG drawing.
If both output device and file name are specified, the output device will have precedence.
See also
- Access functions:
outputDevice
()setOutputDevice
(outputDevice)
- property PᅟySide6.QtSvg.QSvgGenerator.resolution: int#
This property holds the resolution of the generated output.
The resolution is specified in dots per inch, and is used to calculate the physical size of an SVG drawing.
- Access functions:
resolution
()setResolution
(dpi)
- property PᅟySide6.QtSvg.QSvgGenerator.size: PySide6.QtCore.QSize#
This property holds the size of the generated SVG drawing.
By default this property is set to QSize(-1, -1)
, which indicates that the generator should not output the width and height attributes of the <svg>
element.
Note
It is not possible to change this property while a QPainter
is active on the generator.
See also
- property PᅟySide6.QtSvg.QSvgGenerator.title: str#
This property holds the title of the generated SVG drawing.
See also
- property PᅟySide6.QtSvg.QSvgGenerator.viewBox: PySide6.QtCore.QRectF#
This property holds the viewBox
of the generated SVG drawing.
By default this property is set to QRect(0, 0, -1, -1)
, which indicates that the generator should not output the viewBox
attribute of the <svg>
element.
Note
It is not possible to change this property while a QPainter
is active on the generator.
See also
- Access functions:
viewBoxF
()setViewBox
(viewBox)
- PySide6.QtSvg.QSvgGenerator.SvgVersion#
This enumeration describes the version of the SVG output of the generator.
Constant
Description
QSvgGenerator.SvgVersion.SvgTiny12
The generated document follows the SVG Tiny 1.2 specification.
QSvgGenerator.SvgVersion.Svg11
The generated document follows the SVG 1.1 specification.
New in version 6.5.
- PySide6.QtSvg.QSvgGenerator.description()#
- Return type:
str
See also
Getter of property description
.
- PySide6.QtSvg.QSvgGenerator.fileName()#
- Return type:
str
See also
Getter of property fileName
.
- PySide6.QtSvg.QSvgGenerator.outputDevice()#
- Return type:
See also
Getter of property outputDevice
.
- PySide6.QtSvg.QSvgGenerator.resolution()#
- Return type:
int
See also
Getter of property resolution
.
- PySide6.QtSvg.QSvgGenerator.setDescription(description)#
- Parameters:
description – str
See also
Setter of property description
.
- PySide6.QtSvg.QSvgGenerator.setFileName(fileName)#
- Parameters:
fileName – str
See also
Setter of property fileName
.
- PySide6.QtSvg.QSvgGenerator.setOutputDevice(outputDevice)#
- Parameters:
outputDevice –
PySide6.QtCore.QIODevice
See also
Setter of property outputDevice
.
- PySide6.QtSvg.QSvgGenerator.setResolution(dpi)#
- Parameters:
dpi – int
See also
Setter of property resolution
.
- PySide6.QtSvg.QSvgGenerator.setSize(size)#
- Parameters:
size –
PySide6.QtCore.QSize
See also
Setter of property size
.
Setter of property title
.
- PySide6.QtSvg.QSvgGenerator.setViewBox(viewBox)#
- Parameters:
viewBox –
PySide6.QtCore.QRect
See also
- PySide6.QtSvg.QSvgGenerator.setViewBox(viewBox)
- Parameters:
viewBox –
PySide6.QtCore.QRectF
Setter of property viewBox
.
- PySide6.QtSvg.QSvgGenerator.size()#
- Return type:
See also
Getter of property size
.
- PySide6.QtSvg.QSvgGenerator.svgVersion()#
- Return type:
Returns the version of the SVG document that this generator is producing.
- PySide6.QtSvg.QSvgGenerator.title()#
- Return type:
str
See also
Getter of property title
.
- PySide6.QtSvg.QSvgGenerator.viewBox()#
- Return type:
Returns viewBoxF()
.toRect().
See also
- PySide6.QtSvg.QSvgGenerator.viewBoxF()#
- Return type:
Getter of property viewBox
.