CopperSpice API  1.9.1
QGraphicsSvgItem Class Reference

The QGraphicsSvgItem class is a QGraphicsItem which can be used to render the contents of SVG files. More...

Inheritance diagram for QGraphicsSvgItem:
QGraphicsObject QObject QGraphicsItem

Public Methods

 QGraphicsSvgItem (const QString &fileName, QGraphicsItem *parent=nullptr)
 
 QGraphicsSvgItem (QGraphicsItem *parent=nullptr)
 
QRectF boundingRect () const override
 
bool isCachingEnabled () const
 
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr) override
 
QSvgRendererrenderer () const
 
void setCachingEnabled (bool caching)
 
void setSharedRenderer (QSvgRenderer *renderer)
 
int type () const override
 
- Public Methods inherited from QGraphicsObject
 QGraphicsObject (QGraphicsItem *parent=nullptr)
 
const QList< QObject * > & children () const
 
void grabGesture (Qt::GestureType gesture, Qt::GestureFlags flags=Qt::GestureFlags ())
 
void ungrabGesture (Qt::GestureType gesture)
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 
- Public Methods inherited from QGraphicsItem
 QGraphicsItem (QGraphicsItem *parent=nullptr)
 
virtual ~QGraphicsItem ()
 
bool acceptDrops () const
 
Qt::MouseButtons acceptedMouseButtons () const
 
bool acceptHoverEvents () const
 
bool acceptTouchEvents () const
 
virtual void advance (int phase)
 
QRegion boundingRegion (const QTransform &itemToDeviceTransform) const
 
qreal boundingRegionGranularity () const
 
CacheMode cacheMode () const
 
QList< QGraphicsItem * > childItems () const
 
QRectF childrenBoundingRect () const
 
void clearFocus ()
 
QPainterPath clipPath () const
 
