|  | Home · All Classes · Main Classes · Grouped Classes · Modules · Functions |

# QSvgRenderer Class Reference
[QtSvg module]

The QSvgRenderer class is used to draw the contents of SVG files onto paint devices. More...

    #include <QSvgRenderer>

Inherits QObject.

This class was introduced in Qt 4.1.

- List of all members, including inherited members

### Properties

- currentFrame : int
- framesPerSecond : int
- viewBox : QRect

- 1 property inherited from QObject

### Public Functions

- QSvgRenderer ( QObject * parent = 0 )
- QSvgRenderer ( const QString & filename, QObject * parent = 0 )
- QSvgRenderer ( const QByteArray & contents, QObject * parent = 0 )
- ~QSvgRenderer ()
- bool animated () const
- int animationDuration () const
- int currentFrame () const
- QSize defaultSize () const
- int framesPerSecond () const
- bool isValid () const
- void setCurrentFrame ( int )
- void setFramesPerSecond ( int num )
- void setViewBox ( const QRect & viewbox )
- QRect viewBox () const

- 28 public functions inherited from QObject

### Public Slots

- bool load ( const QString & filename )
- bool load ( const QByteArray & contents )
- void render ( QPainter * painter )

- 1 public slot inherited from QObject

### Signals

- void repaintNeeded ()

- 1 signal inherited from QObject

### Additional Inherited Members

- 4 static public members inherited from QObject
- 7 protected functions inherited from QObject

## Detailed Description

The QSvgRenderer class is used to draw the contents of SVG files onto paint devices.

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 the load() 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.

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 the viewBox 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 animationDuration() function provides the duration in milliseconds of the animation, without taking any looping into account.
- The currentFrame property contains the current frame of the animation.
- The framesPerSecond property contains the rate at which the animation plays.

See also QSvgWidget, QtSvg Module, SVG Viewer Example, and QPicture.

## Property Documentation

### currentFrame : int

This property holds the current frame of the document's animation, or 0 if the document is not animated.

Access functions:

- int currentFrame () const
- void setCurrentFrame ( int )

See also animationDuration(), framesPerSecond, and animated().

### 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.

Access functions:

- int framesPerSecond () const
- void setFramesPerSecond ( int num )

See also currentFrame, animationDuration(), and animated().

### viewBox : QRect

This property holds the rectangle specifying the visible area of the document in logical coordinates.

Access functions:

- QRect viewBox () const
- void setViewBox ( const QRect & viewbox )

## Member Function Documentation

### QSvgRenderer::QSvgRenderer ( QObject * parent = 0 )

Constructs a new renderer with the given parent.

### QSvgRenderer::QSvgRenderer ( const QString & filename, QObject * parent = 0 )

Constructs a new renderer with the given parent and loads the contents of the SVG file with the specified filename.

### QSvgRenderer::QSvgRenderer ( const QByteArray & contents, QObject * parent = 0 )

Constructs a new renderer with the given parent and loads the specified SVG format contents.

### QSvgRenderer::~QSvgRenderer ()

Destroys the renderer.

### bool QSvgRenderer::animated () const

Returns true if the current document contains animated elements; otherwise returns false.

See also currentFrame(), animationDuration(), and framesPerSecond().

### int QSvgRenderer::animationDuration () const

Returns the number of frames in the animation, or 0 if the current document is not animated.

See also animated(), currentFrame(), and framesPerSecond().

### QSize QSvgRenderer::defaultSize () const

Returns the default size of the document contents.

### bool QSvgRenderer::isValid () const

Returns true if there is a valid current document; otherwise returns false.

### bool QSvgRenderer::load ( const QString & filename ) `[slot]`

Loads the SVG file specified by filename.

### bool QSvgRenderer::load ( const QByteArray & contents ) `[slot]`

This is an overloaded member function, provided for convenience.

Loads the specified SVG format contents.

### void QSvgRenderer::render ( QPainter * painter ) `[slot]`

Renders the document, or current frame of an animated document, using the given painter.

### void QSvgRenderer::repaintNeeded () `[signal]`

This signal is emitted whenever the document needs to be updated, usually for the purposes of animation.