• PySide 模块
  • PySide.QtSvg
  • 内容表表

    上一话题

    QSvgRenderer

    下一话题

    QSvgWidget

    QGraphicsSvgItem

    详细描述

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

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

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

    PySide.QtSvg.QGraphicsSvgItem provides a way of rendering only parts of the SVG files via the setElementId. If PySide.QtSvg.QGraphicsSvgItem.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(QLatin1String("SvgCardDeck.svg"))
    black = QGraphicsSvgItem()
    red   = 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 PySide.QtCore.QRectF.setSize() 方法源于 bounding rectangle 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 QGraphicsItem.setCacheMode() 方法。

    class PySide.QtSvg. QGraphicsSvgItem ( [ parentItem=None ] )
    class PySide.QtSvg. QGraphicsSvgItem ( fileName [ , parentItem=None ] )
    参数:

    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 .

    PySide.QtSvg.QGraphicsSvgItem. elementId ( )
    返回类型: unicode

    This property holds the element's XML ID.

    PySide.QtSvg.QGraphicsSvgItem. isCachingEnabled ( )
    返回类型: PySide.QtCore.bool

    使用 QGraphicsItem.cacheMode() 代替。

    PySide.QtSvg.QGraphicsSvgItem. maximumCacheSize ( )
    返回类型: PySide.QtCore.QSize

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

    PySide.QtSvg.QGraphicsSvgItem. renderer ( )
    返回类型: PySide.QtSvg.QSvgRenderer

    Returns the currently use PySide.QtSvg.QSvgRenderer .

    PySide.QtSvg.QGraphicsSvgItem. setCachingEnabled ( arg__1 )
    参数: arg__1 PySide.QtCore.bool

    使用 QGraphicsItem.setCacheMode() instead. Passing true to this function is equivalent to QGraphicsItem::setCacheMode( QGraphicsItem.DeviceCoordinateCache ).

    PySide.QtSvg.QGraphicsSvgItem. setElementId ( id )
    参数: id – unicode

    This property holds the element's XML ID.

    PySide.QtSvg.QGraphicsSvgItem. setMaximumCacheSize ( size )
    参数: size PySide.QtCore.QSize

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

    PySide.QtSvg.QGraphicsSvgItem. setSharedRenderer ( renderer )
    参数: renderer PySide.QtSvg.QSvgRenderer

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