QGraphicsSvgItem 类

The QGraphicsSvgItem 类是 QGraphicsItem 可用于渲染 SVG 文件的内容。 更多...

头: #include <QGraphicsSvgItem>
qmake: QT += svg
Since: Qt 4.2
继承: QGraphicsObject

特性

公共函数

QGraphicsSvgItem (QGraphicsItem * parent = Q_NULLPTR)
QGraphicsSvgItem (const QString & fileName , QGraphicsItem * parent = Q_NULLPTR)
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 override
virtual void paint (QPainter * painter , const QStyleOptionGraphicsItem * option , QWidget * widget = Q_NULLPTR) override
virtual int type () const override

额外继承成员

详细描述

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 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 , Qt SVG C++ 类 , 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 = Q_NULLPTR)

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

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

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

[override virtual] QRectF QGraphicsSvgItem:: boundingRect () const

重实现自 QGraphicsItem::boundingRect ().

返回此项的边界矩形。

QString QGraphicsSvgItem:: elementId () const

Returns the XML ID the element that is currently being rendered. Returns an empty string if the whole file is being rendered.

注意: Getter 函数对于特性 elementId .

另请参阅 setElementId ().

QSize QGraphicsSvgItem:: maximumCacheSize () const

Returns the current maximum size of the device coordinate cache for this item. If the item is cached using QGraphicsItem::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. QPixmapCache::cacheLimit () gives the cumulative bounds of the whole cache, whereas maximumCacheSize() refers to a maximum cache size for this particular item.

注意: Getter 函数对于特性 maximumCacheSize .

另请参阅 setMaximumCacheSize () 和 QGraphicsItem::cacheMode ().

[override virtual] void QGraphicsSvgItem:: paint ( QPainter * painter , const QStyleOptionGraphicsItem * option , QWidget * widget = Q_NULLPTR)

重实现自 QGraphicsItem::paint ().

QSvgRenderer *QGraphicsSvgItem:: renderer () const

Returns the currently use QSvgRenderer .

void QGraphicsSvgItem:: setElementId (const QString & id )

Sets the XML ID of the element to id .

注意: Setter 函数对于特性 elementId .

另请参阅 elementId ().

void QGraphicsSvgItem:: setMaximumCacheSize (const QSize & size )

Sets the maximum device coordinate cache size of the item to size . If the item is cached using QGraphicsItem::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 QPixmapCache::setCacheLimit () to set limitations on the whole cache and use setMaximumCacheSize() when setting cache size for individual items.

注意: Setter 函数对于特性 maximumCacheSize .

另请参阅 maximumCacheSize () 和 QGraphicsItem::cacheMode ().

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.

[override virtual] int QGraphicsSvgItem:: type () const

重实现自 QGraphicsItem::type ().