PySide6.QtSvg.QSvgRenderer¶
- class QSvgRenderer¶
The
QSvgRenderer
class is used to draw the contents of SVG files onto paint devices. More…Synopsis¶
Properties¶
animationEnabledᅟ
- Whether the animation should run, if the SVG is animatedaspectRatioModeᅟ
- How rendering adheres to the SVG view box aspect ratioframesPerSecondᅟ
- The number of frames per second to be shownviewBoxᅟ
- The rectangle specifying the visible area of the document in logical coordinates
Methods¶
def
__init__()
def
animated()
def
currentFrame()
def
defaultSize()
def
elementExists()
def
isValid()
def
options()
def
setOptions()
def
setViewBox()
def
viewBox()
def
viewBoxF()
Slots¶
Signals¶
def
repaintNeeded()
Static functions¶
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¶
Using
QSvgRenderer
, Scalable Vector Graphics (SVG) can be rendered onto any QPaintDevice subclass, including QWidget, QImage, and QGLWidget.QSvgRenderer
provides an API that supports basic features of SVG rendering, such as loading and rendering of static drawings, and more interactive features like animation. Since the rendering is performed using QPainter, SVG drawings can be rendered on any subclass of QPaintDevice.SVG drawings are either loaded when an
QSvgRenderer
is constructed, or loaded later using theload()
functions. Data is either supplied directly as serialized XML, or indirectly using a file name. If a valid file has been loaded, either when the renderer is constructed or at some later time,isValid()
returns true; otherwise it returns false.QSvgRenderer
provides therender()
slot to render the current document, or the current frame of an animated document, using a given painter.The
defaultSize()
function provides information about the amount of space that is required to render the currently loaded SVG file. This is useful for paint devices, such as QWidget, that often need to supply a size hint to their parent layout. The default size of a drawing may differ from its visible area, found using theviewBox
property.Animated SVG drawings are supported, and can be controlled with a simple collection of functions and properties:
The
animated()
function indicates whether a drawing contains animation information.The
framesPerSecond
property contains the rate at which the animation plays.
Finally, the
QSvgRenderer
class provides therepaintNeeded()
signal which is emitted whenever the rendering of the document needs to be updated.See also
Note
Properties can be used directly when
from __feature__ import true_property
is used or via accessor functions otherwise.- property animationEnabledᅟ: bool¶
This property holds whether the animation should run, if the SVG is animated.
Setting the property to false stops the animation timer. Setting the property to true starts the animation timer, provided that the SVG contains animated elements.
If the SVG is not animated, the property will have no effect. Otherwise, the property defaults to true.
See also
- Access functions:
- property aspectRatioModeᅟ: Qt.AspectRatioMode¶
This property holds how rendering adheres to the SVG view box aspect ratio.
The accepted modes are:
Qt::IgnoreAspectRatio (the default): the aspect ratio is ignored and the rendering is stretched to the target bounds.
Qt::KeepAspectRatio: rendering is centered and scaled as large as possible within the target bounds while preserving aspect ratio.
- Access functions:
- property currentFrameᅟ: int¶
- Access functions:
- property framesPerSecondᅟ: int¶
This property holds the number of frames per second to be shown.
The number of frames per second is 0 if the current document is not animated.
See also
- Access functions:
- property optionsᅟ: Combination of QtSvg.Option¶
This property holds a set of
Option
flags that can be used to enable or disable various features of the parsing and rendering of SVG files.In order to take effect, this property must be set
before
load()
is executed. Note that the constructors taking an SVG source parameter will perform loading during construction.See also
- Access functions:
This property holds the rectangle specifying the visible area of the document in logical coordinates.
- Access functions:
Constructs a new renderer with the given
parent
.- __init__(contents[, parent=None])
- Parameters:
contents –
QXmlStreamReader
parent –
QObject
Constructs a new renderer with the given
parent
and loads the SVG data using the stream reader specified bycontents
.- __init__(contents[, parent=None])
- Parameters:
contents –
QByteArray
parent –
QObject
Constructs a new renderer with the given
parent
and loads the SVG data from the byte array specified bycontents
.- __init__(filename[, parent=None])
- Parameters:
filename – str
parent –
QObject
Constructs a new renderer with the given
parent
and loads the contents of the SVG file with the specifiedfilename
.- animated()¶
- Return type:
bool
Returns true if the current document contains animated elements; otherwise returns false.
See also
- animationDuration()¶
- Return type:
int
- aspectRatioMode()¶
- Return type:
See also
Getter of property
aspectRatioModeᅟ
.Returns bounding rectangle of the item with the given
id
. The transformation matrix of parent elements is not affecting the bounds of the element.See also
- currentFrame()¶
- Return type:
int
Getter of property
currentFrameᅟ
.Returns the default size of the document contents.
- elementExists(id)¶
- Parameters:
id – str
- Return type:
bool
Returns true if the element with the given
id
exists in the currently parsed SVG file and is a renderable element.Note: this method returns true only for elements that can be rendered. Which implies that elements that are considered part of the fill/stroke style properties, e.g. radialGradients even tough marked with “id” attributes will not be found by this method.
- framesPerSecond()¶
- Return type:
int
See also
Getter of property
framesPerSecondᅟ
.- isAnimationEnabled()¶
- Return type:
bool
Getter of property
animationEnabledᅟ
.- isValid()¶
- Return type:
bool
Returns true if there is a valid current document; otherwise returns false.
- load(contents)¶
- Parameters:
contents –
QXmlStreamReader
- Return type:
bool
Loads the specified SVG in
contents
, returning true if the content was successfully parsed; otherwise returns false.The reader will be used from where it currently is positioned. If
contents
isnull
, behavior is undefined.- load(contents)
- Parameters:
contents –
QByteArray
- Return type:
bool
Loads the specified SVG format
contents
, returning true if the content was successfully parsed; otherwise returns false.- load(filename)
- Parameters:
filename – str
- Return type:
bool
Loads the SVG file specified by
filename
, returning true if the content was successfully parsed; otherwise returns false.Getter of property
optionsᅟ
.Renders the current document, or the current frame of an animated document, using the given
painter
.Renders the current document, or the current frame of an animated document, using the given
painter
on the specifiedbounds
within the painter. Ifbounds
is not empty, the output will be scaled to fill it, ignoring any aspect ratio implied by the SVG.Renders the given element with
elementId
using the givenpainter
on the specifiedbounds
. If the bounding rectangle is not specified the SVG element is mapped to the whole paint device.- repaintNeeded()¶
This signal is emitted whenever the rendering of the document needs to be updated, usually for the purposes of animation.
- setAnimationEnabled(enable)¶
- Parameters:
enable – bool
See also
Setter of property
animationEnabledᅟ
.- setAspectRatioMode(mode)¶
- Parameters:
mode –
AspectRatioMode
See also
Setter of property
aspectRatioModeᅟ
.- setCurrentFrame(arg__1)¶
- Parameters:
arg__1 – int
Setter of property
currentFrameᅟ
.Sets the option flags that renderers will be created with to
flags
. By default, no flags are set.At runtime, this can be overridden by the QT_SVG_DEFAULT_OPTIONS environment variable.
- setFramesPerSecond(num)¶
- Parameters:
num – int
See also
Setter of property
framesPerSecondᅟ
.Setter of property
optionsᅟ
.- setViewBox(viewbox)
- Parameters:
viewbox –
QRectF
Setter of property
viewBoxᅟ
.- transformForElement(id)¶
- Parameters:
id – str
- Return type:
Returns the transformation matrix for the element with the given
id
. The matrix is a product of the transformation of the element’s parents. The transformation of the element itself is not included.To find the bounding rectangle of the element in logical coordinates, you can apply the matrix on the rectangle returned from
boundsOnElement()
.See also
Returns
viewBoxF()
.toRect().See also
Getter of property
viewBoxᅟ
.