QSvgRenderer¶
The
QSvgRenderer
class is used to draw the contents of SVG files onto paint devices. More…
Synopsis¶
Functions¶
def
animated
()def
animationDuration
()def
aspectRatioMode
()def
boundsOnElement
(id)def
currentFrame
()def
defaultSize
()def
elementExists
(id)def
framesPerSecond
()def
isValid
()def
matrixForElement
(id)def
setAspectRatioMode
(mode)def
setCurrentFrame
(arg__1)def
setFramesPerSecond
(num)def
setViewBox
(viewbox)def
setViewBox
(viewbox)def
transformForElement
(id)def
viewBox
()def
viewBoxF
()
Slots¶
Signals¶
def
repaintNeeded
()
Detailed Description¶
Using
QSvgRenderer
, Scalable Vector Graphics (SVG) can be rendered onto anyQPaintDevice
subclass, includingQWidget
,QImage
, andQGLWidget
.
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 usingQPainter
, SVG drawings can be rendered on any subclass ofQPaintDevice
.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 asQWidget
, 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
QSvgWidget
Qt SVG C++ Classes SVG Viewer ExampleQPicture
- class PySide2.QtSvg.QSvgRenderer([parent=None])¶
PySide2.QtSvg.QSvgRenderer(contents[, parent=None])
PySide2.QtSvg.QSvgRenderer(contents[, parent=None])
PySide2.QtSvg.QSvgRenderer(filename[, parent=None])
- param parent:
- param contents:
- param filename:
str
Constructs a new renderer with the given
parent
.Constructs a new renderer with the given
parent
and loads the SVG data using the stream reader specified bycontents
.
- PySide2.QtSvg.QSvgRenderer.animated()¶
- Return type:
bool
Returns true if the current document contains animated elements; otherwise returns false.
See also
- PySide2.QtSvg.QSvgRenderer.animationDuration()¶
- Return type:
int
Returns the number of frames in the animation, or 0 if the current document is not animated.
See also
- PySide2.QtSvg.QSvgRenderer.aspectRatioMode()¶
- Return type:
This property holds how rendering adheres to the SVG view box aspect ratio.
The accepted modes are:
IgnoreAspectRatio
(the default): the aspect ratio is ignored and the rendering is stretched to the target bounds.KeepAspectRatio
: rendering is centered and scaled as large as possible within the target bounds while preserving aspect ratio.
- PySide2.QtSvg.QSvgRenderer.boundsOnElement(id)¶
- Parameters:
id – str
- Return type:
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
- PySide2.QtSvg.QSvgRenderer.currentFrame()¶
- Return type:
int
This property holds the current frame of the document’s animation, or 0 if the document is not animated.
See also
- PySide2.QtSvg.QSvgRenderer.defaultSize()¶
- Return type:
Returns the default size of the document contents.
- PySide2.QtSvg.QSvgRenderer.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.
- PySide2.QtSvg.QSvgRenderer.framesPerSecond()¶
- Return type:
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
- PySide2.QtSvg.QSvgRenderer.isValid()¶
- Return type:
bool
Returns true if there is a valid current document; otherwise returns false.
- PySide2.QtSvg.QSvgRenderer.load(contents)¶
- Parameters:
contents –
PySide2.QtCore.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.
- PySide2.QtSvg.QSvgRenderer.load(contents)
- Parameters:
contents –
PySide2.QtCore.QByteArray
- Return type:
bool
- PySide2.QtSvg.QSvgRenderer.load(filename)
- Parameters:
filename – str
- Return type:
bool
- PySide2.QtSvg.QSvgRenderer.matrixForElement(id)¶
- Parameters:
id – str
- Return type:
Note
This function is deprecated.
Use
transformForElement()
instead.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
- PySide2.QtSvg.QSvgRenderer.render(p, elementId[, bounds=QRectF()])¶
- Parameters:
elementId – str
bounds –
PySide2.QtCore.QRectF
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.
- PySide2.QtSvg.QSvgRenderer.render(p)
- Parameters:
Renders the current document, or the current frame of an animated document, using the given
painter
.
- PySide2.QtSvg.QSvgRenderer.render(p, bounds)
- Parameters:
bounds –
PySide2.QtCore.QRectF
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.
- PySide2.QtSvg.QSvgRenderer.repaintNeeded()¶
- PySide2.QtSvg.QSvgRenderer.setAspectRatioMode(mode)¶
- Parameters:
mode –
AspectRatioMode
This property holds how rendering adheres to the SVG view box aspect ratio.
The accepted modes are:
IgnoreAspectRatio
(the default): the aspect ratio is ignored and the rendering is stretched to the target bounds.KeepAspectRatio
: rendering is centered and scaled as large as possible within the target bounds while preserving aspect ratio.
- PySide2.QtSvg.QSvgRenderer.setCurrentFrame(arg__1)¶
- Parameters:
arg__1 – int
This property holds the current frame of the document’s animation, or 0 if the document is not animated.
See also
- PySide2.QtSvg.QSvgRenderer.setFramesPerSecond(num)¶
- Parameters:
num – 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
- PySide2.QtSvg.QSvgRenderer.setViewBox(viewbox)¶
- Parameters:
viewbox –
PySide2.QtCore.QRect
- PySide2.QtSvg.QSvgRenderer.setViewBox(viewbox)
- Parameters:
viewbox –
PySide2.QtCore.QRectF
This property holds the rectangle specifying the visible area of the document in logical coordinates.
- PySide2.QtSvg.QSvgRenderer.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
- PySide2.QtSvg.QSvgRenderer.viewBox()¶
- Return type:
Returns
viewBoxF()
.toRect().See also
- PySide2.QtSvg.QSvgRenderer.viewBoxF()¶
- Return type:
This property holds the rectangle specifying the visible area of the document in logical coordinates.
© 2022 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.