QGraphicsSvgItem 類

The QGraphicsSvgItem 類是 QGraphicsItem 可用於渲染 SVG 文件的內容。 更多...

頭: #include <QGraphicsSvgItem>
Since: Qt 4.2
繼承: QGraphicsObject

特性

公共函數

QGraphicsSvgItem (QGraphicsItem * parent = 0)
QGraphicsSvgItem (const QString & fileName , QGraphicsItem * parent = 0)
QString elementId () const
QSize maximumCacheSize () const
QSvgRenderer * renderer () const
void setElementId (const QString & id )
void setMaximumCacheSize (const QSize & size )
void setSharedRenderer (QSvgRenderer * renderer )

重實現公共函數

virtual QRectF boundingRect () const
virtual void paint (QPainter * painter , const QStyleOptionGraphicsItem * option , QWidget * widget = 0)
virtual int type () const

額外繼承成員

詳細描述

The QGraphicsSvgItem 類是 QGraphicsItem 可用於渲染 SVG 文件的內容。

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.

注意,設置 QSvgRenderer 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 。若 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() 方法在 邊界矩形 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 () 方法。

另請參閱 QSvgWidget , QtSvg 模塊 , QGraphicsItem ,和 QGraphicsView .

特性文檔編製

elementId : QString

This property holds the element's XML ID.

該特性在 Qt 4.6 引入。

訪問函數:

QString elementId () const
void setElementId (const QString & id )

maximumCacheSize : QSize

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

該特性在 Qt 4.6 引入。

訪問函數:

QSize maximumCacheSize () const
void setMaximumCacheSize (const QSize & size )

成員函數文檔編製

QGraphicsSvgItem:: QGraphicsSvgItem ( QGraphicsItem * parent = 0)

構造新的 SVG 項采用給定 parent .

QGraphicsSvgItem:: QGraphicsSvgItem (const QString & fileName , QGraphicsItem * parent = 0)

構造新的項采用給定 parent and loads the contents of the SVG file with the specified fileName .

[虛擬] QRectF QGraphicsSvgItem:: boundingRect () const

重實現自 QGraphicsItem::boundingRect ().

返迴此項的邊界矩形。

[虛擬] void QGraphicsSvgItem:: paint ( QPainter * painter , const QStyleOptionGraphicsItem * option , QWidget * widget = 0)

重實現自 QGraphicsItem::paint ().

QSvgRenderer * QGraphicsSvgItem:: renderer () const

Returns the currently use QSvgRenderer .

void QGraphicsSvgItem:: setSharedRenderer ( 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 () const

重實現自 QGraphicsItem::type ().