virtual bool collidesWithItem (const QGraphicsItem *graphicsItem, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 
virtual bool collidesWithPath (const QPainterPath &path, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 
QList< QGraphicsItem * > collidingItems (Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 
QGraphicsItem * commonAncestorItem (const QGraphicsItem *graphicsItem) const
 
virtual bool contains (const QPointF &point) const
 
QCursor cursor () const
 
QVariant data (int key) const
 
QTransform deviceTransform (const QTransform &viewportTransform) const
 
qreal effectiveOpacity () const
 
void ensureVisible (const QRectF &rectF=QRectF (), int xmargin=50, int ymargin=50)
 
void ensureVisible (qreal x, qreal y, qreal width, qreal height, int xmargin=50, int ymargin=50)
 
bool filtersChildEvents () const
 
GraphicsItemFlags flags () const
 
QGraphicsItem * focusItem () const
 
QGraphicsItem * focusProxy () const
 
void grabKeyboard ()
 
void grabMouse ()
 
QGraphicsEffectgraphicsEffect () const
 
QGraphicsItemGroupgroup () const
 
bool handlesChildEvents () const
 
bool hasCursor () const
 
bool hasFocus () const
 
void hide ()
 
Qt::InputMethodHints inputMethodHints () const
 
void installSceneEventFilter (QGraphicsItem *filterItem)
 
bool isActive () const
 
bool isAncestorOf (const QGraphicsItem *graphicsItem) const
 
bool isBlockedByModalPanel (QGraphicsItem **blockingPanel=nullptr) const
 
bool isClipped () const
 
bool isEnabled () const
 
bool isObscured (const QRectF &rectF=QRectF ()) const
 
bool isObscured (qreal x, qreal y, qreal width, qreal height) const
 
virtual bool isObscuredBy (const QGraphicsItem *graphicsItem) const
 
bool isPanel () const
 
bool isSelected () const
 
bool isUnderMouse () const
 
bool isVisible () const
 
bool isVisibleTo (const QGraphicsItem *graphicsItem) const
 
bool isWidget () const
 
bool isWindow () const
 
QTransform itemTransform (const QGraphicsItem *graphicsItem, bool *ok=nullptr) const
 
QPainterPath mapFromItem (const QGraphicsItem *graphicsItem, const QPainterPath &path) const
 
QPointF mapFromItem (const QGraphicsItem *graphicsItem, const QPointF &point) const
 
QPolygonF mapFromItem (const QGraphicsItem *graphicsItem, const QPolygonF &polygon) const
 
QPolygonF mapFromItem (const QGraphicsItem *graphicsItem, const QRectF &rectF) const
 
QPointF mapFromItem (const QGraphicsItem *graphicsItem, qreal x, qreal y) const
 
QPolygonF mapFromItem (const QGraphicsItem *graphicsItem, qreal x, qreal y, qreal width, qreal height) const
 
QPainterPath mapFromParent (const QPainterPath &path) const
 
QPointF mapFromParent (const QPointF &point) const
 
QPolygonF mapFromParent (const QPolygonF &polygon) const
 
QPolygonF mapFromParent (const QRectF &rectF) const
 
QPointF mapFromParent (qreal x, qreal y) const
 
QPolygonF mapFromParent (qreal x, qreal y, qreal width, qreal height) const
 
QPainterPath mapFromScene (const QPainterPath &path) const
 
QPointF mapFromScene (const QPointF &point) const
 
QPolygonF mapFromScene (const QPolygonF &polygon) const
 
QPolygonF mapFromScene (const QRectF &rectF) const
 
QPointF mapFromScene (qreal x, qreal y) const
 
QPolygonF mapFromScene (qreal x, qreal y, qreal width, qreal height) const
 
QRectF mapRectFromItem (const QGraphicsItem *graphicsItem, const QRectF &rectF) const
 
QRectF mapRectFromItem (const QGraphicsItem *graphicsItem, qreal x, qreal y, qreal width, qreal height) const
 
QRectF mapRectFromParent (const QRectF &rectF) const
 
QRectF mapRectFromParent (qreal x, qreal y, qreal width, qreal height) const
 
QRectF mapRectFromScene (const QRectF &rectF) const
 
QRectF mapRectFromScene (qreal x, qreal y, qreal width, qreal height) const
 
QRectF mapRectToItem (const QGraphicsItem *graphicsItem, const QRectF &rectF) const
 
QRectF mapRectToItem (const QGraphicsItem *graphicsItem, qreal x, qreal y, qreal width, qreal height) const
 
QRectF mapRectToParent (const QRectF &rectF) const
 
QRectF mapRectToParent (qreal x, qreal y, qreal width, qreal height) const
 
QRectF mapRectToScene (const QRectF &rectF) const
 
QRectF mapRectToScene (qreal x, qreal y, qreal width, qreal height) const
 
QPainterPath mapToItem (const QGraphicsItem *graphicsItem, const QPainterPath &path) const
 
QPointF mapToItem (const QGraphicsItem *graphicsItem, const QPointF &point) const
 
QPolygonF mapToItem (const QGraphicsItem *graphicsItem, const QPolygonF &polygon) const
 
QPolygonF mapToItem (const QGraphicsItem *graphicsItem, const QRectF &rectF) const
 
QPointF mapToItem (const QGraphicsItem *graphicsItem, qreal x, qreal y) const
 
QPolygonF mapToItem (const QGraphicsItem *graphicsItem, qreal x, qreal y, qreal width, qreal height) const
 
QPainterPath mapToParent (const QPainterPath &path) const
 
QPointF mapToParent (const QPointF &point) const
 
QPolygonF mapToParent (const QPolygonF &polygon) const
 
QPolygonF mapToParent (const QRectF &rectF) const
 
QPointF mapToParent (qreal x, qreal y) const
 
QPolygonF mapToParent (qreal x, qreal y, qreal width, qreal height) const
 
QPainterPath mapToScene (const QPainterPath &path) const
 
QPointF mapToScene (const QPointF &point) const
 
QPolygonF mapToScene (const QPolygonF &polygon) const
 
QPolygonF mapToScene (const QRectF &rectF) const
 
QPointF mapToScene (qreal x, qreal y) const
 
QPolygonF mapToScene (qreal x, qreal y, qreal width, qreal height) const
 
QMatrix matrix () const
 
void moveBy (qreal dx, qreal dy)
 
qreal opacity () const
 
virtual QPainterPath opaqueArea () const
 
QGraphicsItem * panel () const
 
PanelModality panelModality () const
 
QGraphicsItem * parentItem () const
 
QGraphicsObjectparentObject () const
 
QGraphicsWidgetparentWidget () const
 
QPointF pos () const
 
void removeSceneEventFilter (QGraphicsItem *filterItem)
 
void resetMatrix ()
 
void resetTransform ()
 
qreal rotation () const
 
qreal scale () const
 
QGraphicsScenescene () const
 
QRectF sceneBoundingRect () const
 
QMatrix sceneMatrix () const
 
QPointF scenePos () const
 
QTransform sceneTransform () const
 
void scroll (qreal dx, qreal dy, const QRectF &rectF=QRectF ())
 
void setAcceptDrops (bool on)
 
void setAcceptedMouseButtons (Qt::MouseButtons buttons)
 
void setAcceptHoverEvents (bool enabled)
 
void setAcceptTouchEvents (bool enabled)
 
void setActive (bool active)
 
void setBoundingRegionGranularity (qreal granularity)
 
void setCacheMode (CacheMode mode, const QSize &cacheSize=QSize ())
 
void setCursor (const QCursor &cursor)
 
void setData (int key, const QVariant &value)
 
void setEnabled (bool enabled)
 
void setFiltersChildEvents (bool enabled)
 
void setFlag (GraphicsItemFlag flag, bool enabled=true)
 
void setFlags (GraphicsItemFlags flags)
 
void setFocus (Qt::FocusReason focusReason=Qt::OtherFocusReason)
 
void setFocusProxy (QGraphicsItem *graphicsItem)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 
void setGroup (QGraphicsItemGroup *group)
 
void setHandlesChildEvents (bool enabled)
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setMatrix (const QMatrix &matrix, bool combine=false)
 
void setOpacity (qreal opacity)
 
void setPanelModality (PanelModality panelModality)
 
void setParentItem (QGraphicsItem *parent)
 
void setPos (const QPointF &pos)
 
void setPos (qreal x, qreal y)
 
void setRotation (qreal angle)
 
void setScale (qreal factor)
 
void setSelected (bool selected)
 
void setToolTip (const QString &toolTip)
 
void setTransform (const QTransform &matrix, bool combine=false)
 
void setTransformations (const QList< QGraphicsTransform * > &transformations)
 
void setTransformOriginPoint (const QPointF &origin)
 
void setTransformOriginPoint (qreal x, qreal y)
 
void setVisible (bool visible)
 
void setX (qreal x)
 
void setY (qreal y)
 
void setZValue (qreal z)
 
virtual QPainterPath shape () const
 
void show ()
 
void stackBefore (const QGraphicsItem *graphicsItem)
 
QGraphicsObjecttoGraphicsObject ()
 
const QGraphicsObjecttoGraphicsObject () const
 
QString toolTip () const
 
QGraphicsItem * topLevelItem () const
 
QGraphicsWidgettopLevelWidget () const
 
QTransform transform () const
 
QList< QGraphicsTransform * > transformations () const
 
QPointF transformOriginPoint () const
 
void ungrabKeyboard ()
 
void ungrabMouse ()
 
void unsetCursor ()
 
void update (const QRectF &rectF=QRectF ())
 
void update (qreal x, qreal y, qreal width, qreal height)
 
QGraphicsWidgetwindow () const
 
qreal x () const
 
qreal y () const
 
qreal zValue () const
 

Properties

 elementId
 
 maximumCacheSize
 
- Properties inherited from QGraphicsObject
 effect
 
 enabled
 
 opacity
 
 parent
 
 pos
 
 rotation
 
 scale
 
 transformOriginPoint
 
 visible
 
 x
 
 y
 
 z
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Public Typedefs inherited from QGraphicsItem
using GraphicsItemFlags = QFlags< GraphicsItemFlag >
 
- Public Types inherited from QGraphicsItem
enum  CacheMode
 
enum  GraphicsItemChange
 
enum  GraphicsItemFlag
 
enum  PanelModality
 
- Public Signals inherited from QGraphicsObject
void enabledChanged ()
 
void opacityChanged ()
 
void parentChanged ()
 
void rotationChanged ()
 
void scaleChanged ()
 
void visibleChanged ()
 
void xChanged ()
 
void yChanged ()
 
void zChanged ()
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 
- Public Slots inherited from QObject
void deleteLater ()
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Static Public Members inherited from QGraphicsItem
static constexpr const int UserType = 65536
 
- Protected Slots inherited from QGraphicsObject
void updateMicroFocus ()
 
- Protected Methods inherited from QGraphicsObject
bool event (QEvent *event) override
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Protected Methods inherited from QGraphicsItem
virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *event)
 
virtual void dragEnterEvent (QGraphicsSceneDragDropEvent *event)
 
virtual void dragLeaveEvent (QGraphicsSceneDragDropEvent *event)
 
virtual void dragMoveEvent (QGraphicsSceneDragDropEvent *event)
 
virtual void dropEvent (QGraphicsSceneDragDropEvent *event)
 
virtual void focusInEvent (QFocusEvent *event)
 
virtual void focusOutEvent (QFocusEvent *event)
 
virtual void hoverEnterEvent (QGraphicsSceneHoverEvent *event)
 
virtual void hoverLeaveEvent (QGraphicsSceneHoverEvent *event)
 
virtual void hoverMoveEvent (QGraphicsSceneHoverEvent *event)
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 
virtual QVariant itemChange (GraphicsItemChange change, const QVariant &value)
 
virtual void keyPressEvent (QKeyEvent *event)
 
virtual void keyReleaseEvent (QKeyEvent *event)
 
virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event)
 
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event)
 
