PySide6.QtSvgWidgets.QGraphicsSvgItem¶
- class QGraphicsSvgItem¶
- The - QGraphicsSvgItemclass is a QGraphicsItem that can be used to render the contents of SVG files. More…- Synopsis¶- Properties¶- Methods¶- def - __init__()
- def - elementId()
- def - renderer()
- def - setElementId()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - QGraphicsSvgItemprovides a way of rendering SVG files onto QGraphicsView.- QGraphicsSvgItemcan be created by passing the SVG file to be rendered to its constructor or by explicit setting a shared- QSvgRendereron it.- Note that setting - QSvgRendereron a- QGraphicsSvgItemdoesn’t make the item take ownership of the renderer, therefore if using- setSharedRenderer()method one has to make sure that the lifetime of the- QSvgRendererobject will be at least as long as that of the- QGraphicsSvgItem.- QGraphicsSvgItemprovides 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:- renderer = QSvgRenderer("SvgCardDeck.svg") black = QGraphicsSvgItem() red = QGraphicsSvgItem() black.setSharedRenderer(renderer) black.setElementId("black_joker") red.setSharedRenderer(renderer) red.setElementId("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 QGraphicsItem::DeviceCoordinateCache mode to speedup the display of items. Caching can be disabled by passing QGraphicsItem::NoCache to the QGraphicsItem::setCacheMode() method. - See also - QSvgWidgetQt SVG C++ Classes- QGraphicsItemQGraphicsView- Note - Properties can be used directly when - from __feature__ import true_propertyis used or via accessor functions otherwise.- property elementIdᅟ: str¶
 - This property holds the element’s XML ID. - Access functions:
 - This property holds the maximum size of the device coordinate cache for this item. - Access functions:
 - __init__([parentItem=None])¶
- Parameters:
- parentItem – - QGraphicsItem
 
 - Constructs a new SVG item with the given - parent.- __init__(fileName[, parentItem=None])
- Parameters:
- fileName – str 
- parentItem – - QGraphicsItem
 
 
 - Constructs a new item with the given - parentand loads the contents of the SVG file with the specified- fileName.- elementId()¶
- Return type:
- str 
 
 - Returns the XML ID the element that is currently being rendered. Returns an empty string if the whole file is being rendered. - See also - Getter of property - elementIdᅟ.- isCachingEnabled()¶
- Return type:
- bool 
 
 - Use QGraphicsItem::cacheMode() instead. - 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 - Getter of property - maximumCacheSizeᅟ.- renderer()¶
- Return type:
 
 - Returns the currently use - QSvgRenderer.- setCachingEnabled(caching)¶
- Parameters:
- caching – bool 
 
 - Use QGraphicsItem::setCacheMode() instead. Passing true to this function is equivalent to QGraphicsItem::setCacheMode(QGraphicsItem::DeviceCoordinateCache). - See also - setElementId(id)¶
- Parameters:
- id – str 
 
 - Sets the XML ID of the element to - id.- See also - Setter of property - elementIdᅟ.- 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 - Setter of property - maximumCacheSizeᅟ.- Parameters:
- renderer – - QSvgRenderer
 
 - Sets - rendererto be a shared- QSvgRendereron the item. By using this method one can share the same- QSvgRendereron 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.