Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

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.

Note: All the functions in this class are reentrant.

This class was introduced in Qt 4.1.

Properties

  • 1 property inherited from QObject

Public Functions

  • 29 public functions inherited from QObject

Public Slots

  • bool load ( const QString & filename )
  • bool load ( const QByteArray & contents )
  • void render ( QPainter * painter )
  • void render ( QPainter * painter, const QRectF & bounds )
  • void render ( QPainter * painter, const QString & elementId, const QRectF & bounds = QRectF() )
  • 1 public slot inherited from QObject

Signals

Additional Inherited Members

  • 5 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. 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, QtSvg Module, SVG Viewer Example, and QPicture.


Property Documentation

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

viewBox : QRectF

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 )

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

This function was introduced in Qt 4.2.

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.

This function was introduced in Qt 4.2.

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, returning true if the content was successfully parsed; otherwise returns false.

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

This is an overloaded member function, provided for convenience.

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

QMatrix QSvgRenderer::matrixForElement ( const QString & id ) const

Returns the transformation matrix setup for the element with the given id. That includes the transformation on the element itself.

This function was introduced in Qt 4.2.

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

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]

This is an overloaded member function, provided for convenience.

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]

This is an overloaded member function, provided for convenience.

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

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 94
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 42
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 8
Page suivante

Le Qt Labs au hasard

Logo

Utiliser OpenCL avec Qt

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt qtextended4.4
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web