QGraphicsSvgItem Class Reference

[ QtSvg module]

QGraphicsSvgItem 类是 QGraphicsItem that can be used to render the contents of SVG files. 更多...

继承 QGraphicsObject .

方法


详细描述

QGraphicsSvgItem 类是 QGraphicsItem that can be used to render the contents of SVG files.

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:

 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 the 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 to the QGraphicsItem.setCacheMode () 方法。


方法文档编制

QGraphicsSvgItem.__init__ ( self , QGraphicsItem   parent  = None)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

构造新的 SVG 项采用给定 parent .

QGraphicsSvgItem.__init__ ( self , QString  fileName , QGraphicsItem   parent  = None)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

构造新的项采用给定 parent and loads the contents of the SVG file with the specified fileName .

QRectF QGraphicsSvgItem.boundingRect ( self )

重实现自 QGraphicsItem.boundingRect ().

返回此项的边界矩形。

QString QGraphicsSvgItem.elementId ( self )

bool QGraphicsSvgItem.isCachingEnabled ( self )

QSize QGraphicsSvgItem.maximumCacheSize ( self )

QGraphicsSvgItem.paint ( self , QPainter   painter , QStyleOptionGraphicsItem   option , QWidget   widget  = None)

重实现自 QGraphicsItem.paint ().

QSvgRenderer QGraphicsSvgItem.renderer ( self )

Returns the currently use QSvgRenderer .

QGraphicsSvgItem.setCachingEnabled ( self , bool)

QGraphicsSvgItem.setElementId ( self , QString  id )

QGraphicsSvgItem.setMaximumCacheSize ( self , QSize   size )

QGraphicsSvgItem.setSharedRenderer ( self , QSvgRenderer   renderer )

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.

int QGraphicsSvgItem.type ( self )

重实现自 QGraphicsItem.type ().