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  · 

QGraphicsSvgItem Class Reference
[QtSvg module]

The QGraphicsSvgItem class is a QGraphicsItem that can be used to render the contents of SVG files. More...

 #include <QGraphicsSvgItem>

Inherits QObject and QGraphicsItem.

This class was introduced in Qt 4.2.

Public Functions

Additional Inherited Members


Detailed Description

The QGraphicsSvgItem class is a QGraphicsItem that can be used to render the contents of SVG files.

QGraphicsSvgItem provides a way of rendering SVG files onto QGraphicsView. QGraphicsSvgItem can be created by passing the SVG file to be rendered to its constructor or by explicit setting a shared QSvgRenderer on it.

Note that setting QSvgRenderer on a QGraphicsSvgItem doesn't make the item take ownership of the renderer, therefore if using setSharedRenderer() method one has to make sure that the lifetime of the QSvgRenderer object will be at least as long as that of the QGraphicsSvgItem.

QGraphicsSvgItem provides a way of rendering only parts of the SVG files via the setElementId. If setElementId() method is called, only the SVG element (and its children) with the passed id will be renderer. This provides a convenient way of selectively rendering large SVG files that contain a number of discrete elements. For example the following code renders only jokers from a SVG file containing a whole card deck:

 QSvgRenderer *renderer = new QSvgRenderer(QLatin1String("SvgCardDeck.svg"));
 QGraphicsSvgItem *black = new QGraphicsSvgItem();
 QGraphicsSvgItem *red   = new QGraphicsSvgItem();

 black->setSharedRenderer(renderer);
 black->setElementId(QLatin1String("black_joker"));

 red->setSharedRenderer(renderer);
 red->setElementId(QLatin1String("red_joker"));

Size of the item can be set via the setSize() method or via direct manipulation of the items transformation matrix.

By default the SVG rendering is cached using QGraphicsItem::DeviceCoordinateCache mode to speedup the display of items. Caching can be disabled by passing QGraphicsItem::NoCache to the QGraphicsItem::setCacheMode() method.

See also QSvgWidget, QtSvg Module, QGraphicsItem, and QGraphicsView.


Member Function Documentation

QGraphicsSvgItem::QGraphicsSvgItem ( QGraphicsItem * parent = 0 )

Constructs a new SVG item with the given parent.

QGraphicsSvgItem::QGraphicsSvgItem ( const QString & fileName, QGraphicsItem * parent = 0 )

Constructs a new item with the given parent and loads the contents of the SVG file with the specified fileName.

QRectF QGraphicsSvgItem::boundingRect () const   [virtual]

Returns the bounding rectangle of this item.

Reimplemented from QGraphicsItem.

QString QGraphicsSvgItem::elementId () const

Returns the XML ID the element that is currently being renderer. Returns an empty string if the whole file is being rendered.

See also setElementId().

QSize QGraphicsSvgItem::maximumCacheSize () const

Returns the current maximum size of the device coordinate cache for this item. If the item is cached using QGraphicsItem::DeviceCoordinateCache mode, caching is bypassed if the extension of the item in device coordinates is larger than the maximum size.

The default maximum cache size is 1024x768. QPixmapCache::cacheLimit() gives the cumulative bounds of the whole cache, whereas maximumCacheSize() refers to a maximum cache size for this particular item.

See also setMaximumCacheSize() and QGraphicsItem::cacheMode().

QSvgRenderer * QGraphicsSvgItem::renderer () const

Returns the currently use QSvgRenderer.

void QGraphicsSvgItem::setElementId ( const QString & id )

Sets the XML ID of the element that this item should render to id.

See also elementId().

void QGraphicsSvgItem::setMaximumCacheSize ( const QSize & size )

Sets the maximum device coordinate cache size of the item to size. If the item is cached using QGraphicsItem::DeviceCoordinateCache mode, caching is bypassed if the extension of the item in device coordinates is larger than size.

The cache corresponds to the QPixmap which is used to cache the results of the rendering. Use QPixmapCache::setCacheLimit() to set limitations on the whole cache and use setMaximumCacheSize() when setting cache size for individual items.

See also maximumCacheSize() and QGraphicsItem::cacheMode().

void QGraphicsSvgItem::setSharedRenderer ( QSvgRenderer * renderer )

Sets renderer to be a shared QSvgRenderer on the item. By using this method one can share the same QSvgRenderer on a number of items. This means that the SVG file will be parsed only once. QSvgRenderer passed to this method has to exist for as long as this item is used.

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 59
  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. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  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. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Labs au hasard

Logo

Construire l'avenir : (ré-)introduction aux composants de Qt Quick

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