CopperSpice API  1.7.2
QSvgRenderer Class Reference

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

Inheritance diagram for QSvgRenderer:
QObject

Public Signals

void repaintNeeded ()
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Slots

bool load (const QString &filename)
 
bool load (QXmlStreamReader *contents)
 
void render (QPainter *painter, const QRectF &bounds)
 
void render (QPainter *painter, const QString &elementId, const QRectF &bounds=QRectF ())
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QSvgRenderer (const QByteArray &contents, QObject *parent=nullptr)
 
 QSvgRenderer (const QString &filename, QObject *parent=nullptr)
 
 QSvgRenderer (QObject *parent=nullptr)
 
 QSvgRenderer (QXmlStreamReader *contents, QObject *parent=nullptr)
 
 ~QSvgRenderer ()
 
bool animated () const
 
QRectF boundsOnElement (const QString &id) const
 
QSize defaultSize () const
 
bool elementExists (const QString &id) const
 
bool isValid () const
 
bool load (const QByteArray &contents)) SVG_CS_SLOT_OVERLOAD_BOOL (load
 
QMatrix matrixForElement (const QString &id) const
 
void render (QPainter *painter)) CS_SLOT_OVERLOAD (render
 
QRect viewBox () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &objName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 

Properties

 framesPerSecond
 
 viewBox
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

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:

  • 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 the repaintNeeded() signal which is emitted whenever the rendering of the document needs to be updated.

See also
QSvgWidget, CsSvg library, QPicture

Constructor & Destructor Documentation

QSvgRenderer::QSvgRenderer ( QObject parent = nullptr)

Constructs a new renderer with the given parent.

QSvgRenderer::QSvgRenderer ( const QString filename,
QObject parent = nullptr 
)

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 = nullptr 
)

Constructs a new renderer with the given parent and loads the SVG data from the byte array specified by contents.

QSvgRenderer::QSvgRenderer ( QXmlStreamReader contents,
QObject parent = nullptr 
)

Constructs a new renderer with the given parent and loads the SVG data using the stream reader specified by contents.

QSvgRenderer::~QSvgRenderer ( )

Destroys the renderer.

Method Documentation

bool QSvgRenderer::animated ( ) const

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

See also
framesPerSecond()
QRectF QSvgRenderer::boundsOnElement ( const QString id) const

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
matrixForElement()
QSize QSvgRenderer::defaultSize ( ) const

Returns the default size of the document contents.

bool QSvgRenderer::elementExists ( const QString id) const

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.

bool QSvgRenderer::isValid ( ) const

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

bool QSvgRenderer::load ( const QByteArray contents)

Loads the specified SVG format contents, returning true if the content was successfully parsed, otherwise returns false.

bool QSvgRenderer::load ( const QString filename)
slot

Loads the SVG file specified by filename, returning true if the content was successfully parsed, otherwise returns false.

bool QSvgRenderer::load ( QXmlStreamReader contents)
slot

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 is null, behavior is undefined.

QMatrix QSvgRenderer::matrixForElement ( const QString id) const

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
boundsOnElement()
void QSvgRenderer::render ( QPainter painter)

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

void QSvgRenderer::render ( QPainter painter,
const QRectF bounds 
)
slot

Renders the current document, or the current frame of an animated document, using the given painter on the specified bounds within the painter. If the bounding rectangle is not specified the SVG file is mapped to the whole paint device.

void QSvgRenderer::render ( QPainter painter,
const QString elementId,
const QRectF bounds = QRectF() 
)
slot

Renders the given element with elementId using the given painter on the specified bounds. If the bounding rectangle is not specified the SVG element is mapped to the whole paint device.

void QSvgRenderer::repaintNeeded ( )
signal

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

QRect QSvgRenderer::viewBox ( ) const

Returns viewBoxF().toRect().

See also
setViewBox(), viewBoxF()

Property Documentation

QSvgRenderer::framesPerSecond

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
animated()
PropertiesClass Methods
read framesPerSecond
write setFramesPerSecond
QSvgRenderer::viewBox

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

PropertiesClass Methods
read viewBoxF
write cs_setViewBox