virtual void mousePressEvent (QGraphicsSceneMouseEvent *event)
 
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event)
 
void prepareGeometryChange ()
 
virtual bool sceneEvent (QEvent *event)
 
virtual bool sceneEventFilter (QGraphicsItem *watched, QEvent *event)
 
void updateMicroFocus ()
 
virtual void wheelEvent (QGraphicsSceneWheelEvent *event)
 

Detailed Description

The QGraphicsSvgItem class is a QGraphicsItem which can be used to render the contents of SVG files. This class 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.

Setting QSvgRenderer on a QGraphicsSvgItem does not 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("SvgCardDeck.svg");
black->setElementId("black_joker");
red->setElementId("red_joker");

Size of the item can be set via the setSize() method of the 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() method.

See also
QSvgWidget, CsSvg library, QGraphicsItem, QGraphicsView

Constructor & Destructor Documentation

QGraphicsSvgItem::QGraphicsSvgItem ( QGraphicsItem parent = nullptr)

Constructs a new SVG item with the given parent.

QGraphicsSvgItem::QGraphicsSvgItem ( const QString fileName,
QGraphicsItem parent = nullptr 
)

Constructs a new item with the given parent and loads the contents of the SVG file with the specified fileName.

Method Documentation

QRectF QGraphicsSvgItem::boundingRect ( ) const
overridevirtual

Returns the bounding rectangle of this item.

Implements QGraphicsItem::boundingRect()

bool QGraphicsSvgItem::isCachingEnabled ( ) const
deprecated
void QGraphicsSvgItem::paint ( QPainter painter,
const QStyleOptionGraphicsItem option,
QWidget widget = nullptr 
)
overridevirtual
QSvgRenderer * QGraphicsSvgItem::renderer ( ) const

Returns the currently use QSvgRenderer.

void QGraphicsSvgItem::setCachingEnabled ( bool  caching)
deprecated
Deprecated:
Use QGraphicsItem::setCacheMode() instead. Passing true to this function is equivalent to QGraphicsItem::setCacheMode(QGraphicsItem::DeviceCoordinateCache).
See also
isCachingEnabled()
void QGraphicsSvgItem::setSharedRenderer ( QSvgRenderer renderer)

Sets 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
overridevirtual

Reimplemented from QGraphicsItem::type()

Property Documentation

QGraphicsSvgItem::elementId

This property holds the element's XML ID.

PropertiesClass Methods
read elementId
write setElementId
QGraphicsSvgItem::maximumCacheSize

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

PropertiesClass Methods
read maximumCacheSize
write setMaximumCacheSize