Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QGraphicsSvgItem Class

TheQGraphicsSvgItem class is aQGraphicsItem that can be used to render the contents of SVG files.More...

Header:#include <QGraphicsSvgItem>
Since: Qt 4.2
Inherits:QGraphicsObject

Properties

Public Functions

QGraphicsSvgItem(QGraphicsItem * parent = 0)
QGraphicsSvgItem(const QString & fileName, QGraphicsItem * parent = 0)
QStringelementId() const
QSizemaximumCacheSize() const
QSvgRenderer *renderer() const
voidsetElementId(const QString & id)
voidsetMaximumCacheSize(const QSize & size)
voidsetSharedRenderer(QSvgRenderer * renderer)

Reimplemented Public Functions

virtual QRectFboundingRect() const
virtual voidpaint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0)
virtual inttype() const

Additional Inherited Members

Detailed Description

TheQGraphicsSvgItem class is aQGraphicsItem that can be used to render the contents of SVG files.

QGraphicsSvgItem provides a way of rendering SVG files ontoQGraphicsView.QGraphicsSvgItem can be created by passing the SVG file to be rendered to its constructor or by explicit setting a sharedQSvgRenderer on it.

Note that settingQSvgRenderer on aQGraphicsSvgItem doesn't make the item take ownership of the renderer, therefore if usingsetSharedRenderer() method one has to make sure that the lifetime of theQSvgRenderer object will be at least as long as that of theQGraphicsSvgItem.

QGraphicsSvgItem provides a way of rendering only parts of the SVG files via thesetElementId. IfsetElementId() 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=newQSvgRenderer(QLatin1String("SvgCardDeck.svg"));QGraphicsSvgItem*black=newQGraphicsSvgItem();QGraphicsSvgItem*red=newQGraphicsSvgItem();black->setSharedRenderer(renderer);black->setElementId(QLatin1String("black_joker"));red->setSharedRenderer(renderer);red->setElementId(QLatin1String("red_joker"));

Size of the item can be set via thesetSize() method of thebounding rectangle or via direct manipulation of the items transformation matrix.

By default the SVG rendering is cached usingQGraphicsItem::DeviceCoordinateCache mode to speedup the display of items. Caching can be disabled by passingQGraphicsItem::NoCache to theQGraphicsItem::setCacheMode() method.

See alsoQSvgWidget,QtSvg Module,QGraphicsItem, andQGraphicsView.

Property Documentation

elementId :QString

This property holds the element's XML ID.

This property was introduced in Qt 4.6.

Access functions:

QStringelementId() const
voidsetElementId(const QString & id)

maximumCacheSize :QSize

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

This property was introduced in Qt 4.6.

Access functions:

QSizemaximumCacheSize() const
voidsetMaximumCacheSize(const QSize & size)

Member Function Documentation

QGraphicsSvgItem::QGraphicsSvgItem(QGraphicsItem * parent = 0)

Constructs a new SVG item with the givenparent.

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

Constructs a new item with the givenparent and loads the contents of the SVG file with the specifiedfileName.

[virtual]QRectF QGraphicsSvgItem::boundingRect() const

Reimplemented fromQGraphicsItem::boundingRect().

Returns the bounding rectangle of this item.

[virtual]void QGraphicsSvgItem::paint(QPainter * painter, constQStyleOptionGraphicsItem * option,QWidget * widget = 0)

Reimplemented fromQGraphicsItem::paint().

QSvgRenderer * QGraphicsSvgItem::renderer() const

Returns the currently useQSvgRenderer.

void QGraphicsSvgItem::setSharedRenderer(QSvgRenderer * renderer)

Setsrenderer to be a sharedQSvgRenderer on the item. By using this method one can share the sameQSvgRenderer 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.

[virtual]int QGraphicsSvgItem::type() const

Reimplemented fromQGraphicsItem::type().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp