QSvgRenderer 类

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

头: #include <QSvgRenderer>
qmake: QT += svg
Since: Qt 4.1
继承: QObject

注意: 此类的所有函数 可重入 .

特性

公共函数

QSvgRenderer (QObject * parent = Q_NULLPTR)
QSvgRenderer (const QString & filename , QObject * parent = Q_NULLPTR)
QSvgRenderer (const QByteArray & contents , QObject * parent = Q_NULLPTR)
QSvgRenderer (QXmlStreamReader * contents , QObject * parent = Q_NULLPTR)
~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 ()

额外继承成员

详细描述

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

使用 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 提供 render () slot to render the current document, or the current frame of an animated document, using a given painter.

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 特性。

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

  • animated () function indicates whether a drawing contains animation information.
  • 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.

另请参阅 QSvgWidget , Qt SVG C++ 类 , SVG 查看器范例 ,和 QPicture .

特性文档编制

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.

访问函数:

int framesPerSecond () const
void setFramesPerSecond (int num )

另请参阅 animated ().

viewBox : QRectF

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

该特性在 Qt 4.2 引入。

访问函数:

QRectF viewBoxF () const
void setViewBox (const QRect & viewbox )
void setViewBox (const QRectF & viewbox )

成员函数文档编制

QSvgRenderer:: QSvgRenderer ( QObject * parent = Q_NULLPTR)

Constructs a new renderer with the given parent .

QSvgRenderer:: QSvgRenderer (const QString & filename , QObject * parent = Q_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 = Q_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 = Q_NULLPTR)

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

该函数在 Qt 4.5 引入。

QSvgRenderer:: ~QSvgRenderer ()

Destroys the renderer.

bool QSvgRenderer:: animated () const

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

另请参阅 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.

该函数在 Qt 4.2 引入。

另请参阅 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.

该函数在 Qt 4.2 引入。

bool QSvgRenderer:: isValid () const

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

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

Loads the SVG file specified by filename ,返回 true 若内容被成功剖析;否则返回 false。

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

加载指定 SVG 格式 contents ,返回 true 若内容被成功剖析;否则返回 false。

[slot] bool QSvgRenderer:: load ( QXmlStreamReader * contents )

Loads the specified SVG in contents ,返回 true 若内容被成功剖析;否则返回 false。

The reader will be used from where it currently is positioned. If contents is null , behavior is undefined.

该函数在 Qt 4.5 引入。

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

该函数在 Qt 4.2 引入。

另请参阅 boundsOnElement ().

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

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

[slot] void QSvgRenderer:: render ( QPainter * painter , const QRectF & bounds )

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.

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

Renders the given element with elementId 使用给定 painter on the specified bounds . 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.

QRect QSvgRenderer:: viewBox () const

返回 viewBoxF ().toRect().

另请参阅 setViewBox () 和 viewBoxF ().