QGraphicsSvgItemclass is aQGraphicsItem可用于渲染 SVG 文件的内容。 更多 …
def
elementId
()
def
isCachingEnabled
()
def
maximumCacheSize
()
def
renderer
()
def
setCachingEnabled
(arg__1)
def
setElementId
(id)
def
setMaximumCacheSize
(size)
def
setSharedRenderer
(renderer)
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
QSvgRenderer在QGraphicsSvgItemdoesn’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。若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"));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 passingNoCache到setCacheMode()方法。另请参阅
QSvgWidgetQt SVG C++ 类QGraphicsItemQGraphicsView
QGraphicsSvgItem
(
[
parentItem=None
]
)
¶
QGraphicsSvgItem(fileName[, parentItem=None])
- param fileName
unicode
- param parentItem
QGraphicsItem
构造新的 SVG 项采用给定
parent
.
构造新的项采用给定
parent
and loads the contents of the SVG file with the specified
fileName
.
PySide2.QtSvg.QGraphicsSvgItem.
elementId
(
)
¶
unicode
Returns the XML ID the element that is currently being rendered. Returns an empty string if the whole file is being rendered.
另请参阅
PySide2.QtSvg.QGraphicsSvgItem.
isCachingEnabled
(
)
¶
bool
使用
cacheMode()
代替。
PySide2.QtSvg.QGraphicsSvgItem.
maximumCacheSize
(
)
¶
QSize
Returns the current maximum size of the device coordinate cache for this item. If the item is cached using
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.
cacheLimit()
gives the cumulative bounds of the whole cache, whereas refers to a maximum cache size for this particular item.
另请参阅
setMaximumCacheSize()
cacheMode()
PySide2.QtSvg.QGraphicsSvgItem.
renderer
(
)
¶
Returns the currently use
QSvgRenderer
.
PySide2.QtSvg.QGraphicsSvgItem.
setCachingEnabled
(
arg__1
)
¶
arg__1
–
bool
使用
setCacheMode()
instead. Passing true to this function is equivalent to
setCacheMode
(
DeviceCoordinateCache
).
另请参阅
PySide2.QtSvg.QGraphicsSvgItem.
setElementId
(
id
)
¶
id – unicode
Sets the XML ID of the element to
id
.
另请参阅
PySide2.QtSvg.QGraphicsSvgItem.
setMaximumCacheSize
(
size
)
¶
size
–
QSize
Sets the maximum device coordinate cache size of the item to
size
. If the item is cached using
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
setCacheLimit()
to set limitations on the whole cache and use when setting cache size for individual items.
另请参阅
maximumCacheSize()
cacheMode()
renderer
–
QSvgRenderer
集
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.