<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html><head><title>QSvgRenderer Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } td.postheader { font-family: sans-serif } tr.address { font-family: sans-serif } body { background: #ffffff; color: black; } </style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QSvgRenderer Class Reference<br /><sup><sup>[<a href="qtsvg.html">QtSvg</a> module]</sup></sup></h1><p>The QSvgRenderer class is used to draw the contents of SVG files onto paint devices. <a href="#details">More...</a></p> <p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qsvgrenderer.html#QSvgRenderer">__init__</a></b> (<i>self</i>, QObject <i>parent</i> = None)</li><li><div class="fn" /><b><a href="qsvgrenderer.html#QSvgRenderer-2">__init__</a></b> (<i>self</i>, QString <i>filename</i>, QObject <i>parent</i> = None)</li><li><div class="fn" /><b><a href="qsvgrenderer.html#QSvgRenderer-3">__init__</a></b> (<i>self</i>, QByteArray <i>contents</i>, QObject <i>parent</i> = None)</li><li><div class="fn" /><b><a href="qsvgrenderer.html#QSvgRenderer-4">__init__</a></b> (<i>self</i>, QXmlStreamReader <i>contents</i>, QObject <i>parent</i> = None)</li><li><div class="fn" />bool <b><a href="qsvgrenderer.html#animated">animated</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qsvgrenderer.html#animationDuration">animationDuration</a></b> (<i>self</i>)</li><li><div class="fn" />QRectF <b><a href="qsvgrenderer.html#boundsOnElement">boundsOnElement</a></b> (<i>self</i>, QString <i>id</i>)</li><li><div class="fn" />int <b><a href="qsvgrenderer.html#currentFrame">currentFrame</a></b> (<i>self</i>)</li><li><div class="fn" />QSize <b><a href="qsvgrenderer.html#defaultSize">defaultSize</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsvgrenderer.html#elementExists">elementExists</a></b> (<i>self</i>, QString <i>id</i>)</li><li><div class="fn" />int <b><a href="qsvgrenderer.html#framesPerSecond">framesPerSecond</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsvgrenderer.html#isValid">isValid</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsvgrenderer.html#load">load</a></b> (<i>self</i>, QString <i>filename</i>)</li><li><div class="fn" />bool <b><a href="qsvgrenderer.html#load-2">load</a></b> (<i>self</i>, QByteArray <i>contents</i>)</li><li><div class="fn" />bool <b><a href="qsvgrenderer.html#load-3">load</a></b> (<i>self</i>, QXmlStreamReader <i>contents</i>)</li><li><div class="fn" />QMatrix <b><a href="qsvgrenderer.html#matrixForElement">matrixForElement</a></b> (<i>self</i>, QString <i>id</i>)</li><li><div class="fn" /><b><a href="qsvgrenderer.html#render">render</a></b> (<i>self</i>, QPainter <i>p</i>)</li><li><div class="fn" /><b><a href="qsvgrenderer.html#render-2">render</a></b> (<i>self</i>, QPainter <i>p</i>, QRectF <i>bounds</i>)</li><li><div class="fn" /><b><a href="qsvgrenderer.html#render-3">render</a></b> (<i>self</i>, QPainter <i>painter</i>, QString <i>elementId</i>, QRectF <i>bounds</i> = QRectF())</li><li><div class="fn" /><b><a href="qsvgrenderer.html#setCurrentFrame">setCurrentFrame</a></b> (<i>self</i>, int)</li><li><div class="fn" /><b><a href="qsvgrenderer.html#setFramesPerSecond">setFramesPerSecond</a></b> (<i>self</i>, int <i>num</i>)</li><li><div class="fn" /><b><a href="qsvgrenderer.html#setViewBox">setViewBox</a></b> (<i>self</i>, QRect <i>viewbox</i>)</li><li><div class="fn" /><b><a href="qsvgrenderer.html#setViewBox-2">setViewBox</a></b> (<i>self</i>, QRectF <i>viewbox</i>)</li><li><div class="fn" />QRect <b><a href="qsvgrenderer.html#viewBox">viewBox</a></b> (<i>self</i>)</li><li><div class="fn" />QRectF <b><a href="qsvgrenderer.html#viewBoxF">viewBoxF</a></b> (<i>self</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qsvgrenderer.html#repaintNeeded">repaintNeeded</a></b> ()</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QSvgRenderer class is used to draw the contents of SVG files onto paint devices.</p> <p>Using QSvgRenderer, Scalable Vector Graphics (SVG) can be rendered onto any <a href="qpaintdevice.html">QPaintDevice</a> subclass, including <a href="qwidget.html">QWidget</a>, <a href="qimage.html">QImage</a>, and <a href="qglwidget.html">QGLWidget</a>.</p> <p>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 <a href="qpainter.html">QPainter</a>, SVG drawings can be rendered on any subclass of <a href="qpaintdevice.html">QPaintDevice</a>.</p> <p>SVG drawings are either loaded when an QSvgRenderer is constructed, or loaded later using the <a href="qsvgrenderer.html#load">load</a>() 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, <a href="qsvgrenderer.html#isValid">isValid</a>() returns true; otherwise it returns false. QSvgRenderer provides the <a href="qsvgrenderer.html#render">render</a>() slot to render the current document, or the current frame of an animated document, using a given painter.</p> <p>The <a href="qsvgrenderer.html#defaultSize">defaultSize</a>() 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 <a href="qwidget.html">QWidget</a>, 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 the <a href="qsvgrenderer.html#viewBox-prop">viewBox</a> property.</p> <p>Animated SVG drawings are supported, and can be controlled with a simple collection of functions and properties:</p> <ul> <li>The <a href="qsvgrenderer.html#animated">animated</a>() function indicates whether a drawing contains animation information.</li> <li>The <a href="qsvgrenderer.html#framesPerSecond-prop">framesPerSecond</a> property contains the rate at which the animation plays.</li> </ul> <p>Finally, the QSvgRenderer class provides the <a href="qsvgrenderer.html#repaintNeeded">repaintNeeded</a>() signal which is emitted whenever the rendering of the document needs to be updated.</p> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QSvgRenderer" />QSvgRenderer.__init__ (<i>self</i>, <a href="qobject.html">QObject</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a new renderer with the given <i>parent</i>.</p> <h3 class="fn"><a name="QSvgRenderer-2" />QSvgRenderer.__init__ (<i>self</i>, QString <i>filename</i>, <a href="qobject.html">QObject</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a new renderer with the given <i>parent</i> and loads the contents of the SVG file with the specified <i>filename</i>.</p> <h3 class="fn"><a name="QSvgRenderer-3" />QSvgRenderer.__init__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>contents</i>, <a href="qobject.html">QObject</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a new renderer with the given <i>parent</i> and loads the SVG data from the byte array specified by <i>contents</i>.</p> <h3 class="fn"><a name="QSvgRenderer-4" />QSvgRenderer.__init__ (<i>self</i>, <a href="qxmlstreamreader.html">QXmlStreamReader</a> <i>contents</i>, <a href="qobject.html">QObject</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a new renderer with the given <i>parent</i> and loads the SVG data using the stream reader specified by <i>contents</i>.</p> <p>This function was introduced in Qt 4.5.</p> <h3 class="fn"><a name="animated" />bool QSvgRenderer.animated (<i>self</i>)</h3><p>Returns true if the current document contains animated elements; otherwise returns false.</p> <p><b>See also</b> <a href="qsvgrenderer.html#framesPerSecond-prop">framesPerSecond</a>().</p> <h3 class="fn"><a name="animationDuration" />int QSvgRenderer.animationDuration (<i>self</i>)</h3><h3 class="fn"><a name="boundsOnElement" /><a href="qrectf.html">QRectF</a> QSvgRenderer.boundsOnElement (<i>self</i>, QString <i>id</i>)</h3><p>Returns bounding rectangle of the item with the given <i>id</i>. The transformation matrix of parent elements is not affecting the bounds of the element.</p> <p>This function was introduced in Qt 4.2.</p> <p><b>See also</b> <a href="qsvgrenderer.html#matrixForElement">matrixForElement</a>().</p> <h3 class="fn"><a name="currentFrame" />int QSvgRenderer.currentFrame (<i>self</i>)</h3><h3 class="fn"><a name="defaultSize" /><a href="qsize.html">QSize</a> QSvgRenderer.defaultSize (<i>self</i>)</h3><p>Returns the default size of the document contents.</p> <h3 class="fn"><a name="elementExists" />bool QSvgRenderer.elementExists (<i>self</i>, QString <i>id</i>)</h3><p>Returns true if the element with the given <i>id</i> exists in the currently parsed SVG file and is a renderable element.</p> <p>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.</p> <p>This function was introduced in Qt 4.2.</p> <h3 class="fn"><a name="framesPerSecond" />int QSvgRenderer.framesPerSecond (<i>self</i>)</h3><h3 class="fn"><a name="isValid" />bool QSvgRenderer.isValid (<i>self</i>)</h3><p>Returns true if there is a valid current document; otherwise returns false.</p> <h3 class="fn"><a name="load" />bool QSvgRenderer.load (<i>self</i>, QString <i>filename</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>bool load(const QString&)</tt>.</p><p>Loads the SVG file specified by <i>filename</i>, returning true if the content was successfully parsed; otherwise returns false.</p> <h3 class="fn"><a name="load-2" />bool QSvgRenderer.load (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>contents</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>bool load(const QByteArray&)</tt>.</p><p>Loads the specified SVG format <i>contents</i>, returning true if the content was successfully parsed; otherwise returns false.</p> <h3 class="fn"><a name="load-3" />bool QSvgRenderer.load (<i>self</i>, <a href="qxmlstreamreader.html">QXmlStreamReader</a> <i>contents</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>bool load(QXmlStreamReader *)</tt>.</p><p>Loads the specified SVG in <i>contents</i>, returning true if the content was successfully parsed; otherwise returns false.</p> <p>The reader will be used from where it currently is positioned. If <i>contents</i> is <tt>null</tt>, behavior is undefined.</p> <p>This function was introduced in Qt 4.5.</p> <h3 class="fn"><a name="matrixForElement" /><a href="qmatrix.html">QMatrix</a> QSvgRenderer.matrixForElement (<i>self</i>, QString <i>id</i>)</h3><p>Returns the transformation matrix for the element with the given <i>id</i>. The matrix is a product of the transformation of the element's parents. The transformation of the element itself is not included.</p> <p>To find the bounding rectangle of the element in logical coordinates, you can apply the matrix on the rectangle returned from <a href="qsvgrenderer.html#boundsOnElement">boundsOnElement</a>().</p> <p>This function was introduced in Qt 4.2.</p> <p><b>See also</b> <a href="qsvgrenderer.html#boundsOnElement">boundsOnElement</a>().</p> <h3 class="fn"><a name="render" />QSvgRenderer.render (<i>self</i>, <a href="qpainter.html">QPainter</a> <i>p</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void render(QPainter *)</tt>.</p><p>Renders the current document, or the current frame of an animated document, using the given <i>painter</i>.</p> <h3 class="fn"><a name="render-2" />QSvgRenderer.render (<i>self</i>, <a href="qpainter.html">QPainter</a> <i>p</i>, <a href="qrectf.html">QRectF</a> <i>bounds</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void render(QPainter *,const QRectF&)</tt>.</p><p>Renders the current document, or the current frame of an animated document, using the given <i>painter</i> on the specified <i>bounds</i> within the painter. If the bounding rectangle is not specified the SVG file is mapped to the whole paint device.</p> <h3 class="fn"><a name="render-3" />QSvgRenderer.render (<i>self</i>, <a href="qpainter.html">QPainter</a> <i>painter</i>, QString <i>elementId</i>, <a href="qrectf.html">QRectF</a> <i>bounds</i> = QRectF())</h3><p>This method is also a Qt slot with the C++ signature <tt>void render(QPainter *,const QString&,const QRectF& = QRectF())</tt>.</p><p>Renders the given element with <i>elementId</i> using the given <i>painter</i> on the specified <i>bounds</i>. If the bounding rectangle is not specified the SVG element is mapped to the whole paint device.</p> <h3 class="fn"><a name="setCurrentFrame" />QSvgRenderer.setCurrentFrame (<i>self</i>, int)</h3><h3 class="fn"><a name="setFramesPerSecond" />QSvgRenderer.setFramesPerSecond (<i>self</i>, int <i>num</i>)</h3><h3 class="fn"><a name="setViewBox" />QSvgRenderer.setViewBox (<i>self</i>, <a href="qrect.html">QRect</a> <i>viewbox</i>)</h3><h3 class="fn"><a name="setViewBox-2" />QSvgRenderer.setViewBox (<i>self</i>, <a href="qrectf.html">QRectF</a> <i>viewbox</i>)</h3><h3 class="fn"><a name="viewBox" /><a href="qrect.html">QRect</a> QSvgRenderer.viewBox (<i>self</i>)</h3><p>Returns <a href="qsvgrenderer.html#viewBox-prop">viewBoxF</a>().toRect().</p> <p><b>See also</b> <a href="qsvgrenderer.html#viewBox-prop">setViewBox</a>() and <a href="qsvgrenderer.html#viewBox-prop">viewBoxF</a>().</p> <h3 class="fn"><a name="viewBoxF" /><a href="qrectf.html">QRectF</a> QSvgRenderer.viewBoxF (<i>self</i>)</h3><hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="repaintNeeded" />void repaintNeeded ()</h3><p>This is the default overload of this signal.</p><p>This signal is emitted whenever the rendering of the document needs to be updated, usually for the purposes of animation.</p> <address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>