QGraphicsSvgItem¶
The
QGraphicsSvgItemclass is aQGraphicsItemthat can be used to render the contents of SVG files. More…

Synopsis¶
Functions¶
def
elementId()def
isCachingEnabled()def
maximumCacheSize()def
renderer()def
setCachingEnabled(arg__1)def
setElementId(id)def
setMaximumCacheSize(size)def
setSharedRenderer(renderer)
Detailed Description¶
QGraphicsSvgItemprovides a way of rendering SVG files ontoQGraphicsView.QGraphicsSvgItemcan be created by passing the SVG file to be rendered to its constructor or by explicit setting a sharedQSvgRendereron it.Note that setting
QSvgRendereron aQGraphicsSvgItemdoesn’t make the item take ownership of the renderer, therefore if usingsetSharedRenderer()method one has to make sure that the lifetime of theQSvgRendererobject will be at least as long as that of theQGraphicsSvgItem.
QGraphicsSvgItemprovides a way of rendering only parts of the SVG files via thesetElementId. IfsetElementId()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 direct manipulation of the items transformation matrix.
By default the SVG rendering is cached using
DeviceCoordinateCachemode to speedup the display of items. Caching can be disabled by passingNoCacheto thesetCacheMode()method.See also
QSvgWidgetQt SVG C++ ClassesQGraphicsItemQGraphicsView
- class PySide2.QtSvg.QGraphicsSvgItem([parentItem=None])¶
PySide2.QtSvg.QGraphicsSvgItem(fileName[, parentItem=None])
- param fileName:
str
- param parentItem:
Constructs a new SVG item with the given
parent.Constructs a new item with the given
parentand loads the contents of the SVG file with the specifiedfileName.
- PySide2.QtSvg.QGraphicsSvgItem.elementId()¶
- Return type:
str
This property holds the element’s XML ID.
- PySide2.QtSvg.QGraphicsSvgItem.isCachingEnabled()¶
- Return type:
bool
Use
cacheMode()instead.
- PySide2.QtSvg.QGraphicsSvgItem.maximumCacheSize()¶
- Return type:
This property holds the maximum size of the device coordinate cache for this item.
- PySide2.QtSvg.QGraphicsSvgItem.renderer()¶
- Return type:
Returns the currently use
QSvgRenderer.
- PySide2.QtSvg.QGraphicsSvgItem.setCachingEnabled(arg__1)¶
- Parameters:
arg__1 – bool
Use
setCacheMode()instead. Passing true to this function is equivalent tosetCacheMode(DeviceCoordinateCache).See also
- PySide2.QtSvg.QGraphicsSvgItem.setElementId(id)¶
- Parameters:
id – str
This property holds the element’s XML ID.
- PySide2.QtSvg.QGraphicsSvgItem.setMaximumCacheSize(size)¶
- Parameters:
size –
PySide2.QtCore.QSize
This property holds the maximum size of the device coordinate cache for this item.
- Parameters:
renderer –
PySide2.QtSvg.QSvgRenderer
Sets
rendererto be a sharedQSvgRendereron the item. By using this method one can share the sameQSvgRendereron a number of items. This means that the SVG file will be parsed only once.QSvgRendererpassed to this method has to exist for as long as this item is used.
© 2022 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.