Home · All Classes · Modules

QSvgRenderer Class Reference
[QtSvg module]

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

Inherits QObject.

Methods

Qt Signals


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. QSvgRenderer provides the render() 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 the viewBox property.

Animated SVG drawings are supported, and can be controlled with a simple collection of functions and properties:

Finally, the QSvgRenderer class provides the repaintNeeded() signal which is emitted whenever the rendering of the document needs to be updated.

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


Method Documentation

QSvgRenderer.__init__ (self, QObject parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a new renderer with the given parent.

QSvgRenderer.__init__ (self, QString filename, QObject parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

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

QSvgRenderer.__init__ (self, QByteArray contents, QObject parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

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

bool QSvgRenderer.animated (self)

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

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

int QSvgRenderer.animationDuration (self)

int QSvgRenderer.currentFrame (self)

See also setCurrentFrame().

QSize QSvgRenderer.defaultSize (self)

Returns the default size of the document contents.

int QSvgRenderer.framesPerSecond (self)

bool QSvgRenderer.isValid (self)

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

bool QSvgRenderer.load (self, QString filename)

This method is also a Qt slot with the C++ signature bool load(const QString&).

Loads the SVG file specified by filename.

bool QSvgRenderer.load (self, QByteArray contents)

This method is also a Qt slot with the C++ signature bool load(const QByteArray&).

This is an overloaded member function, provided for convenience.

Loads the specified SVG format contents.

QSvgRenderer.render (self, QPainter p)

This method is also a Qt slot with the C++ signature void render(QPainter *).

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

QSvgRenderer.setCurrentFrame (self, int)

See also currentFrame().

QSvgRenderer.setFramesPerSecond (self, int num)

QSvgRenderer.setViewBox (self, QRect viewbox)

QRect QSvgRenderer.viewBox (self)


Qt Signal Documentation

void repaintNeeded ()

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


PyQt 4.0.1 for X11Copyright © Riverbank Computing Ltd and Trolltech AS 2006Qt 4.1.4