QGraphicsSvgItem

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

Inheritance diagram of PySide6.QtSvgWidgets.QGraphicsSvgItem

Synopsis

Functions

Detailed Description

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:

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 DeviceCoordinateCache mode to speedup the display of items. Caching can be disabled by passing NoCache to the setCacheMode() method.

See also

QSvgWidget Qt SVG C++ Classes QGraphicsItem QGraphicsView

class PySide6.QtSvgWidgets.QGraphicsSvgItem([parentItem=None])

PySide6.QtSvgWidgets.QGraphicsSvgItem(fileName[, parentItem=None])

Parameters

Constructs a new SVG item with the given parent.

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

PySide6.QtSvgWidgets.QGraphicsSvgItem.elementId()
Return type

str

This property holds the element’s XML ID.

PySide6.QtSvgWidgets.QGraphicsSvgItem.isCachingEnabled()
Return type

bool

Use cacheMode() instead.

PySide6.QtSvgWidgets.QGraphicsSvgItem.maximumCacheSize()
Return type

PySide6.QtCore.QSize

This property holds the maximum size of the device coordinate cache for this item.

PySide6.QtSvgWidgets.QGraphicsSvgItem.renderer()
Return type

PySide6.QtSvg.QSvgRenderer

Returns the currently use QSvgRenderer .

PySide6.QtSvgWidgets.QGraphicsSvgItem.setCachingEnabled(arg__1)
Parameters

arg__1 – bool

Use setCacheMode() instead. Passing true to this function is equivalent to setCacheMode ( DeviceCoordinateCache ).

PySide6.QtSvgWidgets.QGraphicsSvgItem.setElementId(id)
Parameters

id – str

This property holds the element’s XML ID.

PySide6.QtSvgWidgets.QGraphicsSvgItem.setMaximumCacheSize(size)
Parameters

sizePySide6.QtCore.QSize

This property holds the maximum size of the device coordinate cache for this item.

PySide6.QtSvgWidgets.QGraphicsSvgItem.setSharedRenderer(renderer)
Parameters

rendererPySide6.QtSvg.QSvgRenderer

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.