|qmake:||QT += svg|
|QGraphicsSvgItem(QGraphicsItem * parent = 0)|
|QGraphicsSvgItem(const QString & fileName, QGraphicsItem * parent = 0)|
|QSvgRenderer *||renderer() const|
|void||setElementId(const QString & id)|
|void||setMaximumCacheSize(const QSize & size)|
|void||setSharedRenderer(QSvgRenderer * renderer)|
Reimplemented Public Functions
|virtual QRectF||boundingRect() const|
|virtual void||paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0)|
|virtual int||type() const|
- 2 public functions inherited from QGraphicsObject
- 31 public functions inherited from QObject
- 176 public functions inherited from QGraphicsItem
Additional Inherited Members
- 1 public slot inherited from QObject
- 9 signals inherited from QGraphicsObject
- 2 signals inherited from QObject
- 11 static public members inherited from QObject
- 2 static public members inherited from QGraphicsItem
- 1 protected function inherited from QGraphicsObject
- 9 protected functions inherited from QObject
- 24 protected functions inherited from QGraphicsItem
- 1 protected slot inherited from QGraphicsObject
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"));
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.
elementId : QString
This property holds the element's XML ID.
This property was introduced in Qt 4.6.
maximumCacheSize : QSize
This property holds the maximum size of the device coordinate cache for this item.
This property was introduced in Qt 4.6.
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.
[virtual] QRectF QGraphicsSvgItem::boundingRect() const
Reimplemented from QGraphicsItem::boundingRect().
Returns the bounding rectangle of this item.
QString QGraphicsSvgItem::elementId() const
Returns the XML ID the element that is currently being rendered. Returns an empty string if the whole file is being rendered.
Note: Getter function for property elementId.
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.
Note: Getter function for property maximumCacheSize.
[virtual] void QGraphicsSvgItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0)
Reimplemented from QGraphicsItem::paint().
QSvgRenderer * QGraphicsSvgItem::renderer() const
Returns the currently use QSvgRenderer.
void QGraphicsSvgItem::setElementId(const QString & id)
Sets the XML ID of the element to id.
Note: Setter function for property elementId.
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.
Note: Setter function for property maximumCacheSize.
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.
Reimplemented from QGraphicsItem::type().
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.