
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQSvgRenderer class is used to draw the contents of SVG files onto paint devices.More...
| Header: | #include <QSvgRenderer> |
| Since: | Qt 4.1 |
| Inherits: | QObject |
Note: All functions in this class arereentrant.
| QSvgRenderer(QObject * parent = 0) | |
| QSvgRenderer(const QString & filename, QObject * parent = 0) | |
| QSvgRenderer(const QByteArray & contents, QObject * parent = 0) | |
| QSvgRenderer(QXmlStreamReader * contents, QObject * parent = 0) | |
| ~QSvgRenderer() | |
| bool | animated() const |
| QRectF | boundsOnElement(const QString & id) const |
| QSize | defaultSize() const |
| bool | elementExists(const QString & id) const |
| int | framesPerSecond() const |
| bool | isValid() const |
| QMatrix | matrixForElement(const QString & id) const |
| void | setFramesPerSecond(int num) |
| void | setViewBox(const QRect & viewbox) |
| void | setViewBox(const QRectF & viewbox) |
| QRect | viewBox() const |
| QRectF | viewBoxF() const |
| bool | load(const QString & filename) |
| bool | load(const QByteArray & contents) |
| bool | load(QXmlStreamReader * contents) |
| void | render(QPainter * painter) |
| void | render(QPainter * painter, const QRectF & bounds) |
| void | render(QPainter * painter, const QString & elementId, const QRectF & bounds = QRectF()) |
| void | repaintNeeded() |
TheQSvgRenderer class is used to draw the contents of SVG files onto paint devices.
UsingQSvgRenderer, 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 anQSvgRenderer 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.
ThedefaultSize() 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:
Finally, theQSvgRenderer class provides therepaintNeeded() signal which is emitted whenever the rendering of the document needs to be updated.
See alsoQSvgWidget,QtSvg Module,SVG Viewer Example, andQPicture.
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.
Access functions:
| int | framesPerSecond() const |
| void | setFramesPerSecond(int num) |
See alsoanimated().
This property holds the rectangle specifying the visible area of the document in logical coordinates.
This property was introduced in Qt 4.2.
Access functions:
| QRectF | viewBoxF() const |
| void | setViewBox(const QRect & viewbox) |
| void | setViewBox(const QRectF & viewbox) |
Constructs a new renderer with the givenparent.
Constructs a new renderer with the givenparent and loads the contents of the SVG file with the specifiedfilename.
Constructs a new renderer with the givenparent and loads the SVG data from the byte array specified bycontents.
Constructs a new renderer with the givenparent and loads the SVG data using the stream reader specified bycontents.
This function was introduced in Qt 4.5.
Destroys the renderer.
Returns true if the current document contains animated elements; otherwise returns false.
See alsoframesPerSecond().
Returns bounding rectangle of the item with the givenid. The transformation matrix of parent elements is not affecting the bounds of the element.
This function was introduced in Qt 4.2.
See alsomatrixForElement().
Returns the default size of the document contents.
Returns true if the element with the givenid 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.
This function was introduced in Qt 4.2.
Returns true if there is a valid current document; otherwise returns false.
[slot]bool QSvgRenderer::load(constQString & filename)Loads the SVG file specified byfilename, returning true if the content was successfully parsed; otherwise returns false.
[slot]bool QSvgRenderer::load(constQByteArray & contents)Loads the specified SVG formatcontents, returning true if the content was successfully parsed; otherwise returns false.
[slot]bool QSvgRenderer::load(QXmlStreamReader * contents)Loads the specified SVG incontents, returning true if the content was successfully parsed; otherwise returns false.
The reader will be used from where it currently is positioned. Ifcontents isnull, behavior is undefined.
This function was introduced in Qt 4.5.
Returns the transformation matrix for the element with the givenid. 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 fromboundsOnElement().
This function was introduced in Qt 4.2.
See alsoboundsOnElement().
[slot]void QSvgRenderer::render(QPainter * painter)Renders the current document, or the current frame of an animated document, using the givenpainter.
[slot]void QSvgRenderer::render(QPainter * painter, constQRectF & bounds)Renders the current document, or the current frame of an animated document, using the givenpainter on the specifiedbounds within the painter. If the bounding rectangle is not specified the SVG file is mapped to the whole paint device.
[slot]void QSvgRenderer::render(QPainter * painter, constQString & elementId, constQRectF & bounds = QRectF())Renders the given element withelementId using the givenpainter on the specifiedbounds. If the bounding rectangle is not specified the SVG element is mapped to the whole paint device.
[signal]void QSvgRenderer::repaintNeeded()This signal is emitted whenever the rendering of the document needs to be updated, usually for the purposes of animation.
ReturnsviewBoxF().toRect().
See alsosetViewBox() andviewBoxF().
© 2016 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 theGNU 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.