Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QGraphicsItem Class Referenceabstract

The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene. More...

#include <qgraphicsitem.h>

+ Inheritance diagram for QGraphicsItem:
+ Collaboration diagram for QGraphicsItem:

Public Types

enum  GraphicsItemFlag {
  ItemIsMovable = 0x1 , ItemIsSelectable = 0x2 , ItemIsFocusable = 0x4 , ItemClipsToShape = 0x8 ,
  ItemClipsChildrenToShape = 0x10 , ItemIgnoresTransformations = 0x20 , ItemIgnoresParentOpacity = 0x40 , ItemDoesntPropagateOpacityToChildren = 0x80 ,
  ItemStacksBehindParent = 0x100 , ItemUsesExtendedStyleOption = 0x200 , ItemHasNoContents = 0x400 , ItemSendsGeometryChanges = 0x800 ,
  ItemAcceptsInputMethod = 0x1000 , ItemNegativeZStacksBehindParent = 0x2000 , ItemIsPanel = 0x4000 , ItemIsFocusScope = 0x8000 ,
  ItemSendsScenePositionChanges = 0x10000 , ItemStopsClickFocusPropagation = 0x20000 , ItemStopsFocusHandling = 0x40000 , ItemContainsChildrenInShape = 0x80000
}
 This enum describes different flags that you can set on an item to toggle different features in the item's behavior. More...
 
enum  GraphicsItemChange {
  ItemPositionChange , ItemVisibleChange = 2 , ItemEnabledChange , ItemSelectedChange ,
  ItemParentChange , ItemChildAddedChange , ItemChildRemovedChange , ItemTransformChange ,
  ItemPositionHasChanged , ItemTransformHasChanged , ItemSceneChange , ItemVisibleHasChanged ,
  ItemEnabledHasChanged , ItemSelectedHasChanged , ItemParentHasChanged , ItemSceneHasChanged ,
  ItemCursorChange , ItemCursorHasChanged , ItemToolTipChange , ItemToolTipHasChanged ,
  ItemFlagsChange , ItemFlagsHaveChanged , ItemZValueChange , ItemZValueHasChanged ,
  ItemOpacityChange , ItemOpacityHasChanged , ItemScenePositionHasChanged , ItemRotationChange ,
  ItemRotationHasChanged , ItemScaleChange , ItemScaleHasChanged , ItemTransformOriginPointChange ,
  ItemTransformOriginPointHasChanged
}
 This enum describes the state changes that are notified by QGraphicsItem::itemChange(). More...
 
enum  CacheMode { NoCache , ItemCoordinateCache , DeviceCoordinateCache }
 
enum  PanelModality { NonModal , PanelModal , SceneModal }
 
enum  { Type = 1 , UserType = 65536 }
 

Public Member Functions

 QGraphicsItem (QGraphicsItem *parent=nullptr)
 Constructs a QGraphicsItem with the given parent item.
 
virtual ~QGraphicsItem ()
 Destroys the QGraphicsItem and all its children.
 
QGraphicsScenescene () const
 Returns the current scene for the item, or \nullptr if the item is not stored in a scene.
 
QGraphicsItemparentItem () const
 Returns a pointer to this item's parent item.
 
QGraphicsItemtopLevelItem () const
 Returns this item's top-level item.
 
QGraphicsObjectparentObject () const
 
QGraphicsWidgetparentWidget () const
 
QGraphicsWidgettopLevelWidget () const
 
QGraphicsWidgetwindow () const
 
QGraphicsItempanel () const
 
void setParentItem (QGraphicsItem *parent)
 Sets this item's parent item to newParent.
 
QList< QGraphicsItem * > childItems () const
 
bool isWidget () const
 
bool isWindow () const
 
bool isPanel () const
 
QGraphicsObjecttoGraphicsObject ()
 
const QGraphicsObjecttoGraphicsObject () const
 
QGraphicsItemGroupgroup () const
 Returns a pointer to this item's item group, or \nullptr if this item is not member of a group.
 
void setGroup (QGraphicsItemGroup *group)
 Adds this item to the item group group.
 
GraphicsItemFlags flags () const
 Returns this item's flags.
 
void setFlag (GraphicsItemFlag flag, bool enabled=true)
 If enabled is true, the item flag flag is enabled; otherwise, it is disabled.
 
void setFlags (GraphicsItemFlags flags)
 Sets the item flags to flags.
 
CacheMode cacheMode () const
 
void setCacheMode (CacheMode mode, const QSize &cacheSize=QSize())
 
PanelModality panelModality () const
 
void setPanelModality (PanelModality panelModality)
 
bool isBlockedByModalPanel (QGraphicsItem **blockingPanel=nullptr) const
 
QCursor cursor () const
 Returns the current cursor shape for the item.
 
void setCursor (const QCursor &cursor)
 Sets the current cursor shape for the item to cursor.
 
bool hasCursor () const
 Returns true if this item has a cursor set; otherwise, false is returned.
 
void unsetCursor ()
 Clears the cursor from this item.
 
bool isVisible () const
 Returns true if the item is visible; otherwise, false is returned.
 
bool isVisibleTo (const QGraphicsItem *parent) const
 
void setVisible (bool visible)
 If visible is true, the item is made visible.
 
void hide ()
 Hides the item (items are visible by default).
 
void show ()
 Shows the item (items are visible by default).
 
bool isEnabled () const
 Returns true if the item is enabled; otherwise, false is returned.
 
void setEnabled (bool enabled)
 If enabled is true, the item is enabled; otherwise, it is disabled.
 
bool isSelected () const
 Returns true if this item is selected; otherwise, false is returned.
 
void setSelected (bool selected)
 If selected is true and this item is selectable, this item is selected; otherwise, it is unselected.
 
bool acceptDrops () const
 Returns true if this item can accept drag and drop events; otherwise, returns false.
 
void setAcceptDrops (bool on)
 If on is true, this item will accept drag and drop events; otherwise, it is transparent for drag and drop events.
 
qreal opacity () const
 
qreal effectiveOpacity () const
 
void setOpacity (qreal opacity)
 
Qt::MouseButtons acceptedMouseButtons () const
 Returns the mouse buttons that this item accepts mouse events for.
 
void setAcceptedMouseButtons (Qt::MouseButtons buttons)
 Sets the mouse buttons that this item accepts mouse events for.
 
bool acceptHoverEvents () const
 
void setAcceptHoverEvents (bool enabled)
 
bool acceptTouchEvents () const
 
void setAcceptTouchEvents (bool enabled)
 
bool filtersChildEvents () const
 
void setFiltersChildEvents (bool enabled)
 
bool handlesChildEvents () const
 
void setHandlesChildEvents (bool enabled)
 
bool isActive () const
 
void setActive (bool active)
 
bool hasFocus () const
 Returns true if this item is active, and it or its \l{focusProxy()}{focus proxy} has keyboard input focus; otherwise, returns false.
 
void setFocus (Qt::FocusReason focusReason=Qt::OtherFocusReason)
 Gives keyboard input focus to this item.
 
void clearFocus ()
 Takes keyboard input focus from the item.
 
QGraphicsItemfocusProxy () const
 
void setFocusProxy (QGraphicsItem *item)
 
QGraphicsItemfocusItem () const
 
QGraphicsItemfocusScopeItem () const
 
void grabMouse ()
 
void ungrabMouse ()
 
void grabKeyboard ()
 
void ungrabKeyboard ()
 
QPointF pos () const
 Returns the position of the item in parent coordinates.
 
qreal x () const
 This convenience function is equivalent to calling pos().x().
 
void setX (qreal x)
 
qreal y () const
 This convenience function is equivalent to calling pos().y().
 
void setY (qreal y)
 
QPointF scenePos () const
 Returns the item's position in scene coordinates.
 
void setPos (const QPointF &pos)
 Sets the position of the item to pos, which is in parent coordinates.
 
void setPos (qreal x, qreal y)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling setPos(QPointF(x, y)).
 
void moveBy (qreal dx, qreal dy)
 Moves the item by dx points horizontally, and dy point vertically.
 
void ensureVisible (const QRectF &rect=QRectF(), int xmargin=50, int ymargin=50)
 If this item is part of a scene that is viewed by a QGraphicsView, this convenience function will attempt to scroll the view to ensure that rect is visible inside the view's viewport.
 
void ensureVisible (qreal x, qreal y, qreal w, qreal h, int xmargin=50, int ymargin=50)
 This convenience function is equivalent to calling ensureVisible(QRectF(x, y, w, h), xmargin, ymargin).
 
QTransform transform () const
 
QTransform sceneTransform () const
 
QTransform deviceTransform (const QTransform &viewportTransform) const
 
QTransform itemTransform (const QGraphicsItem *other, bool *ok=nullptr) const
 
void setTransform (const QTransform &matrix, bool combine=false)
 
void resetTransform ()
 
void setRotation (qreal angle)
 
qreal rotation () const
 
void setScale (qreal scale)
 
qreal scale () const
 
QList< QGraphicsTransform * > transformations () const
 
void setTransformations (const QList< QGraphicsTransform * > &transformations)
 
QPointF transformOriginPoint () const
 
void setTransformOriginPoint (const QPointF &origin)
 
void setTransformOriginPoint (qreal ax, qreal ay)
 
virtual void advance (int phase)
 This virtual function is called twice for all items by the QGraphicsScene::advance() slot.
 
qreal zValue () const
 Returns the Z-value of the item.
 
void setZValue (qreal z)
 Sets the Z-value of the item to z.
 
void stackBefore (const QGraphicsItem *sibling)
 
virtual QRectF boundingRect () const =0
 This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be restricted to inside an item's bounding rect.
 
QRectF childrenBoundingRect () const
 Returns the bounding rect of this item's descendants (i.e., its children, their children, etc.) in local coordinates.
 
QRectF sceneBoundingRect () const
 Returns the bounding rect of this item in scene coordinates, by combining sceneTransform() with boundingRect().
 
virtual QPainterPath shape () const
 Returns the shape of this item as a QPainterPath in local coordinates.
 
bool isClipped () const
 Returns true if this item is clipped.
 
QPainterPath clipPath () const
 
virtual bool contains (const QPointF &point) const
 Returns true if this item contains point, which is in local coordinates; otherwise, false is returned.
 
virtual bool collidesWithItem (const QGraphicsItem *other, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 Returns true if this item collides with other; otherwise returns false.
 
virtual bool collidesWithPath (const QPainterPath &path, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 Returns true if this item collides with path.
 
QList< QGraphicsItem * > collidingItems (Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 Returns a list of all items that collide with this item.
 
bool isObscured (const QRectF &rect=QRectF()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool isObscured (qreal x, qreal y, qreal w, qreal h) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
virtual bool isObscuredBy (const QGraphicsItem *item) const
 Returns true if this item's bounding rect is completely obscured by the opaque shape of item.
 
virtual QPainterPath opaqueArea () const
 This virtual function returns a shape representing the area where this item is opaque.
 
QRegion boundingRegion (const QTransform &itemToDeviceTransform) const
 
qreal boundingRegionGranularity () const
 
void setBoundingRegionGranularity (qreal granularity)
 
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr)=0
 This function, which is usually called by QGraphicsView, paints the contents of an item in local coordinates.
 
void update (const QRectF &rect=QRectF())
 Schedules a redraw of the area covered by rect in this item.
 
void update (qreal x, qreal y, qreal width, qreal height)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling update(QRectF(x, y, width, height)).
 
void scroll (qreal dx, qreal dy, const QRectF &rect=QRectF())
 
QPointF mapToItem (const QGraphicsItem *item, const QPointF &point) const
 Maps the point point, which is in this item's coordinate system, to item's coordinate system, and returns the mapped coordinate.
 
QPointF mapToParent (const QPointF &point) const
 Maps the point point, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped coordinate.
 
QPointF mapToScene (const QPointF &point) const
 Maps the point point, which is in this item's coordinate system, to the scene's coordinate system, and returns the mapped coordinate.
 
QPolygonF mapToItem (const QGraphicsItem *item, const QRectF &rect) const
 Maps the rectangle rect, which is in this item's coordinate system, to item's coordinate system, and returns the mapped rectangle as a polygon.
 
QPolygonF mapToParent (const QRectF &rect) const
 Maps the rectangle rect, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped rectangle as a polygon.
 
QPolygonF mapToScene (const QRectF &rect) const
 Maps the rectangle rect, which is in this item's coordinate system, to the scene's coordinate system, and returns the mapped rectangle as a polygon.
 
QRectF mapRectToItem (const QGraphicsItem *item, const QRectF &rect) const
 
QRectF mapRectToParent (const QRectF &rect) const
 
QRectF mapRectToScene (const QRectF &rect) const
 
QPolygonF mapToItem (const QGraphicsItem *item, const QPolygonF &polygon) const
 Maps the polygon polygon, which is in this item's coordinate system, to item's coordinate system, and returns the mapped polygon.
 
QPolygonF mapToParent (const QPolygonF &polygon) const
 Maps the polygon polygon, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped polygon.
 
QPolygonF mapToScene (const QPolygonF &polygon) const
 Maps the polygon polygon, which is in this item's coordinate system, to the scene's coordinate system, and returns the mapped polygon.
 
QPainterPath mapToItem (const QGraphicsItem *item, const QPainterPath &path) const
 Maps the path path, which is in this item's coordinate system, to item's coordinate system, and returns the mapped path.
 
QPainterPath mapToParent (const QPainterPath &path) const
 Maps the path path, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped path.
 
QPainterPath mapToScene (const QPainterPath &path) const
 Maps the path path, which is in this item's coordinate system, to the scene's coordinate system, and returns the mapped path.
 
QPointF mapFromItem (const QGraphicsItem *item, const QPointF &point) const
 Maps the point point, which is in item's coordinate system, to this item's coordinate system, and returns the mapped coordinate.
 
QPointF mapFromParent (const QPointF &point) const
 Maps the point point, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped coordinate.
 
QPointF mapFromScene (const QPointF &point) const
 Maps the point point, which is in this item's scene's coordinate system, to this item's coordinate system, and returns the mapped coordinate.
 
QPolygonF mapFromItem (const QGraphicsItem *item, const QRectF &rect) const
 Maps the rectangle rect, which is in item's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a polygon.
 
QPolygonF mapFromParent (const QRectF &rect) const
 Maps the rectangle rect, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a polygon.
 
QPolygonF mapFromScene (const QRectF &rect) const
 Maps the rectangle rect, which is in this item's scene's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a polygon.
 
QRectF mapRectFromItem (const QGraphicsItem *item, const QRectF &rect) const
 
QRectF mapRectFromParent (const QRectF &rect) const
 
QRectF mapRectFromScene (const QRectF &rect) const
 
QPolygonF mapFromItem (const QGraphicsItem *item, const QPolygonF &polygon) const
 Maps the polygon polygon, which is in item's coordinate system, to this item's coordinate system, and returns the mapped polygon.
 
QPolygonF mapFromParent (const QPolygonF &polygon) const
 Maps the polygon polygon, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped polygon.
 
QPolygonF mapFromScene (const QPolygonF &polygon) const
 Maps the polygon polygon, which is in this item's scene's coordinate system, to this item's coordinate system, and returns the mapped polygon.
 
QPainterPath mapFromItem (const QGraphicsItem *item, const QPainterPath &path) const
 Maps the path path, which is in item's coordinate system, to this item's coordinate system, and returns the mapped path.
 
QPainterPath mapFromParent (const QPainterPath &path) const
 Maps the path path, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped path.
 
QPainterPath mapFromScene (const QPainterPath &path) const
 Maps the path path, which is in this item's scene's coordinate system, to this item's coordinate system, and returns the mapped path.
 
QPointF mapToItem (const QGraphicsItem *item, qreal x, qreal y) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling mapToItem(item, QPointF(x, y)).
 
QPointF mapToParent (qreal x, qreal y) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling mapToParent(QPointF(x, y)).
 
QPointF mapToScene (qreal x, qreal y) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling mapToScene(QPointF(x, y)).
 
QPolygonF mapToItem (const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
 
QPolygonF mapToParent (qreal x, qreal y, qreal w, qreal h) const
 
QPolygonF mapToScene (qreal x, qreal y, qreal w, qreal h) const
 
QRectF mapRectToItem (const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
 
QRectF mapRectToParent (qreal x, qreal y, qreal w, qreal h) const
 
QRectF mapRectToScene (qreal x, qreal y, qreal w, qreal h) const
 
QPointF mapFromItem (const QGraphicsItem *item, qreal x, qreal y) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling mapFromItem(item, QPointF(x, y)).
 
QPointF mapFromParent (qreal x, qreal y) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling mapFromParent(QPointF(x, y)).
 
QPointF mapFromScene (qreal x, qreal y) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling mapFromScene(QPointF(x, y)).
 
QPolygonF mapFromItem (const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
 
QPolygonF mapFromParent (qreal x, qreal y, qreal w, qreal h) const
 
QPolygonF mapFromScene (qreal x, qreal y, qreal w, qreal h) const
 
QRectF mapRectFromItem (const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
 
QRectF mapRectFromParent (qreal x, qreal y, qreal w, qreal h) const
 
QRectF mapRectFromScene (qreal x, qreal y, qreal w, qreal h) const
 
bool isAncestorOf (const QGraphicsItem *child) const
 Returns true if this item is an ancestor of child (i.e., if this item is child's parent, or one of child's parent's ancestors).
 
QGraphicsItemcommonAncestorItem (const QGraphicsItem *other) const
 
bool isUnderMouse () const
 
QVariant data (int key) const
 Returns this item's custom data for the key key as a QVariant.
 
void setData (int key, const QVariant &value)
 Sets this item's custom data for the key key to value.
 
Qt::InputMethodHints inputMethodHints () const
 Returns the current input method hints of this item.
 
void setInputMethodHints (Qt::InputMethodHints hints)
 Sets the current input method hints of this item to hints.
 
virtual int type () const
 Returns the type of an item as an int.
 
void installSceneEventFilter (QGraphicsItem *filterItem)
 Installs an event filter for this item on filterItem, causing all events for this item to first pass through filterItem's sceneEventFilter() function.
 
void removeSceneEventFilter (QGraphicsItem *filterItem)
 Removes an event filter on this item from filterItem.
 

Protected Types

enum  Extension { UserExtension = 0x80000000 }
 

Protected Member Functions

void updateMicroFocus ()
 Updates the item's micro focus.
 
virtual bool sceneEventFilter (QGraphicsItem *watched, QEvent *event)
 Filters events for the item watched.
 
virtual bool sceneEvent (QEvent *event)
 This virtual function receives events to this item.
 
virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *event)
 This event handler can be reimplemented in a subclass to process context menu events.
 
virtual void dragEnterEvent (QGraphicsSceneDragDropEvent *event)
 This event handler, for event event, can be reimplemented to receive drag enter events for this item.
 
virtual void dragLeaveEvent (QGraphicsSceneDragDropEvent *event)
 This event handler, for event event, can be reimplemented to receive drag leave events for this item.
 
virtual void dragMoveEvent (QGraphicsSceneDragDropEvent *event)
 This event handler, for event event, can be reimplemented to receive drag move events for this item.
 
virtual void dropEvent (QGraphicsSceneDragDropEvent *event)
 This event handler, for event event, can be reimplemented to receive drop events for this item.
 
virtual void focusInEvent (QFocusEvent *event)
 This event handler, for event event, can be reimplemented to receive focus in events for this item.
 
virtual void focusOutEvent (QFocusEvent *event)
 This event handler, for event event, can be reimplemented to receive focus out events for this item.
 
virtual void hoverEnterEvent (QGraphicsSceneHoverEvent *event)
 This event handler, for event event, can be reimplemented to receive hover enter events for this item.
 
virtual void hoverMoveEvent (QGraphicsSceneHoverEvent *event)
 This event handler, for event event, can be reimplemented to receive hover move events for this item.
 
virtual void hoverLeaveEvent (QGraphicsSceneHoverEvent *event)
 This event handler, for event event, can be reimplemented to receive hover leave events for this item.
 
virtual void keyPressEvent (QKeyEvent *event)
 This event handler, for event event, can be reimplemented to receive key press events for this item.
 
virtual void keyReleaseEvent (QKeyEvent *event)
 This event handler, for event event, can be reimplemented to receive key release events for this item.
 
virtual void mousePressEvent (QGraphicsSceneMouseEvent *event)
 This event handler, for event event, can be reimplemented to receive mouse press events for this item.
 
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event)
 This event handler, for event event, can be reimplemented to receive mouse move events for this item.
 
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event)
 This event handler, for event event, can be reimplemented to receive mouse release events for this item.
 
virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event)
 This event handler, for event event, can be reimplemented to receive mouse double-click events for this item.
 
virtual void wheelEvent (QGraphicsSceneWheelEvent *event)
 This event handler, for event event, can be reimplemented to receive wheel events for this item.
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 This event handler, for event event, can be reimplemented to receive input method events for this item.
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 This method is only relevant for input items.
 
virtual QVariant itemChange (GraphicsItemChange change, const QVariant &value)
 This virtual function is called by QGraphicsItem to notify custom items that some part of the item's state changes.
 
virtual bool supportsExtension (Extension extension) const
 
virtual void setExtension (Extension extension, const QVariant &variant)
 
virtual QVariant extension (const QVariant &variant) const
 
 QGraphicsItem (QGraphicsItemPrivate &dd, QGraphicsItem *parent)
 
void addToIndex ()
 
void removeFromIndex ()
 
void prepareGeometryChange ()
 Prepares the item for a geometry change.
 

Protected Attributes

QScopedPointer< QGraphicsItemPrivated_ptr
 

Friends

class QGraphicsItemGroup
 
class QGraphicsScene
 
class QGraphicsScenePrivate
 
class QGraphicsSceneFindItemBspTreeVisitor
 
class QGraphicsSceneBspTree
 
class QGraphicsView
 
class QGraphicsViewPrivate
 
class QGraphicsObject
 
class QGraphicsWidget
 
class QGraphicsWidgetPrivate
 
class QGraphicsProxyWidgetPrivate
 
class QGraphicsSceneIndex
 
class QGraphicsSceneIndexPrivate
 
class QGraphicsSceneBspTreeIndex
 
class QGraphicsSceneBspTreeIndexPrivate
 
class QGraphicsItemEffectSourcePrivate
 
class QGraphicsTransformPrivate
 
class QGestureManager
 
class ::tst_QGraphicsItem
 
bool qt_closestLeaf (const QGraphicsItem *, const QGraphicsItem *)
 
bool qt_closestItemFirst (const QGraphicsItem *, const QGraphicsItem *)
 Returns true if item1 is on top of item2.
 

Related Symbols

(Note that these are not member symbols.)

template< class T > qgraphicsitem_cast (QGraphicsItem *item)
 

Detailed Description

The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.

Since
4.2

\inmodule QtWidgets

It provides a light-weight foundation for writing your own custom items. This includes defining the item's geometry, collision detection, its painting implementation and item interaction through its event handlers. QGraphicsItem is part of the \l{Graphics View Framework}

For convenience, Qt provides a set of standard graphics items for the most common shapes. These are:

\list

All of an item's geometric information is based on its local coordinate system. The item's position, pos(), is the only function that does not operate in local coordinates, as it returns a position in parent coordinates. \l {The Graphics View Coordinate System} describes the coordinate system in detail.

You can set whether an item should be visible (i.e., drawn, and accepting events), by calling setVisible(). Hiding an item will also hide its children. Similarly, you can enable or disable an item by calling setEnabled(). If you disable an item, all its children will also be disabled. By default, items are both visible and enabled. To toggle whether an item is selected or not, first enable selection by setting the ItemIsSelectable flag, and then call setSelected(). Normally, selection is toggled by the scene, as a result of user interaction.

To write your own graphics item, you first create a subclass of QGraphicsItem, and then start by implementing its two pure virtual public functions: boundingRect(), which returns an estimate of the area painted by the item, and paint(), which implements the actual painting. For example:

class SimpleItem : public QGraphicsItem
{
public:
QRectF boundingRect() const override
{
qreal penWidth = 1;
return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,
20 + penWidth, 20 + penWidth);
}
QWidget *widget) override
{
painter->drawRoundedRect(-10, -10, 20, 20, 5, 5);
}
};

The boundingRect() function has many different purposes. QGraphicsScene bases its item index on boundingRect(), and QGraphicsView uses it both for culling invisible items, and for determining the area that needs to be recomposed when drawing overlapping items. In addition, QGraphicsItem's collision detection mechanisms use boundingRect() to provide an efficient cut-off. The fine grained collision algorithm in collidesWithItem() is based on calling shape(), which returns an accurate outline of the item's shape as a QPainterPath.

QGraphicsScene expects all items boundingRect() and shape() to remain unchanged unless it is notified. If you want to change an item's geometry in any way, you must first call prepareGeometryChange() to allow QGraphicsScene to update its bookkeeping.

Collision detection can be done in two ways:

\list 1

  • Reimplement shape() to return an accurate shape for your item, and rely on the default implementation of collidesWithItem() to do shape-shape intersection. This can be rather expensive if the shapes are complex.
  • Reimplement collidesWithItem() to provide your own custom item and shape collision algorithm.

\endlist

The contains() function can be called to determine whether the item contains a point or not. This function can also be reimplemented by the item. The default behavior of contains() is based on calling shape().

Items can contain other items, and also be contained by other items. All items can have a parent item and a list of children. Unless the item has no parent, its position is in parent coordinates (i.e., the parent's local coordinates). Parent items propagate both their position and their transformation to all children.

Definition at line 46 of file qgraphicsitem.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
Type 
UserType 

Definition at line 356 of file qgraphicsitem.h.

◆ CacheMode

Since
4.4

This enum describes QGraphicsItem's cache modes. Caching is used to speed up rendering by allocating and rendering to an off-screen pixel buffer, which can be reused when the item requires redrawing. For some paint devices, the cache is stored directly in graphics memory, which makes rendering very quick.

\value NoCache The default; all item caching is disabled. QGraphicsItem::paint() is called every time the item needs redrawing.

\value ItemCoordinateCache Caching is enabled for the item's logical (local) coordinate system. QGraphicsItem creates an off-screen pixel buffer with a configurable size / resolution that you can pass to QGraphicsItem::setCacheMode(). Rendering quality will typically degrade, depending on the resolution of the cache and the item transformation. The first time the item is redrawn, it will render itself into the cache, and the cache is then reused for every subsequent expose. The cache is also reused as the item is transformed. To adjust the resolution of the cache, you can call setCacheMode() again.

\value DeviceCoordinateCache Caching is enabled at the paint device level, in device coordinates. This mode is for items that can move, but are not rotated, scaled or sheared. If the item is transformed directly or indirectly, the cache will be regenerated automatically. Unlike ItemCoordinateCacheMode, DeviceCoordinateCache always renders at maximum quality.

See also
QGraphicsItem::setCacheMode()
Enumerator
NoCache 
ItemCoordinateCache 
DeviceCoordinateCache 

Definition at line 110 of file qgraphicsitem.h.

◆ Extension

enum QGraphicsItem::Extension
protected

Note: This is provided as a hook to avoid future problems related to adding virtual functions. See also extension(), supportsExtension() and setExtension().

Enumerator
UserExtension 

Definition at line 391 of file qgraphicsitem.h.

◆ GraphicsItemChange

This enum describes the state changes that are notified by QGraphicsItem::itemChange().

The notifications are sent as the state changes, and in some cases, adjustments can be made (see the documentation for each change for details).

Note: Be careful with calling functions on the QGraphicsItem itself inside itemChange(), as certain function calls can lead to unwanted recursion. For example, you cannot call setPos() in itemChange() on an ItemPositionChange notification, as the setPos() function will again call itemChange(ItemPositionChange). Instead, you can return the new, adjusted position from itemChange().

\value ItemEnabledChange The item's enabled state changes. If the item is presently enabled, it will become disabled, and vice verca. The value argument is the new enabled state (i.e., true or false). Do not call setEnabled() in itemChange() as this notification is delivered. Instead, you can return the new state from itemChange().

\value ItemEnabledHasChanged The item's enabled state has changed. The value argument is the new enabled state (i.e., true or false). Do not call setEnabled() in itemChange() as this notification is delivered. The return value is ignored.

\value ItemPositionChange The item's position changes. This notification is sent if the ItemSendsGeometryChanges flag is enabled, and when the item's local position changes, relative to its parent (i.e., as a result of calling setPos() or moveBy()). The value argument is the new position (i.e., a QPointF). You can call pos() to get the original position. Do not call setPos() or moveBy() in itemChange() as this notification is delivered; instead, you can return the new, adjusted position from itemChange(). After this notification, QGraphicsItem immediately sends the ItemPositionHasChanged notification if the position changed.

\value ItemPositionHasChanged The item's position has changed. This notification is sent if the ItemSendsGeometryChanges flag is enabled, and after the item's local position, relative to its parent, has changed. The value argument is the new position (the same as pos()), and QGraphicsItem ignores the return value for this notification (i.e., a read-only notification).

\value ItemTransformChange The item's transformation matrix changes. This notification is sent if the ItemSendsGeometryChanges flag is enabled, and when the item's local transformation matrix changes (i.e., as a result of calling setTransform(). The value argument is the new matrix (i.e., a QTransform); to get the old matrix, call transform(). Do not call setTransform() or set any of the transformation properties in itemChange() as this notification is delivered; instead, you can return the new matrix from itemChange(). This notification is not sent if you change the transformation properties.

\value ItemTransformHasChanged The item's transformation matrix has changed either because setTransform is called, or one of the transformation properties is changed. This notification is sent if the ItemSendsGeometryChanges flag is enabled, and after the item's local transformation matrix has changed. The value argument is the new matrix (same as transform()), and QGraphicsItem ignores the return value for this notification (i.e., a read-only notification).

\value ItemRotationChange The item's rotation property changes. This notification is sent if the ItemSendsGeometryChanges flag is enabled, and when the item's rotation property changes (i.e., as a result of calling setRotation()). The value argument is the new rotation (i.e., a double); to get the old rotation, call rotation(). Do not call setRotation() in itemChange() as this notification is delivered; instead, you can return the new rotation from itemChange().

\value ItemRotationHasChanged The item's rotation property has changed. This notification is sent if the ItemSendsGeometryChanges flag is enabled, and after the item's rotation property has changed. The value argument is the new rotation (i.e., a double), and QGraphicsItem ignores the return value for this notification (i.e., a read-only notification). Do not call setRotation() in itemChange() as this notification is delivered.

\value ItemScaleChange The item's scale property changes. This notification is sent if the ItemSendsGeometryChanges flag is enabled, and when the item's scale property changes (i.e., as a result of calling setScale()). The value argument is the new scale (i.e., a double); to get the old scale, call scale(). Do not call setScale() in itemChange() as this notification is delivered; instead, you can return the new scale from itemChange().

\value ItemScaleHasChanged The item's scale property has changed. This notification is sent if the ItemSendsGeometryChanges flag is enabled, and after the item's scale property has changed. The value argument is the new scale (i.e., a double), and QGraphicsItem ignores the return value for this notification (i.e., a read-only notification). Do not call setScale() in itemChange() as this notification is delivered.

\value ItemTransformOriginPointChange The item's transform origin point property changes. This notification is sent if the ItemSendsGeometryChanges flag is enabled, and when the item's transform origin point property changes (i.e., as a result of calling setTransformOriginPoint()). The value argument is the new origin point (i.e., a QPointF); to get the old origin point, call transformOriginPoint(). Do not call setTransformOriginPoint() in itemChange() as this notification is delivered; instead, you can return the new transform origin point from itemChange().

\value ItemTransformOriginPointHasChanged The item's transform origin point property has changed. This notification is sent if the ItemSendsGeometryChanges flag is enabled, and after the item's transform origin point property has changed. The value argument is the new origin point (i.e., a QPointF), and QGraphicsItem ignores the return value for this notification (i.e., a read-only notification). Do not call setTransformOriginPoint() in itemChange() as this notification is delivered.

\value ItemSelectedChange The item's selected state changes. If the item is presently selected, it will become unselected, and vice verca. The value argument is the new selected state (i.e., true or false). Do not call setSelected() in itemChange() as this notification is delivered; instead, you can return the new selected state from itemChange().

\value ItemSelectedHasChanged The item's selected state has changed. The value argument is the new selected state (i.e., true or false). Do not call setSelected() in itemChange() as this notification is delivered. The return value is ignored.

\value ItemVisibleChange The item's visible state changes. If the item is presently visible, it will become invisible, and vice verca. The value argument is the new visible state (i.e., true or false). Do not call setVisible() in itemChange() as this notification is delivered; instead, you can return the new visible state from itemChange().

\value ItemVisibleHasChanged The item's visible state has changed. The value argument is the new visible state (i.e., true or false). Do not call setVisible() in itemChange() as this notification is delivered. The return value is ignored.

\value ItemParentChange The item's parent changes. The value argument is the new parent item (i.e., a QGraphicsItem pointer). Do not call setParentItem() in itemChange() as this notification is delivered; instead, you can return the new parent from itemChange().

\value ItemParentHasChanged The item's parent has changed. The value argument is the new parent (i.e., a pointer to a QGraphicsItem). Do not call setParentItem() in itemChange() as this notification is delivered. The return value is ignored.

\value ItemChildAddedChange A child is added to this item. The value argument is the new child item (i.e., a QGraphicsItem pointer). Do not pass this item to any item's setParentItem() function as this notification is delivered. The return value is unused; you cannot adjust anything in this notification. Note that the new child might not be fully constructed when this notification is sent; calling pure virtual functions on the child can lead to a crash.

\value ItemChildRemovedChange A child is removed from this item. The value argument is the child item that is about to be removed (i.e., a QGraphicsItem pointer). The return value is unused; you cannot adjust anything in this notification.

\value ItemSceneChange The item is moved to a new scene. This notification is also sent when the item is added to its initial scene, and when it is removed. The item's scene() is the old scene, or \nullptr if the item has not been added to a scene yet. The value argument is the new scene (i.e., a QGraphicsScene pointer), or \nullptr if the item is removed from a scene. Do not override this change by passing this item to QGraphicsScene::addItem() as this notification is delivered; instead, you can return the new scene from itemChange(). Use this feature with caution; objecting to a scene change can quickly lead to unwanted recursion.

\value ItemSceneHasChanged The item's scene has changed. The item's scene() is the new scene. This notification is also sent when the item is added to its initial scene, and when it is removed.The value argument is the new scene (i.e., a pointer to a QGraphicsScene). Do not call setScene() in itemChange() as this notification is delivered. The return value is ignored.

\value ItemCursorChange The item's cursor changes. The value argument is the new cursor (i.e., a QCursor). Do not call setCursor() in itemChange() as this notification is delivered. Instead, you can return a new cursor from itemChange().

\value ItemCursorHasChanged The item's cursor has changed. The value argument is the new cursor (i.e., a QCursor). Do not call setCursor() as this notification is delivered. The return value is ignored.

\value ItemToolTipChange The item's tooltip changes. The value argument is the new tooltip (i.e., a QToolTip). Do not call setToolTip() in itemChange() as this notification is delivered. Instead, you can return a new tooltip from itemChange().

\value ItemToolTipHasChanged The item's tooltip has changed. The value argument is the new tooltip (i.e., a QToolTip). Do not call setToolTip() as this notification is delivered. The return value is ignored.

\value ItemFlagsChange The item's flags change. The value argument is the new flags (i.e., a quint32). Do not call setFlags() in itemChange() as this notification is delivered. Instead, you can return the new flags from itemChange().

\value ItemFlagsHaveChanged The item's flags have changed. The value argument is the new flags (i.e., a quint32). Do not call setFlags() in itemChange() as this notification is delivered. The return value is ignored.

\value ItemZValueChange The item's Z-value changes. The value argument is the new Z-value (i.e., a double). Do not call setZValue() in itemChange() as this notification is delivered. Instead, you can return a new Z-value from itemChange().

\value ItemZValueHasChanged The item's Z-value has changed. The value argument is the new Z-value (i.e., a double). Do not call setZValue() as this notification is delivered. The return value is ignored.

\value ItemOpacityChange The item's opacity changes. The value argument is the new opacity (i.e., a double). Do not call setOpacity() in itemChange() as this notification is delivered. Instead, you can return a new opacity from itemChange().

\value ItemOpacityHasChanged The item's opacity has changed. The value argument is the new opacity (i.e., a double). Do not call setOpacity() as this notification is delivered. The return value is ignored.

\value ItemScenePositionHasChanged The item's scene position has changed. This notification is sent if the ItemSendsScenePositionChanges flag is enabled, and after the item's scene position has changed (i.e., the position or transformation of the item itself or the position or transformation of any ancestor has changed). The value argument is the new scene position (the same as scenePos()), and QGraphicsItem ignores the return value for this notification (i.e., a read-only notification).

Enumerator
ItemPositionChange 
ItemVisibleChange 
ItemEnabledChange 
ItemSelectedChange 
ItemParentChange 
ItemChildAddedChange 
ItemChildRemovedChange 
ItemTransformChange 
ItemPositionHasChanged 
ItemTransformHasChanged 
ItemSceneChange 
ItemVisibleHasChanged 
ItemEnabledHasChanged 
ItemSelectedHasChanged 
ItemParentHasChanged 
ItemSceneHasChanged 
ItemCursorChange 
ItemCursorHasChanged 
ItemToolTipChange 
ItemToolTipHasChanged 
ItemFlagsChange 
ItemFlagsHaveChanged 
ItemZValueChange 
ItemZValueHasChanged 
ItemOpacityChange 
ItemOpacityHasChanged 
ItemScenePositionHasChanged 
ItemRotationChange 
ItemRotationHasChanged 
ItemScaleChange 
ItemScaleHasChanged 
ItemTransformOriginPointChange 
ItemTransformOriginPointHasChanged 

Definition at line 74 of file qgraphicsitem.h.

◆ GraphicsItemFlag

This enum describes different flags that you can set on an item to toggle different features in the item's behavior.

All flags are disabled by default.

\value ItemIsMovable The item supports interactive movement using the mouse. By clicking on the item and then dragging, the item will move together with the mouse cursor. If the item has children, all children are also moved. If the item is part of a selection, all selected items are also moved. This feature is provided as a convenience through the base implementation of QGraphicsItem's mouse event handlers.

\value ItemIsSelectable The item supports selection. Enabling this feature will enable setSelected() to toggle selection for the item. It will also let the item be selected automatically as a result of calling QGraphicsScene::setSelectionArea(), by clicking on an item, or by using rubber band selection in QGraphicsView.

\value ItemIsFocusable The item supports keyboard input focus (i.e., it is an input item). Enabling this flag will allow the item to accept focus, which again allows the delivery of key events to QGraphicsItem::keyPressEvent() and QGraphicsItem::keyReleaseEvent().

\value ItemClipsToShape The item clips to its own shape. The item cannot draw or receive mouse, tablet, drag and drop or hover events outside its shape. It is disabled by default. This behavior is enforced by QGraphicsView::drawItems() or QGraphicsScene::drawItems(). This flag was introduced in Qt 4.3.

\value ItemClipsChildrenToShape The item clips the painting of all its descendants to its own shape. Items that are either direct or indirect children of this item cannot draw outside this item's shape. By default, this flag is disabled; children can draw anywhere. This behavior is enforced by QGraphicsView::drawItems() or QGraphicsScene::drawItems(). This flag was introduced in Qt 4.3.

Note
This flag is similar to ItemContainsChildrenInShape but in addition enforces the containment by clipping the children.

\value ItemIgnoresTransformations The item ignores inherited transformations (i.e., its position is still anchored to its parent, but the parent or view rotation, zoom or shear transformations are ignored). This flag is useful for keeping text label items horizontal and unscaled, so they will still be readable if the view is transformed. When set, the item's view geometry and scene geometry will be maintained separately. You must call deviceTransform() to map coordinates and detect collisions in the view. By default, this flag is disabled. This flag was introduced in Qt 4.3.

Note
With this flag set you can still scale the item itself, and that scale transformation will influence the item's children.

\value ItemIgnoresParentOpacity The item ignores its parent's opacity. The item's effective opacity is the same as its own; it does not combine with the parent's opacity. This flags allows your item to keep its absolute opacity even if the parent is semitransparent. This flag was introduced in Qt 4.5.

\value ItemDoesntPropagateOpacityToChildren The item doesn't propagate its opacity to its children. This flag allows you to create a semitransparent item that does not affect the opacity of its children. This flag was introduced in Qt 4.5.

\value ItemStacksBehindParent The item is stacked behind its parent. By default, child items are stacked on top of the parent item. But setting this flag, the child will be stacked behind it. This flag is useful for drop shadow effects and for decoration objects that follow the parent item's geometry without drawing on top of it. This flag was introduced in Qt 4.5.

\value ItemUsesExtendedStyleOption The item makes use of either \l{QStyleOptionGraphicsItem::} {exposedRect} in QStyleOptionGraphicsItem. By default, the \l{QStyleOptionGraphicsItem::} {exposedRect} is initialized to the item's boundingRect(). You can enable this flag for the style options to be set up with more fine-grained values. Use QStyleOptionGraphicsItem::levelOfDetailFromTransform() if you need a higher value. This flag was introduced in Qt 4.6.

\value ItemHasNoContents The item does not paint anything (i.e., calling paint() on the item has no effect). You should set this flag on items that do not need to be painted to ensure that Graphics View avoids unnecessary painting preparations. This flag was introduced in Qt 4.6.

\value ItemSendsGeometryChanges The item enables itemChange() notifications for ItemPositionChange, ItemPositionHasChanged, ItemTransformChange, ItemTransformHasChanged, ItemRotationChange, ItemRotationHasChanged, ItemScaleChange, ItemScaleHasChanged, ItemTransformOriginPointChange, and ItemTransformOriginPointHasChanged. For performance reasons, these notifications are disabled by default. You must enable this flag to receive notifications for position and transform changes. This flag was introduced in Qt 4.6.

\value ItemAcceptsInputMethod The item supports input methods typically used for Asian languages. This flag was introduced in Qt 4.6.

\value ItemNegativeZStacksBehindParent The item automatically stacks behind it's parent if it's z-value is negative. This flag enables setZValue() to toggle ItemStacksBehindParent. This flag was introduced in Qt 4.6.

\value ItemIsPanel The item is a panel. A panel provides activation and contained focus handling. Only one panel can be active at a time (see QGraphicsItem::isActive()). When no panel is active, QGraphicsScene activates all non-panel items. Window items (i.e., QGraphicsItem::isWindow() returns true) are panels. This flag was introduced in Qt 4.6.

\omitvalue ItemIsFocusScope \omit Internal only (for now). \endomit

\value ItemSendsScenePositionChanges The item enables itemChange() notifications for ItemScenePositionHasChanged. For performance reasons, these notifications are disabled by default. You must enable this flag to receive notifications for scene position changes. This flag was introduced in Qt 4.6.

\omitvalue ItemStopsClickFocusPropagation \omit The item stops propagating click focus to items underneath when being clicked on. This flag allows you create a non-focusable item that can be clicked on without changing the focus. \endomit

\omitvalue ItemStopsFocusHandling \omit Same as ItemStopsClickFocusPropagation, but also suppresses focus-out. This flag allows you to completely take over focus handling. This flag was introduced in Qt 4.7. \endomit

\value ItemContainsChildrenInShape This flag indicates that all of the item's direct or indirect children only draw within the item's shape. Unlike ItemClipsChildrenToShape, this restriction is not enforced. Set ItemContainsChildrenInShape when you manually assure that drawing is bound to the item's shape and want to avoid the cost associated with enforcing the clip. Setting this flag enables more efficient drawing and collision detection. The flag is disabled by default.

Note
If both this flag and ItemClipsChildrenToShape are set, the clip will be enforced. This is equivalent to just setting ItemClipsChildrenToShape.

This flag was introduced in Qt 5.4.

Enumerator
ItemIsMovable 
ItemIsSelectable 
ItemIsFocusable 
ItemClipsToShape 
ItemClipsChildrenToShape 
ItemIgnoresTransformations 
ItemIgnoresParentOpacity 
ItemDoesntPropagateOpacityToChildren 
ItemStacksBehindParent 
ItemUsesExtendedStyleOption 
ItemHasNoContents 
ItemSendsGeometryChanges 
ItemAcceptsInputMethod 
ItemNegativeZStacksBehindParent 
ItemIsPanel 
ItemIsFocusScope 
ItemSendsScenePositionChanges 
ItemStopsClickFocusPropagation 
ItemStopsFocusHandling 
ItemContainsChildrenInShape 

Definition at line 49 of file qgraphicsitem.h.

◆ PanelModality

Since
4.6

This enum specifies the behavior of a modal panel. A modal panel is one that blocks input to other panels. Note that items that are children of a modal panel are not blocked.

The values are:

\value NonModal The panel is not modal and does not block input to other panels. This is the default value for panels.

\value PanelModal The panel is modal to a single item hierarchy and blocks input to its parent pane, all grandparent panels, and all siblings of its parent and grandparent panels.

\value SceneModal The window is modal to the entire scene and blocks input to all panels.

See also
QGraphicsItem::setPanelModality(), QGraphicsItem::panelModality(), QGraphicsItem::ItemIsPanel
Enumerator
NonModal 
PanelModal 
SceneModal 

Definition at line 116 of file qgraphicsitem.h.

Constructor & Destructor Documentation

◆ QGraphicsItem() [1/2]

QGraphicsItem::QGraphicsItem ( QGraphicsItem * parent = nullptr)
explicit

Constructs a QGraphicsItem with the given parent item.

It does not modify the parent object returned by QObject::parent().

If parent is \nullptr, you can add the item to a scene by calling QGraphicsScene::addItem(). The item will then become a top-level item.

See also
QGraphicsScene::addItem(), setParentItem()

Definition at line 1503 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::q_ptr, and setParentItem().

+ Here is the call graph for this function:

◆ ~QGraphicsItem()

◆ QGraphicsItem() [2/2]

QGraphicsItem::QGraphicsItem ( QGraphicsItemPrivate & dd,
QGraphicsItem * parent )
protected

Definition at line 1513 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::q_ptr, and setParentItem().

+ Here is the call graph for this function:

Member Function Documentation

◆ acceptDrops()

bool QGraphicsItem::acceptDrops ( ) const

Returns true if this item can accept drag and drop events; otherwise, returns false.

By default, items do not accept drag and drop events; items are transparent to drag and drop.

See also
setAcceptDrops()

Definition at line 3049 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::acceptDrops, and d_ptr.

Referenced by QGraphicsScene::dragMoveEvent().

+ Here is the caller graph for this function:

◆ acceptedMouseButtons()

Qt::MouseButtons QGraphicsItem::acceptedMouseButtons ( ) const

Returns the mouse buttons that this item accepts mouse events for.

By default, all mouse buttons are accepted.

If an item accepts a mouse button, it will become the mouse grabber item when a mouse press event is delivered for that mouse button. However, if the item does not accept the button, QGraphicsScene will forward the mouse events to the first item beneath it that does.

See also
setAcceptedMouseButtons(), mousePressEvent()

Definition at line 3078 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::acceptedMouseButtons, and d_ptr.

Referenced by QQuickDeliveryAgentPrivate::deliverMatchingPointsToItem(), QGraphicsScenePrivate::mousePressEventHandler(), and QQuickDeliveryAgentPrivate::pointerTargets().

+ Here is the caller graph for this function:

◆ acceptHoverEvents()

bool QGraphicsItem::acceptHoverEvents ( ) const
Since
4.4

Returns true if an item accepts hover events (QGraphicsSceneHoverEvent); otherwise, returns false. By default, items do not accept hover events.

See also
setAcceptedMouseButtons()

Definition at line 3117 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::acceptsHover, and d_ptr.

Referenced by QQuickDeliveryAgentPrivate::deliverTouchAsMouse(), and QGraphicsWidget::event().

+ Here is the caller graph for this function:

◆ acceptTouchEvents()

bool QGraphicsItem::acceptTouchEvents ( ) const
Since
4.6

Returns true if an item accepts \l{QTouchEvent}{touch events}; otherwise, returns false. By default, items do not accept touch events.

See also
setAcceptTouchEvents()

Definition at line 3172 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::acceptTouchEvents, and d_ptr.

Referenced by QQuickDeliveryAgentPrivate::deliverMatchingPointsToItem(), QQuickDeliveryAgentPrivate::pointerTargets(), and QGraphicsScenePrivate::sendTouchBeginEvent().

+ Here is the caller graph for this function:

◆ addToIndex()

void QGraphicsItem::addToIndex ( )
protected

Adds this item to the scene's index. Called in conjunction with removeFromIndex() to ensure the index bookkeeping is correct when the item's position, transformation or shape changes.

Definition at line 7412 of file qgraphicsitem.cpp.

References QGraphicsScene::addItem(), QGraphicsItemPrivate::AncestorClipsChildren, QGraphicsItemPrivate::AncestorContainsChildren, QGraphicsItemPrivate::ancestorFlags, d_ptr, and QGraphicsItemPrivate::scene.

+ Here is the call graph for this function:

◆ advance()

void QGraphicsItem::advance ( int phase)
virtual

This virtual function is called twice for all items by the QGraphicsScene::advance() slot.

In the first phase, all items are called with phase == 0, indicating that items on the scene are about to advance, and then all items are called with phase == 1. Reimplement this function to update your item if you need simple scene-controlled animation.

The default implementation does nothing.

This function is intended for animations. An alternative is to multiple-inherit from QObject and QGraphicsItem and use the \l{The Animation Framework}{Animation Framework}.

See also
QGraphicsScene::advance(), QTimeLine

Definition at line 4534 of file qgraphicsitem.cpp.

References Q_UNUSED.

Referenced by QGraphicsScene::advance().

+ Here is the caller graph for this function:

◆ boundingRect()

QRectF QGraphicsItem::boundingRect ( ) const
pure virtual

This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be restricted to inside an item's bounding rect.

QGraphicsView uses this to determine whether the item requires redrawing.

Although the item's shape can be arbitrary, the bounding rect is always rectangular, and it is unaffected by the items' transformation.

If you want to change the item's bounding rectangle, you must first call prepareGeometryChange(). This notifies the scene of the imminent change, so that it can update its item geometry index; otherwise, the scene will be unaware of the item's new geometry, and the results are undefined (typically, rendering artifacts are left within the view).

Reimplement this function to let QGraphicsView determine what parts of the widget, if any, need to be redrawn.

Note: For shapes that paint an outline / stroke, it is important to include half the pen width in the bounding rect. It is not necessary to compensate for antialiasing, though.

Example:

QRectF CircleItem::boundingRect() const
{
qreal penWidth = 1;
return QRectF(-radius - penWidth / 2, -radius - penWidth / 2,
diameter + penWidth, diameter + penWidth);
}
See also
boundingRegion(), shape(), contains(), {The Graphics View Coordinate System}, prepareGeometryChange()

Implemented in QtPrivate::PageItem, SimpleItem, QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPolygonItem, QGraphicsLineItem, QGraphicsPixmapItem, QGraphicsTextItem, QGraphicsSimpleTextItem, QGraphicsItemGroup, QGraphicsWidget, and QGraphicsSvgItem.

Referenced by QGraphicsItemGroup::addToGroup(), adjustedItemBoundingRect(), boundingRegion(), clipPath(), collidesWithPath(), QGraphicsScenePrivate::drawItemHelper(), QGraphicsItemPrivate::effectiveBoundingRect(), QtPrivate::intersect_path(), QtPrivate::intersect_point(), QtPrivate::intersect_rect(), isObscured(), isObscuredBy(), QPrintPreviewWidgetPrivate::layoutPages(), prepareGeometryChange(), QGraphicsScenePrivate::processDirtyItemsRecursive(), qt_graphicsItem_highlightSelected(), sceneBoundingRect(), scroll(), setCursor(), QGraphicsViewPrivate::setUpdateClip(), shape(), QQuickMaterialProgressBarNode::sync(), and QQuickUniversalProgressBarNode::sync().

+ Here is the caller graph for this function:

◆ boundingRegion()

QRegion QGraphicsItem::boundingRegion ( const QTransform & itemToDeviceTransform) const
Since
4.4

Returns the bounding region for this item. The coordinate space of the returned region depends on itemToDeviceTransform. If you pass an identity QTransform as a parameter, this function will return a local coordinate region.

The bounding region describes a coarse outline of the item's visual contents. Although it's expensive to calculate, it's also more precise than boundingRect(), and it can help to avoid unnecessary repainting when an item is updated. This is particularly efficient for thin items (e.g., lines or simple polygons). You can tune the granularity for the bounding region by calling setBoundingRegionGranularity(). The default granularity is 0; in which the item's bounding region is the same as its bounding rect.

itemToDeviceTransform is the transformation from item coordinates to device coordinates. If you want this function to return a QRegion in scene coordinates, you can pass sceneTransform() as an argument.

See also
boundingRegionGranularity()

Definition at line 5157 of file qgraphicsitem.cpp.

References _q_adjustRect(), QPainter::Antialiasing, boundingRect(), boundingRegionGranularity(), deviceRect, QPainter::end(), QImage::Format_ARGB32_Premultiplied, QBitmap::fromImage(), QTransform::fromScale(), QRect::height(), paint, qMax(), rect, QRect::topLeft(), QRect::translated(), and QRect::width().

Referenced by QGraphicsViewPrivate::mapToViewRegion().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ boundingRegionGranularity()

qreal QGraphicsItem::boundingRegionGranularity ( ) const
\since 4.4

Returns the item's bounding region granularity; a value between and
including 0 and 1. The default value is 0 (i.e., the lowest granularity,
where the bounding region corresponds to the item's bounding rectangle).

\omit

NOTE

\endomit

\sa setBoundingRegionGranularity()

Definition at line 5220 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::extra(), QGraphicsItemPrivate::ExtraBoundingRegionGranularity, and QGraphicsItemPrivate::hasBoundingRegionGranularity.

Referenced by boundingRegion(), and QGraphicsScenePrivate::processDirtyItemsRecursive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cacheMode()

QGraphicsItem::CacheMode QGraphicsItem::cacheMode ( ) const
Since
4.4 Returns the cache mode for this item. The default mode is NoCache (i.e., cache is disabled and all painting is immediate).
See also
setCacheMode()

Definition at line 2049 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::cacheMode, and d_ptr.

Referenced by QGraphicsSvgItem::isCachingEnabled().

+ Here is the caller graph for this function:

◆ childItems()

QList< QGraphicsItem * > QGraphicsItem::childItems ( ) const
Since
4.4

Returns a list of this item's children.

The items are sorted by stacking order. This takes into account both the items' insertion order and their Z-values.

See also
setParentItem(), zValue(), {QGraphicsItem::Sorting}{Sorting}

Definition at line 1818 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::children, d_ptr, and QGraphicsItemPrivate::ensureSortedChildren().

Referenced by QQuickSwipeDelegatePrivate::attachedObjectsSetPressed(), debugFocusTree(), QQuickDesignerSupportItems::disableTextCursor(), findAttachedChildren(), firstItemWithDirtyChildrenStacking(), forcePolishHelper(), forceUpdate(), QQuickWindowPrivate::invalidateFontData(), QQuickItemPrivate::nextPrevItemInTabFocusChain(), QQuickItemPrivate::nextTabChildItem(), QQuickItemPrivate::prevTabChildItem(), QQuickControlPrivate::updateFontRecur(), QQuickControlPrivate::updateLocaleRecur(), and updatePixelRatioHelper().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ childrenBoundingRect()

QRectF QGraphicsItem::childrenBoundingRect ( ) const

Returns the bounding rect of this item's descendants (i.e., its children, their children, etc.) in local coordinates.

The rectangle will contain all descendants after they have been mapped to local coordinates. If the item has no children, this function returns an empty QRectF.

This does not include this item's own bounding rect; it only returns its descendants' accumulated bounding rect. If you need to include this item's bounding rect, you can add boundingRect() to childrenBoundingRect() using QRectF::operator|().

This function is linear in complexity; it determines the size of the returned bounding rect by iterating through all descendants.

See also
boundingRect(), sceneBoundingRect()

Definition at line 4714 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::childrenBoundingRect, QGraphicsItemPrivate::childrenBoundingRectHelper(), d_ptr, and QGraphicsItemPrivate::dirtyChildrenBoundingRect.

Referenced by QGraphicsItemGroup::addToGroup(), and QGraphicsItemGroup::removeFromGroup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearFocus()

void QGraphicsItem::clearFocus ( )

Takes keyboard input focus from the item.

If it has focus, a \l{focusOutEvent()}{focus out event} is sent to this item to tell it that it is about to lose the focus.

Only items that set the ItemIsFocusable flag, or widgets that set an appropriate focus policy, can accept keyboard focus.

See also
setFocus(), hasFocus(), QGraphicsWidget::focusPolicy

Definition at line 3463 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::clearFocusHelper(), and d_ptr.

Referenced by ~QGraphicsItem(), QGraphicsScenePrivate::removeItemHelper(), QGraphicsItemPrivate::setEnabledHelper(), setFlags(), and QGraphicsWidget::setFocusPolicy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clipPath()

QPainterPath QGraphicsItem::clipPath ( ) const
Since
4.5

Returns this item's clip path, or an empty QPainterPath if this item is not clipped. The clip path constrains the item's appearance and interaction (i.e., restricts the area the item can draw within and receive events for).

You can enable clipping by setting the ItemClipsToShape or ItemClipsChildrenToShape flags. The item's clip path is calculated by intersecting all clipping ancestors' shapes. If the item sets ItemClipsToShape, the final clip is intersected with the item's own shape.

Note
Clipping introduces a performance penalty for all items involved; you should generally avoid using clipping if you can (e.g., if your items always draw inside boundingRect() or shape() boundaries, clipping is not necessary).
See also
isClipped(), shape(), setFlags()

Definition at line 4855 of file qgraphicsitem.cpp.

References QPainterPath::addRect(), QGraphicsItemPrivate::AncestorClipsChildren, QGraphicsItemPrivate::ancestorFlags, boundingRect(), d, d_ptr, QGraphicsItemPrivate::flags, QPainterPath::intersected(), isClipped(), QPainterPath::isEmpty(), ItemClipsChildrenToShape, ItemClipsToShape, QGraphicsItemPrivate::parent, and shape().

Referenced by collidesWithPath(), contains(), QGraphicsView::fitInView(), and QAbstractGraphicsShapeItem::opaqueArea().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ collidesWithItem()

bool QGraphicsItem::collidesWithItem ( const QGraphicsItem * other,
Qt::ItemSelectionMode mode = Qt::IntersectsItemShape ) const
virtual

Returns true if this item collides with other; otherwise returns false.

The mode is applied to other, and the resulting shape or bounding rectangle is then compared to this item's shape. The default value for mode is Qt::IntersectsItemShape; other collides with this item if it either intersects, contains, or is contained by this item's shape (see Qt::ItemSelectionMode for details).

The default implementation is based on shape intersection, and it calls shape() on both items. Because the complexity of arbitrary shape-shape intersection grows with an order of magnitude when the shapes are complex, this operation can be noticeably time-consuming. You have the option of reimplementing this function in a subclass of QGraphicsItem to provide a custom algorithm. This allows you to make use of natural constraints in the shapes of your own items, in order to improve the performance of the collision detection. For instance, two untransformed perfectly circular items' collision can be determined very efficiently by comparing their positions and radii.

Keep in mind that when reimplementing this function and calling shape() or boundingRect() on other, the returned coordinates must be mapped to this item's coordinate system before any intersection can take place.

See also
contains(), shape()

Definition at line 4947 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::AncestorClipsChildren, QGraphicsItemPrivate::ancestorFlags, collidesWithPath(), d_ptr, isAncestorOf(), ItemClipsChildrenToShape, QGraphicsItemPrivate::localCollisionHack, mapFromItem(), other(), parentItem(), and this.

Referenced by QGraphicsScene::collidingItems().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ collidesWithPath()

bool QGraphicsItem::collidesWithPath ( const QPainterPath & path,
Qt::ItemSelectionMode mode = Qt::IntersectsItemShape ) const
virtual

Returns true if this item collides with path.

The collision is determined by mode. The default value for mode is Qt::IntersectsItemShape; path collides with this item if it either intersects, contains, or is contained by this item's shape.

Note that this function checks whether the item's shape or bounding rectangle (depending on mode) is contained within path, and not whether path is contained within the items shape or bounding rectangle.

See also
collidesWithItem(), contains(), shape()

Definition at line 4990 of file qgraphicsitem.cpp.

References _q_adjustRect(), boundingRect(), clipPath(), Qt::ContainsItemShape, d_ptr, Qt::IntersectsItemBoundingRect, Qt::IntersectsItemShape, isClipped(), QGraphicsItemPrivate::localCollisionHack, and shape().

Referenced by collidesWithItem(), and QGraphicsSceneIndexPrivate::itemCollidesWithPath().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ collidingItems()

QList< QGraphicsItem * > QGraphicsItem::collidingItems ( Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const

Returns a list of all items that collide with this item.

The way collisions are detected is determined by applying mode to items that are compared to this item, i.e., each item's shape or bounding rectangle is checked against this item's shape. The default value for mode is Qt::IntersectsItemShape.

See also
collidesWithItem()

Definition at line 5035 of file qgraphicsitem.cpp.

References QGraphicsScene::collidingItems(), d_ptr, and QGraphicsItemPrivate::scene.

+ Here is the call graph for this function:

◆ commonAncestorItem()

QGraphicsItem * QGraphicsItem::commonAncestorItem ( const QGraphicsItem * other) const
Since
4.4

Returns the closest common ancestor item of this item and other, or \nullptr if either other is \nullptr, or there is no common ancestor.

See also
isAncestorOf()

Definition at line 6421 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::depth(), and other().

Referenced by QGraphicsScenePrivate::dispatchHoverEvent(), isBlockedByModalPanel(), itemTransform(), and QGraphicsItemPrivate::setFocusHelper().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ contains()

bool QGraphicsItem::contains ( const QPointF & point) const
virtual

Returns true if this item contains point, which is in local coordinates; otherwise, false is returned.

It is most often called from QGraphicsView to determine what item is under the cursor, and for that reason, the implementation of this function should be as light-weight as possible.

By default, this function calls shape(), but you can reimplement it in a subclass to provide a (perhaps more efficient) implementation.

See also
shape(), boundingRect(), collidesWithPath()

Reimplemented in QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPolygonItem, QGraphicsLineItem, QGraphicsPixmapItem, QGraphicsTextItem, and QGraphicsSimpleTextItem.

Definition at line 4913 of file qgraphicsitem.cpp.

References clipPath(), QPainterPath::contains(), isClipped(), and shape().

Referenced by QGeoMap::addMapItem(), QQuickSwipeDelegatePrivate::attachedObjectsSetPressed(), QGraphicsPathItem::contains(), QGraphicsRectItem::contains(), QGraphicsEllipseItem::contains(), QGraphicsPolygonItem::contains(), QGraphicsLineItem::contains(), QGraphicsPixmapItem::contains(), QQuickDeliveryAgentPrivate::deliverHoverEventToItem(), QQuickDeliveryAgentPrivate::deliverTouchAsMouse(), QPageRanges::fromString(), fxViewItemAtPosition(), QGraphicsScenePrivate::gestureEventHandler(), QQuickPathViewPrivate::handleMousePressEvent(), QGraphicsProxyWidget::hoverMoveEvent(), QtPrivate::intersect_point(), isUnderMouse(), QQuickPathView::itemAt(), QGraphicsWidget::paintWindowFrame(), QQuickDeliveryAgentPrivate::pointerTargets(), QQuickMouseAreaPrivate::propagateHelper(), QGeoMap::removeMapItem(), and setCursor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ contextMenuEvent()

void QGraphicsItem::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event)
protectedvirtual

This event handler can be reimplemented in a subclass to process context menu events.

The event parameter contains details about the event to be handled.

If you ignore the event (i.e., by calling QEvent::ignore()), event will propagate to any item beneath this item. If no items accept the event, it will be ignored by the scene and propagate to the view.

It's common to open a QMenu in response to receiving a context menu event. Example:

{
QAction *removeAction = menu.addAction("Remove");
QAction *markAction = menu.addAction("Mark");
QAction *selectedAction = menu.exec(event->screenPos());
// ...
}

The default implementation ignores the event.

See also
sceneEvent()

Reimplemented in QGraphicsTextItem, and QGraphicsProxyWidget.

Definition at line 6770 of file qgraphicsitem.cpp.

Referenced by sceneEvent().

+ Here is the caller graph for this function:

◆ cursor()

QCursor QGraphicsItem::cursor ( ) const

Returns the current cursor shape for the item.

The mouse cursor will assume this shape when it's over this item. See the \l{Qt::CursorShape}{list of predefined cursor objects} for a range of useful shapes.

An editor item might want to use an I-beam cursor:

If no cursor has been set, the cursor of the item beneath is used.

See also
setCursor(), hasCursor(), unsetCursor(), QWidget::cursor, QGuiApplication::overrideCursor()

Definition at line 2240 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::extra(), and QGraphicsItemPrivate::ExtraCursor.

Referenced by QGraphicsViewPrivate::_q_unsetViewportCursor(), QGraphicsViewPrivate::mouseMoveEventHandler(), setCursor(), and QGraphicsTextItem::setTextCursor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ data()

QVariant QGraphicsItem::data ( int key) const

Returns this item's custom data for the key key as a QVariant.

Custom item data is useful for storing arbitrary properties in any item. Example:

static const int ObjectName = 0;
if (qgraphicsitem_cast<ButtonItem *>(item))
item->setData(ObjectName, "Button");
}

Qt does not use this feature for storing data; it is provided solely for the convenience of the user.

See also
setData()

Definition at line 6481 of file qgraphicsitem.cpp.

References QHash< Key, T >::contains(), QGraphicsItemCustomDataStore::data, and QHash< Key, T >::value().

Referenced by QStandardItemModel::data(), QLocaleData::doubleToString(), dtoString(), QGraphicsScenePrivate::gestureEventHandler(), and QStandardItemModel::itemData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deviceTransform()

QTransform QGraphicsItem::deviceTransform ( const QTransform & viewportTransform) const
Since
4.3

Returns this item's device transformation matrix, using viewportTransform to map from scene to device coordinates. This matrix can be used to map coordinates and geometrical shapes from this item's local coordinate system to the viewport's (or any device's) coordinate system. To map coordinates from the viewport, you must first invert the returned matrix.

Example:

rect.setPos(100, 100);
rect.deviceTransform(view->viewportTransform()).map(QPointF(0, 0));
// returns the item's (0, 0) point in view's viewport coordinates
rect.deviceTransform(view->viewportTransform()).inverted().map(QPointF(100, 100));
// returns view's viewport's (100, 100) coordinate in item coordinates

This function is the same as combining this item's scene transform with the view's viewport transform, but it also understands the ItemIgnoresTransformations flag. The device transform can be used to do accurate coordinate mapping (and collision detection) for untransformable items.

See also
transform(), setTransform(), scenePos(), {The Graphics View Coordinate System}, itemTransform()

Definition at line 4287 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::AncestorIgnoresTransformations, QGraphicsItemPrivate::combineTransformFromParent(), d_ptr, QGraphicsItemPrivate::ensureSceneTransform(), QTransform::fromTranslate(), i, QGraphicsItemPrivate::itemIsUntransformable(), map, parentItem(), Q_ASSERT_X, and QGraphicsItemPrivate::sceneTransform.

Referenced by QGraphicsItemPrivate::combineTransformFromParent(), QGraphicsItemPrivate::combineTransformToParent(), QGraphicsScenePrivate::drawSubtreeRecursive(), QtPrivate::intersect_path(), QtPrivate::intersect_point(), QtPrivate::intersect_rect(), QGraphicsViewPrivate::mapToViewRect(), QGraphicsViewPrivate::mapToViewRegion(), mouseMoveEvent(), QGraphicsView::paintEvent(), and QGraphicsViewPrivate::setUpdateClip().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dragEnterEvent()

void QGraphicsItem::dragEnterEvent ( QGraphicsSceneDragDropEvent * event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive drag enter events for this item.

Drag enter events are generated as the cursor enters the item's area.

By accepting the event (i.e., by calling QEvent::accept()), the item will accept drop events, in addition to receiving drag move and drag leave. Otherwise, the event will be ignored and propagate to the item beneath. If the event is accepted, the item will receive a drag move event before control goes back to the event loop.

A common implementation of dragEnterEvent accepts or ignores event depending on the associated mime data in event. Example:

CustomItem::CustomItem()
{
setAcceptDrops(true);
...
}
{
event->setAccepted(event->mimeData()->hasFormat("text/plain"));
}

Items do not receive drag and drop events by default; to enable this feature, call setAcceptDrops(true).

The default implementation does nothing.

See also
dropEvent(), dragMoveEvent(), dragLeaveEvent()

Reimplemented in QGraphicsTextItem.

Definition at line 6798 of file qgraphicsitem.cpp.

References d, and dragEnterEvent().

Referenced by dragEnterEvent(), and sceneEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dragLeaveEvent()

void QGraphicsItem::dragLeaveEvent ( QGraphicsSceneDragDropEvent * event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive drag leave events for this item.

Drag leave events are generated as the cursor leaves the item's area. Most often you will not need to reimplement this function, but it can be useful for resetting state in your item (e.g., highlighting).

Calling QEvent::ignore() or QEvent::accept() on event has no effect.

Items do not receive drag and drop events by default; to enable this feature, call setAcceptDrops(true).

The default implementation does nothing.

See also
dragEnterEvent(), dropEvent(), dragMoveEvent()

Reimplemented in QGraphicsTextItem.

Definition at line 6822 of file qgraphicsitem.cpp.

References d, and dragLeaveEvent().

Referenced by dragLeaveEvent(), and sceneEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dragMoveEvent()

void QGraphicsItem::dragMoveEvent ( QGraphicsSceneDragDropEvent * event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive drag move events for this item.

Drag move events are generated as the cursor moves around inside the item's area. Most often you will not need to reimplement this function; it is used to indicate that only parts of the item can accept drops.

Calling QEvent::ignore() or QEvent::accept() on event toggles whether or not the item will accept drops at the position from the event. By default, event is accepted, indicating that the item allows drops at the specified position.

Items do not receive drag and drop events by default; to enable this feature, call setAcceptDrops(true).

The default implementation does nothing.

See also
dropEvent(), dragEnterEvent(), dragLeaveEvent()

Reimplemented in QGraphicsTextItem.

Definition at line 6849 of file qgraphicsitem.cpp.

References d, and dragMoveEvent().

Referenced by dragMoveEvent(), and sceneEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dropEvent()

void QGraphicsItem::dropEvent ( QGraphicsSceneDragDropEvent * event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive drop events for this item.

Items can only receive drop events if the last drag move event was accepted.

Calling QEvent::ignore() or QEvent::accept() on event has no effect.

Items do not receive drag and drop events by default; to enable this feature, call setAcceptDrops(true).

The default implementation does nothing.

See also
dragEnterEvent(), dragMoveEvent(), dragLeaveEvent()

Reimplemented in QGraphicsTextItem.

Definition at line 6871 of file qgraphicsitem.cpp.

References d, and dropEvent().

Referenced by dropEvent(), and sceneEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ effectiveOpacity()

qreal QGraphicsItem::effectiveOpacity ( ) const
Since
4.5

Returns this item's effective opacity, which is between 0.0 (transparent) and 1.0 (opaque). This value is a combination of this item's local opacity, and its parent and ancestors' opacities. The effective opacity decides how the item is rendered.

See also
opacity(), setOpacity(), paint(), ItemIgnoresParentOpacity, ItemDoesntPropagateOpacityToChildren

Definition at line 2806 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::effectiveOpacity().

+ Here is the call graph for this function:

◆ ensureVisible() [1/2]

void QGraphicsItem::ensureVisible ( const QRectF & rect = QRectF(),
int xmargin = 50,
int ymargin = 50 )

If this item is part of a scene that is viewed by a QGraphicsView, this convenience function will attempt to scroll the view to ensure that rect is visible inside the view's viewport.

If rect is a null rect (the default), QGraphicsItem will default to the item's bounding rect. xmargin and ymargin are the number of pixels the view should use for margins.

If the specified rect cannot be reached, the contents are scrolled to the nearest valid position.

If this item is not viewed by a QGraphicsView, this function does nothing.

See also
QGraphicsView::ensureVisible()

Definition at line 3911 of file qgraphicsitem.cpp.

References d_ptr, rect, QGraphicsItemPrivate::scene, sceneBoundingRect(), sceneTransform(), view, and QGraphicsScene::views().

Referenced by QGraphicsTextItemPrivate::_q_ensureVisible(), and ensureVisible().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ensureVisible() [2/2]

void QGraphicsItem::ensureVisible ( qreal x,
qreal y,
qreal w,
qreal h,
int xmargin = 50,
int ymargin = 50 )
inline

This convenience function is equivalent to calling ensureVisible(QRectF(x, y, w, h), xmargin, ymargin).

Definition at line 441 of file qgraphicsitem.h.

References ensureVisible().

+ Here is the call graph for this function:

◆ extension()

QVariant QGraphicsItem::extension ( const QVariant & variant) const
protectedvirtual

Note: This is provided as a hook to avoid future problems related to adding virtual functions.

Reimplemented in QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPolygonItem, QGraphicsLineItem, QGraphicsPixmapItem, QGraphicsTextItem, and QGraphicsSimpleTextItem.

Definition at line 7399 of file qgraphicsitem.cpp.

References Q_UNUSED, and variant.

◆ filtersChildEvents()

bool QGraphicsItem::filtersChildEvents ( ) const
Since
4.6

Returns true if this item filters child events (i.e., all events intended for any of its children are instead sent to this item); otherwise, false is returned.

The default value is false; child events are not filtered.

See also
setFiltersChildEvents()

Definition at line 3206 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::filtersDescendantEvents.

◆ flags()

QGraphicsItem::GraphicsItemFlags QGraphicsItem::flags ( ) const

Returns this item's flags.

The flags describe what configurable features of the item are enabled and not. For example, if the flags include ItemIsFocusable, the item can accept input focus.

By default, no flags are enabled.

See also
setFlags(), setFlag()

Definition at line 1866 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::flags.

Referenced by _qt_movableAncestorIsSelected(), QDockAreaLayoutInfo::apply(), QTextEngine::calculateTabWidth(), QGraphicsSceneBspTreeIndexPrivate::climbTree(), QQmlTreeModelToTableModel::collapseRow(), QmlJSDebugger::collectItemsAt(), QQmlTreeModelToTableModel::expandRow(), QDockAreaLayoutInfo::findSeparator(), QDockAreaLayoutInfo::fitItems(), QStandardItemModel::flags(), forcePolishHelper(), forceUpdate(), formatGraphicsItemHelper(), QDockAreaLayoutInfo::indexOf(), QDockAreaLayoutInfo::insertGap(), QmlJSDebugger::itemAt(), QDockAreaLayoutInfo::itemRect(), QDockAreaLayout::keepSize(), mouseMoveEvent(), mousePressEvent(), QGraphicsScenePrivate::mousePressEventHandler(), QGraphicsItemPrivate::movableAncestorIsSelected(), operator<<(), QGraphicsProxyWidget::paint(), QDockAreaLayoutInfo::plug(), realMaxSize(), realMinSize(), QGraphicsScenePrivate::removeItemHelper(), QDockAreaLayoutInfo::restoreState(), QGraphicsScenePrivate::sendTouchBeginEvent(), QDockAreaLayoutInfo::separatorMove(), setFlags(), QGraphicsScenePrivate::setFocusItemHelper(), QGraphicsScene::setSelectionArea(), QComboBoxDelegate::setSeparator(), QGraphicsTextItem::setTextInteractionFlags(), QDockAreaLayoutInfo::sizeHint(), QDockAreaLayoutInfo::takeAt(), QDockAreaLayoutInfo::unplug(), updatePixelRatioHelper(), and QGraphicsScene::wheelEvent().

+ Here is the caller graph for this function:

◆ focusInEvent()

void QGraphicsItem::focusInEvent ( QFocusEvent * event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive focus in events for this item.

The default implementation calls ensureVisible().

See also
focusOutEvent(), sceneEvent(), setFocus()

Reimplemented in QGraphicsTextItem, QGraphicsProxyWidget, and QGraphicsWidget.

Definition at line 6886 of file qgraphicsitem.cpp.

References Q_UNUSED, and update().

Referenced by sceneEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ focusItem()

QGraphicsItem * QGraphicsItem::focusItem ( ) const
Since
4.6

If this item, a child or descendant of this item currently has input focus, this function will return a pointer to that item. If no descendant has input focus, \nullptr is returned.

See also
hasFocus(), setFocus(), QWidget::focusWidget()

Definition at line 3581 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::subFocusItem.

Referenced by QGraphicsScene::addItem(), QGraphicsScenePrivate::mousePressEventHandler(), QGraphicsScenePrivate::sendTouchBeginEvent(), QGraphicsScenePrivate::setActivePanelHelper(), and QGraphicsItemPrivate::setParentItemHelper().

+ Here is the caller graph for this function:

◆ focusOutEvent()

void QGraphicsItem::focusOutEvent ( QFocusEvent * event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive focus out events for this item.

The default implementation does nothing.

See also
focusInEvent(), sceneEvent(), setFocus()

Reimplemented in QGraphicsTextItem, QGraphicsProxyWidget, and QGraphicsWidget.

Definition at line 6898 of file qgraphicsitem.cpp.

References Q_UNUSED, and update().

Referenced by sceneEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ focusProxy()

QGraphicsItem * QGraphicsItem::focusProxy ( ) const
Since
4.6

Returns this item's focus proxy, or \nullptr if this item has no focus proxy.

See also
setFocusProxy(), setFocus(), hasFocus()

Definition at line 3519 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::focusProxy.

Referenced by setFocusProxy().

+ Here is the caller graph for this function:

◆ focusScopeItem()

QGraphicsItem * QGraphicsItem::focusScopeItem ( ) const

Returns this item's focus scope item.

Definition at line 3591 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::focusScopeItem.

◆ grabKeyboard()

void QGraphicsItem::grabKeyboard ( )
Since
4.4 Grabs the keyboard input.

The item will receive all keyboard input to the scene until one of the following events occur:

\list

  • The item becomes invisible
  • The item is removed from the scene
  • The item is deleted
  • The item calls ungrabKeyboard()
  • Another item calls grabKeyboard(); the item will regain the keyboard grab when the other item calls ungrabKeyboard(). \endlist

When an item gains the keyboard grab, it receives a QEvent::GrabKeyboard event. When it loses the keyboard grab, it receives a QEvent::UngrabKeyboard event. These events can be used to detect when your item gains or loses the keyboard grab through other means than gaining input focus.

It is almost never necessary to explicitly grab the keyboard in Qt, as Qt grabs and releases it sensibly. In particular, Qt grabs the keyboard when your item gains input focus, and releases it when your item loses input focus, or when the item is hidden.

Note that only visible items can grab keyboard input. Calling grabKeyboard() on an invisible item has no effect.

Keyboard events are not affected.

See also
ungrabKeyboard(), grabMouse(), setFocus()

Definition at line 3692 of file qgraphicsitem.cpp.

References d_ptr, qWarning, QGraphicsItemPrivate::scene, and QGraphicsItemPrivate::visible.

◆ grabMouse()

void QGraphicsItem::grabMouse ( )
Since
4.4 Grabs the mouse input.

This item will receive all mouse events for the scene until any of the following events occurs:

\list

  • The item becomes invisible
  • The item is removed from the scene
  • The item is deleted
  • The item call ungrabMouse()
  • Another item calls grabMouse(); the item will regain the mouse grab when the other item calls ungrabMouse(). \endlist

When an item gains the mouse grab, it receives a QEvent::GrabMouse event. When it loses the mouse grab, it receives a QEvent::UngrabMouse event. These events can be used to detect when your item gains or loses the mouse grab through other means than receiving mouse button events.

It is almost never necessary to explicitly grab the mouse in Qt, as Qt grabs and releases it sensibly. In particular, Qt grabs the mouse when you press a mouse button, and keeps the mouse grabbed until you release the last mouse button. Also, Qt::Popup widgets implicitly call grabMouse() when shown, and ungrabMouse() when hidden.

Note that only visible items can grab mouse input. Calling grabMouse() on an invisible item has no effect.

Keyboard events are not affected.

See also
QGraphicsScene::mouseGrabberItem(), ungrabMouse(), grabKeyboard()

Definition at line 3630 of file qgraphicsitem.cpp.

References d_ptr, qWarning, QGraphicsItemPrivate::scene, and QGraphicsItemPrivate::visible.

◆ group()

QGraphicsItemGroup * QGraphicsItem::group ( ) const

Returns a pointer to this item's item group, or \nullptr if this item is not member of a group.

See also
QGraphicsItemGroup, QGraphicsScene::createItemGroup()

Definition at line 1616 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::isMemberOfGroup, and QGraphicsItemPrivate::parent.

Referenced by isSelected(), QGraphicsItemGroup::removeFromGroup(), setGroup(), and setSelected().

+ Here is the caller graph for this function:

◆ handlesChildEvents()

bool QGraphicsItem::handlesChildEvents ( ) const
Deprecated

Returns true if this item handles child events (i.e., all events intended for any of its children are instead sent to this item); otherwise, false is returned.

This property is useful for item groups; it allows one item to handle events on behalf of its children, as opposed to its children handling their events individually.

The default is to return false; children handle their own events. The exception for this is if the item is a QGraphicsItemGroup, then it defaults to return true.

See also
setHandlesChildEvents()

Definition at line 3248 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::handlesChildEvents.

◆ hasCursor()

bool QGraphicsItem::hasCursor ( ) const

Returns true if this item has a cursor set; otherwise, false is returned.

By default, items don't have any cursor set. cursor() will return a standard pointing arrow cursor.

See also
unsetCursor()

Definition at line 2300 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::hasCursor.

Referenced by QGraphicsViewPrivate::_q_unsetViewportCursor(), and QGraphicsViewPrivate::mouseMoveEventHandler().

+ Here is the caller graph for this function:

◆ hasFocus()

bool QGraphicsItem::hasFocus ( ) const

Returns true if this item is active, and it or its \l{focusProxy()}{focus proxy} has keyboard input focus; otherwise, returns false.

See also
focusItem(), setFocus(), QGraphicsScene::setFocusItem(), isActive()

Definition at line 3350 of file qgraphicsitem.cpp.

References QGraphicsScene::activePanel(), d_ptr, QGraphicsScene::focusItem(), QGraphicsItemPrivate::focusProxy, hasFocus(), QGraphicsScene::isActive(), panel(), and QGraphicsItemPrivate::scene.

Referenced by QGraphicsTextItemPrivate::_q_ensureVisible(), QGraphicsItemPrivate::clearFocusHelper(), QGraphicsProxyWidget::contextMenuEvent(), debugFocusTree(), QGraphicsWidget::focusNextPrevChild(), hasFocus(), QGraphicsWidget::initStyleOption(), QGraphicsProxyWidget::inputMethodQuery(), QGraphicsTextItem::mouseDoubleClickEvent(), QGraphicsWidget::paintWindowFrame(), QGraphicsItemPrivate::setEnabledHelper(), setFlags(), QGraphicsWidget::setFocusPolicy(), setInputMethodHints(), and QGraphicsItemPrivate::setVisibleHelper().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hide()

void QGraphicsItem::hide ( )
inline

Hides the item (items are visible by default).

This convenience function is equivalent to calling setVisible(false).

See also
show(), setVisible()

Definition at line 173 of file qgraphicsitem.h.

Referenced by QGraphicsWidget::close(), QStatusBar::hideOrShow(), QToolBarLayout::takeAt(), and QStackedLayout::takeAt().

+ Here is the caller graph for this function:

◆ hoverEnterEvent()

void QGraphicsItem::hoverEnterEvent ( QGraphicsSceneHoverEvent * event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive hover enter events for this item.

The default implementation calls update(); otherwise it does nothing.

Calling QEvent::ignore() or QEvent::accept() on event has no effect.

See also
hoverMoveEvent(), hoverLeaveEvent(), sceneEvent(), setAcceptHoverEvents()

Reimplemented in QGraphicsTextItem, and QGraphicsProxyWidget.

Definition at line 6913 of file qgraphicsitem.cpp.

References Q_UNUSED, and update().

Referenced by sceneEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hoverLeaveEvent()

void QGraphicsItem::hoverLeaveEvent ( QGraphicsSceneHoverEvent * event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive hover leave events for this item.

The default implementation calls update(); otherwise it does nothing.

Calling QEvent::ignore() or QEvent::accept() on event has no effect.

See also
hoverEnterEvent(), hoverMoveEvent(), sceneEvent(), setAcceptHoverEvents()

Reimplemented in QGraphicsTextItem, QGraphicsProxyWidget, and QGraphicsWidget.

Definition at line 6941 of file qgraphicsitem.cpp.

References Q_UNUSED, and update().

Referenced by QGraphicsWidget::hoverLeaveEvent(), and sceneEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hoverMoveEvent()

void QGraphicsItem::hoverMoveEvent ( QGraphicsSceneHoverEvent * event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive hover move events for this item.

The default implementation does nothing.

Calling QEvent::ignore() or QEvent::accept() on event has no effect.

See also
hoverEnterEvent(), hoverLeaveEvent(), sceneEvent(), setAcceptHoverEvents()

Reimplemented in QGraphicsTextItem, QGraphicsProxyWidget, and QGraphicsWidget.

Definition at line 6927 of file qgraphicsitem.cpp.

References Q_UNUSED.

Referenced by sceneEvent().

+ Here is the caller graph for this function:

◆ inputMethodEvent()

void QGraphicsItem::inputMethodEvent ( QInputMethodEvent * event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive input method events for this item.

The default implementation ignores the event.

See also
inputMethodQuery(), sceneEvent()

Reimplemented in QGraphicsTextItem, and QGraphicsProxyWidget.

Definition at line 7271 of file qgraphicsitem.cpp.

Referenced by sceneEvent().

+ Here is the caller graph for this function:

◆ inputMethodHints()

Qt::InputMethodHints QGraphicsItem::inputMethodHints ( ) const

Returns the current input method hints of this item.

Input method hints are only relevant for input items. The hints are used by the input method to indicate how it should operate. For example, if the Qt::ImhNumbersOnly flag is set, the input method may change its visual components to reflect that only numbers can be entered.

The effect may vary between input method implementations.

Since
4.6
See also
setInputMethodHints(), inputMethodQuery()

Definition at line 7305 of file qgraphicsitem.cpp.

References d.

Referenced by QGraphicsTextItem::inputMethodQuery(), and QGraphicsViewPrivate::updateInputMethodSensitivity().

+ Here is the caller graph for this function:

◆ inputMethodQuery()

QVariant QGraphicsItem::inputMethodQuery ( Qt::InputMethodQuery query) const
protectedvirtual

This method is only relevant for input items.

It is used by the input method to query a set of properties of the item to be able to support complex input method operations, such as support for surrounding text and reconversions. query specifies which property is queried.

See also
inputMethodEvent(), QInputMethodEvent

Reimplemented in QGraphicsTextItem, and QGraphicsProxyWidget.

Definition at line 7285 of file qgraphicsitem.cpp.

References Q_UNUSED.

Referenced by QGraphicsProxyWidget::inputMethodQuery(), and QQuickWindowPrivate::polishItems().

+ Here is the caller graph for this function:

◆ installSceneEventFilter()

void QGraphicsItem::installSceneEventFilter ( QGraphicsItem * filterItem)

Installs an event filter for this item on filterItem, causing all events for this item to first pass through filterItem's sceneEventFilter() function.

To filter another item's events, install this item as an event filter for the other item. Example:

QGraphicsLineItem *line = scene.addLine(QLineF(-10, -10, 20, 20));
line->installSceneEventFilter(ellipse);
// line's events are filtered by ellipse's sceneEventFilter() function.
// ellipse's events are filtered by line's sceneEventFilter() function.

An item can only filter events for other items in the same scene. Also, an item cannot filter its own events; instead, you can reimplement sceneEvent() directly.

Items must belong to a scene for scene event filters to be installed and used.

See also
removeSceneEventFilter(), sceneEventFilter(), sceneEvent()

Definition at line 6559 of file qgraphicsitem.cpp.

References d_ptr, qWarning, and QGraphicsItemPrivate::scene.

◆ isActive()

bool QGraphicsItem::isActive ( ) const
Since
4.6 Returns true if this item is active; otherwise returns false.

An item can only be active if the scene is active. An item is active if it is, or is a descendent of, an active panel. Items in non-active panels are not active.

Items that are not part of a panel follow scene activation when the scene has no active panel.

Only active items can gain input focus.

See also
QGraphicsScene::isActive(), QGraphicsScene::activePanel(), panel(), isPanel()

Definition at line 3296 of file qgraphicsitem.cpp.

References QGraphicsScene::activePanel(), d_ptr, QGraphicsScene::isActive(), panel(), and QGraphicsItemPrivate::scene.

Referenced by QGraphicsWidget::isActiveWindow(), QGraphicsWidget::paintWindowFrame(), QGraphicsItemPrivate::setParentItemHelper(), and QGraphicsItemPrivate::setVisibleHelper().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isAncestorOf()

bool QGraphicsItem::isAncestorOf ( const QGraphicsItem * child) const

Returns true if this item is an ancestor of child (i.e., if this item is child's parent, or one of child's parent's ancestors).

See also
parentItem()

Definition at line 6399 of file qgraphicsitem.cpp.

References child, d_ptr, and QGraphicsItemPrivate::depth().

Referenced by QGraphicsScenePrivate::cancelGesturesForChildren(), QQuickOverlay::childMouseEventFilter(), QGraphicsItemPrivate::clearSubFocus(), collidesWithItem(), QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(), QGraphicsScene::focusNextPrevChild(), isBlockedByPopup(), isChildOrGrandchildOf(), itemTransform(), QQuickTableViewPrivate::releaseItem(), setActive(), QGraphicsItemPrivate::setEnabledHelper(), setFlags(), QGraphicsItemPrivate::setParentItemHelper(), and QGraphicsItemPrivate::setVisibleHelper().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isBlockedByModalPanel()

bool QGraphicsItem::isBlockedByModalPanel ( QGraphicsItem ** blockingPanel = nullptr) const
Since
4.6

Returns true if this item is blocked by a modal panel, false otherwise. If blockingPanel is non-zero, blockingPanel will be set to the modal panel that is blocking this item. If this item is not blocked, blockingPanel will not be set by this function.

This function always returns false for items not in a scene.

See also
panelModality(), setPanelModality(), PanelModality

Definition at line 2159 of file qgraphicsitem.cpp.

References commonAncestorItem(), d_ptr, i, QGraphicsItemPrivate::scene, and SceneModal.

Referenced by QGraphicsScenePrivate::enterModal(), QGraphicsScenePrivate::gestureTargetsAtHotSpots(), QGraphicsScenePrivate::itemAcceptsHoverEvents_helper(), QGraphicsScenePrivate::leaveModal(), QGraphicsScenePrivate::mousePressEventHandler(), QGraphicsScenePrivate::sendMouseEvent(), and QGraphicsScenePrivate::touchEventHandler().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isClipped()

bool QGraphicsItem::isClipped ( ) const

Returns true if this item is clipped.

An item is clipped if it has either set the \l ItemClipsToShape flag, or if it or any of its ancestors has set the \l ItemClipsChildrenToShape flag.

Clipping affects the item's appearance (i.e., painting), as well as mouse and hover event delivery.

See also
clipPath(), shape(), setFlags()

Definition at line 4828 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::AncestorClipsChildren, d, and ItemClipsToShape.

Referenced by clipPath(), collidesWithPath(), contains(), QGraphicsView::fitInView(), and QAbstractGraphicsShapeItem::opaqueArea().

+ Here is the caller graph for this function:

◆ isEnabled()

◆ isObscured() [1/2]

bool QGraphicsItem::isObscured ( const QRectF & rect = QRectF()) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.3

Returns true if rect is completely obscured by the opaque shape of any of colliding items above it (i.e., with a higher Z value than this item).

See also
opaqueArea()

Definition at line 5068 of file qgraphicsitem.cpp.

References boundingRect(), d, Qt::IntersectsItemBoundingRect, QRectF::isNull(), item, items, mapToScene(), qt_QGraphicsItem_isObscured(), and rect.

Referenced by isObscured().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isObscured() [2/2]

bool QGraphicsItem::isObscured ( qreal x,
qreal y,
qreal w,
qreal h ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.3

This convenience function is equivalent to calling isObscured(QRectF(x, y, w, h)).

Definition at line 445 of file qgraphicsitem.h.

References isObscured().

+ Here is the call graph for this function:

◆ isObscuredBy()

bool QGraphicsItem::isObscuredBy ( const QGraphicsItem * item) const
virtual

Returns true if this item's bounding rect is completely obscured by the opaque shape of item.

The base implementation maps item's opaqueArea() to this item's coordinate system, and then checks if this item's boundingRect() is fully contained within the mapped shape.

You can reimplement this function to provide a custom algorithm for determining whether this item is obscured by item.

See also
opaqueArea(), isObscured()

Reimplemented in QAbstractGraphicsShapeItem, QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPolygonItem, QGraphicsLineItem, QGraphicsPixmapItem, QGraphicsTextItem, QGraphicsSimpleTextItem, and QGraphicsItemGroup.

Definition at line 5108 of file qgraphicsitem.cpp.

References boundingRect(), item, qt_closestItemFirst, and qt_QGraphicsItem_isObscured().

Referenced by QAbstractGraphicsShapeItem::isObscuredBy(), QGraphicsLineItem::isObscuredBy(), QGraphicsPixmapItem::isObscuredBy(), QGraphicsTextItem::isObscuredBy(), and QGraphicsItemGroup::isObscuredBy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isPanel()

◆ isSelected()

bool QGraphicsItem::isSelected ( ) const

Returns true if this item is selected; otherwise, false is returned.

Items that are in a group inherit the group's selected state.

Items are not selected by default.

See also
setSelected(), QGraphicsScene::setSelectionArea()

Definition at line 2706 of file qgraphicsitem.cpp.

References d_ptr, group(), and QGraphicsItemPrivate::selected.

Referenced by _qt_movableAncestorIsSelected(), QGraphicsScene::addItem(), QGraphicsScene::clearSelection(), mouseReleaseEvent(), QGraphicsItemPrivate::movableAncestorIsSelected(), QGraphicsScene::selectedItems(), QGraphicsItemPrivate::setEnabledHelper(), setFlags(), QGraphicsScene::setSelectionArea(), and QGraphicsItemPrivate::setVisibleHelper().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isUnderMouse()

bool QGraphicsItem::isUnderMouse ( ) const
Since
4.4 Returns true if this item is currently under the mouse cursor in one of the views; otherwise, false is returned.
See also
QGraphicsScene::views(), QCursor::pos()

Definition at line 6453 of file qgraphicsitem.cpp.

References contains(), d, mapFromScene(), QCursor::pos(), and view.

Referenced by QGraphicsWidget::initStyleOption().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isVisible()

bool QGraphicsItem::isVisible ( ) const

Returns true if the item is visible; otherwise, false is returned.

Note that the item's general visibility is unrelated to whether or not it is actually being visualized by a QGraphicsView.

See also
setVisible()

Definition at line 2337 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::visible.

Referenced by QDBusMenuItem::QDBusMenuItem(), QQuickSplitViewPrivate::accumulatedSize(), QtAndroidMenu::addAllMenuItemsToMenu(), QGraphicsScene::addItem(), QGraphicsWidget::close(), QQuickDeliveryAgentPrivate::deliverMatchingPointsToItem(), QGraphicsObject::event(), QGraphicsScene::event(), QGraphicsWidget::event(), QQuickVisualTestUtils::findItems(), QMapboxGLStyleSetLayoutProperty::fromMapItem(), QStatusBar::hideOrShow(), QQuickVisualTestUtils::isDelegateVisible(), QmlJSDebugger::itemAt(), QGraphicsProxyWidget::itemChange(), QQuickActionPrivate::itemVisibilityChanged(), QQuickSplitViewPrivate::itemVisibilityChanged(), QQuickSplitViewPrivate::layoutPositionItems(), QQuickSplitViewPrivate::layoutResizeSplitItems(), QQuickSplitViewPrivate::limitAndApplySizes(), QStatusBarPrivate::messageRect(), QtAndroidMenu::onPrepareOptionsMenu(), QStatusBar::paintEvent(), QQuickBasePositioner::prePositioning(), QQuickActionPrivate::registerItem(), QGraphicsScenePrivate::removeItemHelper(), QGraphicsScenePrivate::setActivePanelHelper(), QGraphicsScenePrivate::setFocusItemHelper(), setPanelModality(), QGraphicsWidget::setWindowFlags(), QQuickOverlayPrivate::startDrag(), QQuickSplitViewPrivate::updateFillIndex(), QQuickSplitViewPrivate::updateHandleVisibilities(), and QQuick3DItem2D::updateSpatialNode().

+ Here is the caller graph for this function:

◆ isVisibleTo()

bool QGraphicsItem::isVisibleTo ( const QGraphicsItem * parent) const
Since
4.4 Returns true if the item is visible to parent; otherwise, false is returned. parent can be \nullptr, in which case this function will return whether the item is visible to the scene or not.

An item may not be visible to its ancestors even if isVisible() is true. It may also be visible to its ancestors even if isVisible() is false. If any ancestor is hidden, the item itself will be implicitly hidden, in which case this function will return false.

See also
isVisible(), setVisible()

Definition at line 2355 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::explicitlyHidden.

◆ isWidget()

◆ isWindow()

bool QGraphicsItem::isWindow ( ) const
Since
4.4 Returns true if the item is a QGraphicsWidget window, otherwise returns false.
See also
QGraphicsWidget::windowFlags()

Definition at line 1841 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::isWidget, and Qt::Window.

Referenced by _q_paintItem(), QGraphicsProxyWidget::event(), QGraphicsWidget::focusNextPrevChild(), and QGraphicsWidget::initStyleOption().

+ Here is the caller graph for this function:

◆ itemChange()

QVariant QGraphicsItem::itemChange ( GraphicsItemChange change,
const QVariant & value )
protectedvirtual

This virtual function is called by QGraphicsItem to notify custom items that some part of the item's state changes.

By reimplementing this function, you can react to a change, and in some cases (depending on change), adjustments can be made.

change is the parameter of the item that is changing. value is the new value; the type of the value depends on change.

Example:

QVariant Component::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == ItemPositionChange && scene()) {
// value is the new position.
QPointF newPos = value.toPointF();
if (!rect.contains(newPos)) {
// Keep the item inside the scene rect.
newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
return newPos;
}
}
}

The default implementation does nothing, and returns value.

Note: Certain QGraphicsItem functions cannot be called in a reimplementation of this function; see the GraphicsItemChange documentation for details.

See also
GraphicsItemChange

Reimplemented in QGraphicsProxyWidget, and QGraphicsWidget.

Definition at line 7363 of file qgraphicsitem.cpp.

References Q_UNUSED.

Referenced by QGraphicsScenePrivate::_q_polishItems(), QGraphicsScene::addItem(), QGraphicsWidget::itemChange(), QGraphicsScene::removeItem(), QGraphicsItemPrivate::sendScenePosChange(), setCursor(), QGraphicsItemPrivate::setEnabledHelper(), setFlags(), setOpacity(), setParentItem(), QGraphicsItemPrivate::setParentItemHelper(), setPos(), setRotation(), setScale(), setSelected(), setTransform(), setTransformOriginPoint(), QGraphicsItemPrivate::setVisibleHelper(), and setZValue().

+ Here is the caller graph for this function:

◆ itemTransform()

QTransform QGraphicsItem::itemTransform ( const QGraphicsItem * other,
bool * ok = nullptr ) const
Since
4.5

Returns a QTransform that maps coordinates from this item to other. If ok is not null, and if there is no such transform, the boolean pointed to by ok will be set to false; otherwise it will be set to true.

This transform provides an alternative to the mapToItem() or mapFromItem() functions, by returning the appropriate transform so that you can map shapes and coordinates yourself. It also helps you write more efficient code when repeatedly mapping between the same two items.

Note
In rare circumstances, there is no transform that maps between two items.
See also
mapToItem(), mapFromItem(), deviceTransform()

Definition at line 4351 of file qgraphicsitem.cpp.

References child, QGraphicsItemPrivate::combineTransformFromParent(), commonAncestorItem(), d_ptr, QGraphicsItemPrivate::ensureSceneTransform(), QTransform::fromTranslate(), isAncestorOf(), itemTransform(), ok, other(), QGraphicsItemPrivate::parent, QGraphicsItemPrivate::pos, qWarning, QGraphicsItemPrivate::sceneTransform, this, QGraphicsItemPrivate::transformData, Qt::Uninitialized, QPointF::x(), and QPointF::y().

Referenced by QGraphicsItemGroup::addToGroup(), itemTransform(), mapFromItem(), mapFromItem(), mapFromItem(), mapFromItem(), mapRectFromItem(), mapRectToItem(), mapToItem(), mapToItem(), mapToItem(), mapToItem(), mouseMoveEvent(), and QGraphicsItemGroup::removeFromGroup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ keyPressEvent()

void QGraphicsItem::keyPressEvent ( QKeyEvent * event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive key press events for this item.

The default implementation ignores the event. If you reimplement this handler, the event will by default be accepted.

Note that key events are only received for items that set the ItemIsFocusable flag, and that have keyboard input focus.

See also
keyReleaseEvent(), setFocus(), QGraphicsScene::setFocusItem(), sceneEvent()

Reimplemented in QGraphicsTextItem, and QGraphicsProxyWidget.

Definition at line 6959 of file qgraphicsitem.cpp.

Referenced by sceneEvent().

+ Here is the caller graph for this function:

◆ keyReleaseEvent()

void QGraphicsItem::keyReleaseEvent ( QKeyEvent * event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive key release events for this item.

The default implementation ignores the event. If you reimplement this handler, the event will by default be accepted.

Note that key events are only received for items that set the ItemIsFocusable flag, and that have keyboard input focus.

See also
keyPressEvent(), setFocus(), QGraphicsScene::setFocusItem(), sceneEvent()

Reimplemented in QGraphicsTextItem, and QGraphicsProxyWidget.

Definition at line 6976 of file qgraphicsitem.cpp.

Referenced by sceneEvent().

+ Here is the caller graph for this function:

◆ mapFromItem() [1/6]

QPainterPath QGraphicsItem::mapFromItem ( const QGraphicsItem * item,
const QPainterPath & path ) const

Maps the path path, which is in item's coordinate system, to this item's coordinate system, and returns the mapped path.

If item is \nullptr, this function returns the same as mapFromScene().

See also
itemTransform(), mapFromParent(), mapFromScene(), mapToItem(), {The Graphics View Coordinate System}

Definition at line 6357 of file qgraphicsitem.cpp.

References item, itemTransform(), QTransform::map(), and mapFromScene().

+ Here is the call graph for this function:

◆ mapFromItem() [2/6]

QPointF QGraphicsItem::mapFromItem ( const QGraphicsItem * item,
const QPointF & point ) const

Maps the point point, which is in item's coordinate system, to this item's coordinate system, and returns the mapped coordinate.

If item is \nullptr, this function returns the same as mapFromScene().

See also
itemTransform(), mapFromParent(), mapFromScene(), transform(), mapToItem(), {The Graphics View Coordinate System}

Definition at line 6172 of file qgraphicsitem.cpp.

References item, itemTransform(), QTransform::map(), and mapFromScene().

Referenced by QGraphicsItemGroup::addToGroup(), collidesWithItem(), QQuickTableViewHoverHandler::handleEventPoint(), QQuickPathView::itemAt(), mapFromItem(), mapFromItem(), and QGraphicsItemPrivate::remapItemPos().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapFromItem() [3/6]

QPolygonF QGraphicsItem::mapFromItem ( const QGraphicsItem * item,
const QPolygonF & polygon ) const

Maps the polygon polygon, which is in item's coordinate system, to this item's coordinate system, and returns the mapped polygon.

If item is \nullptr, this function returns the same as mapFromScene().

See also
itemTransform(), mapToItem(), mapFromParent(), transform(), {The Graphics View Coordinate System}

Definition at line 6312 of file qgraphicsitem.cpp.

References item, itemTransform(), QTransform::map(), and mapFromScene().

+ Here is the call graph for this function:

◆ mapFromItem() [4/6]

QPolygonF QGraphicsItem::mapFromItem ( const QGraphicsItem * item,
const QRectF & rect ) const

Maps the rectangle rect, which is in item's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a polygon.

If item is \nullptr, this function returns the same as mapFromScene()

See also
itemTransform(), mapToItem(), mapFromParent(), transform(), {The Graphics View Coordinate System}

Definition at line 6244 of file qgraphicsitem.cpp.

References item, itemTransform(), QTransform::map(), mapFromScene(), and rect.

+ Here is the call graph for this function:

◆ mapFromItem() [5/6]

QPointF QGraphicsItem::mapFromItem ( const QGraphicsItem * item,
qreal x,
qreal y ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling mapFromItem(item, QPointF(x, y)).

Definition at line 453 of file qgraphicsitem.h.

References item, and mapFromItem().

+ Here is the call graph for this function:

◆ mapFromItem() [6/6]

QPolygonF QGraphicsItem::mapFromItem ( const QGraphicsItem * item,
qreal x,
qreal y,
qreal w,
qreal h ) const
inline
Since
4.3

This convenience function is equivalent to calling mapFromItem(item, QRectF(x, y, w, h)).

Definition at line 471 of file qgraphicsitem.h.

References item, and mapFromItem().

+ Here is the call graph for this function:

◆ mapFromParent() [1/6]

QPainterPath QGraphicsItem::mapFromParent ( const QPainterPath & path) const

Maps the path path, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped path.

See also
mapFromScene(), mapFromItem(), mapToParent(), {The Graphics View Coordinate System}

Definition at line 6371 of file qgraphicsitem.cpp.

References d_ptr, QTransform::inverted(), QTransform::map(), QGraphicsItemPrivate::pos, QGraphicsItemPrivate::transformData, and QGraphicsItemPrivate::transformToParent().

+ Here is the call graph for this function:

◆ mapFromParent() [2/6]

QPointF QGraphicsItem::mapFromParent ( const QPointF & point) const

Maps the point point, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped coordinate.

See also
mapFromItem(), mapFromScene(), transform(), mapToParent(), {The Graphics View Coordinate System}

Definition at line 6195 of file qgraphicsitem.cpp.

References d_ptr, QTransform::inverted(), QTransform::map(), QGraphicsItemPrivate::pos, QGraphicsItemPrivate::transformData, and QGraphicsItemPrivate::transformToParent().

Referenced by mapFromParent(), and mapFromParent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapFromParent() [3/6]

QPolygonF QGraphicsItem::mapFromParent ( const QPolygonF & polygon) const

Maps the polygon polygon, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped polygon.

See also
mapToParent(), mapToItem(), transform(), {The Graphics View Coordinate System}

Definition at line 6326 of file qgraphicsitem.cpp.

References d_ptr, QTransform::inverted(), QTransform::map(), QGraphicsItemPrivate::pos, QGraphicsItemPrivate::transformData, and QGraphicsItemPrivate::transformToParent().

+ Here is the call graph for this function:

◆ mapFromParent() [4/6]

QPolygonF QGraphicsItem::mapFromParent ( const QRectF & rect) const

Maps the rectangle rect, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a polygon.

See also
mapToParent(), mapFromItem(), transform(), {The Graphics View Coordinate System}

Definition at line 6266 of file qgraphicsitem.cpp.

References d_ptr, QTransform::inverted(), QTransform::map(), QGraphicsItemPrivate::pos, rect, QGraphicsItemPrivate::transformData, and QGraphicsItemPrivate::transformToParent().

+ Here is the call graph for this function:

◆ mapFromParent() [5/6]

QPointF QGraphicsItem::mapFromParent ( qreal x,
qreal y ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling mapFromParent(QPointF(x, y)).

Definition at line 455 of file qgraphicsitem.h.

References mapFromParent().

+ Here is the call graph for this function:

◆ mapFromParent() [6/6]

QPolygonF QGraphicsItem::mapFromParent ( qreal x,
qreal y,
qreal w,
qreal h ) const
inline
Since
4.3

This convenience function is equivalent to calling mapFromItem(QRectF(x, y, w, h)).

Definition at line 473 of file qgraphicsitem.h.

References mapFromParent().

+ Here is the call graph for this function:

◆ mapFromScene() [1/6]

QPainterPath QGraphicsItem::mapFromScene ( const QPainterPath & path) const

Maps the path path, which is in this item's scene's coordinate system, to this item's coordinate system, and returns the mapped path.

See also
mapFromParent(), mapFromItem(), mapToScene(), {The Graphics View Coordinate System}

Definition at line 6386 of file qgraphicsitem.cpp.

References d_ptr, QTransform::dx(), QTransform::dy(), QGraphicsItemPrivate::hasTranslateOnlySceneTransform(), QTransform::inverted(), QTransform::map(), and QGraphicsItemPrivate::sceneTransform.

+ Here is the call graph for this function:

◆ mapFromScene() [2/6]

QPointF QGraphicsItem::mapFromScene ( const QPointF & point) const

Maps the point point, which is in this item's scene's coordinate system, to this item's coordinate system, and returns the mapped coordinate.

See also
mapFromItem(), mapFromParent(), transform(), mapToScene(), {The Graphics View Coordinate System}

Definition at line 6219 of file qgraphicsitem.cpp.

References d_ptr, QTransform::dx(), QTransform::dy(), QGraphicsItemPrivate::hasTranslateOnlySceneTransform(), QTransform::inverted(), QTransform::map(), QGraphicsItemPrivate::sceneTransform, QPointF::x(), and QPointF::y().

Referenced by QQuickSwipeDelegatePrivate::attachedObjectsSetPressed(), QQuickDeliveryAgentPrivate::deliverHoverEventToItem(), QQuickDeliveryAgentPrivate::deliverTouchAsMouse(), QGraphicsProxyWidget::event(), QQuickPathViewPrivate::handleMousePressEvent(), QQuickSwipeDelegatePrivate::handleMouseReleaseEvent(), isUnderMouse(), QQuickHandlerPoint::localize(), mapFromItem(), mapFromItem(), mapFromItem(), mapFromItem(), mapFromScene(), mapFromScene(), QQuickItem::mapToItem(), mouseMoveEvent(), QQuickDeliveryAgentPrivate::pointerTargets(), QQuickMouseAreaPrivate::propagateHelper(), and setCursor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapFromScene() [3/6]

QPolygonF QGraphicsItem::mapFromScene ( const QPolygonF & polygon) const

Maps the polygon polygon, which is in this item's scene's coordinate system, to this item's coordinate system, and returns the mapped polygon.

See also
mapToScene(), mapFromParent(), transform(), {The Graphics View Coordinate System}

Definition at line 6341 of file qgraphicsitem.cpp.

References d_ptr, QTransform::dx(), QTransform::dy(), QGraphicsItemPrivate::hasTranslateOnlySceneTransform(), QTransform::inverted(), QTransform::map(), and QGraphicsItemPrivate::sceneTransform.

+ Here is the call graph for this function:

◆ mapFromScene() [4/6]

QPolygonF QGraphicsItem::mapFromScene ( const QRectF & rect) const

Maps the rectangle rect, which is in this item's scene's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a polygon.

See also
mapToScene(), mapFromItem(), transform(), {The Graphics View Coordinate System}

Definition at line 6289 of file qgraphicsitem.cpp.

References d_ptr, QTransform::dx(), QTransform::dy(), QGraphicsItemPrivate::hasTranslateOnlySceneTransform(), QTransform::inverted(), QTransform::map(), rect, and QGraphicsItemPrivate::sceneTransform.

+ Here is the call graph for this function:

◆ mapFromScene() [5/6]

QPointF QGraphicsItem::mapFromScene ( qreal x,
qreal y ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling mapFromScene(QPointF(x, y)).

Definition at line 457 of file qgraphicsitem.h.

References mapFromScene().

+ Here is the call graph for this function:

◆ mapFromScene() [6/6]

QPolygonF QGraphicsItem::mapFromScene ( qreal x,
qreal y,
qreal w,
qreal h ) const
inline
Since
4.3

This convenience function is equivalent to calling mapFromScene(QRectF(x, y, w, h)).

Definition at line 475 of file qgraphicsitem.h.

References mapFromScene().

+ Here is the call graph for this function:

◆ mapRectFromItem() [1/2]

QRectF QGraphicsItem::mapRectFromItem ( const QGraphicsItem * item,
const QRectF & rect ) const
Since
4.5

Maps the rectangle rect, which is in item's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a new rectangle (i.e., the bounding rectangle of the resulting polygon).

If item is \nullptr, this function returns the same as mapRectFromScene().

See also
itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The Graphics View Coordinate System}

Definition at line 6005 of file qgraphicsitem.cpp.

References item, itemTransform(), QTransform::mapRect(), mapRectFromScene(), and rect.

Referenced by mapRectFromItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapRectFromItem() [2/2]

QRectF QGraphicsItem::mapRectFromItem ( const QGraphicsItem * item,
qreal x,
qreal y,
qreal w,
qreal h ) const
inline
Since
4.5

This convenience function is equivalent to calling mapRectFromItem(item, QRectF(x, y, w, h)).

Definition at line 477 of file qgraphicsitem.h.

References item, and mapRectFromItem().

+ Here is the call graph for this function:

◆ mapRectFromParent() [1/2]

QRectF QGraphicsItem::mapRectFromParent ( const QRectF & rect) const
Since
4.5

Maps the rectangle rect, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a new rectangle (i.e., the bounding rectangle of the resulting polygon).

See also
itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The Graphics View Coordinate System}

Definition at line 6030 of file qgraphicsitem.cpp.

References d_ptr, QTransform::inverted(), QTransform::mapRect(), QGraphicsItemPrivate::pos, rect, QGraphicsItemPrivate::transformData, QGraphicsItemPrivate::transformToParent(), and QRectF::translated().

Referenced by mapRectFromParent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapRectFromParent() [2/2]

QRectF QGraphicsItem::mapRectFromParent ( qreal x,
qreal y,
qreal w,
qreal h ) const
inline
Since
4.5

This convenience function is equivalent to calling mapRectFromParent(QRectF(x, y, w, h)).

Definition at line 479 of file qgraphicsitem.h.

References mapRectFromParent().

+ Here is the call graph for this function:

◆ mapRectFromScene() [1/2]

QRectF QGraphicsItem::mapRectFromScene ( const QRectF & rect) const
Since
4.5

Maps the rectangle rect, which is in scene coordinates, to this item's coordinate system, and returns the mapped rectangle as a new rectangle (i.e., the bounding rectangle of the resulting polygon).

See also
itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The Graphics View Coordinate System}

Definition at line 6055 of file qgraphicsitem.cpp.

References d_ptr, QTransform::dx(), QTransform::dy(), QGraphicsItemPrivate::hasTranslateOnlySceneTransform(), QTransform::inverted(), QTransform::mapRect(), rect, QGraphicsItemPrivate::sceneTransform, and QRectF::translated().

Referenced by mapRectFromItem(), and mapRectFromScene().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapRectFromScene() [2/2]

QRectF QGraphicsItem::mapRectFromScene ( qreal x,
qreal y,
qreal w,
qreal h ) const
inline
Since
4.5

This convenience function is equivalent to calling mapRectFromScene(QRectF(x, y, w, h)).

Definition at line 481 of file qgraphicsitem.h.

References mapRectFromScene().

+ Here is the call graph for this function:

◆ mapRectToItem() [1/2]

QRectF QGraphicsItem::mapRectToItem ( const QGraphicsItem * item,
const QRectF & rect ) const
Since
4.5

Maps the rectangle rect, which is in this item's coordinate system, to item's coordinate system, and returns the mapped rectangle as a new rectangle (i.e., the bounding rectangle of the resulting polygon).

If item is \nullptr, this function returns the same as mapRectToScene().

See also
itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The Graphics View Coordinate System}

Definition at line 5930 of file qgraphicsitem.cpp.

References item, itemTransform(), QTransform::mapRect(), mapRectToScene(), and rect.

Referenced by mapRectToItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapRectToItem() [2/2]

QRectF QGraphicsItem::mapRectToItem ( const QGraphicsItem * item,
qreal x,
qreal y,
qreal w,
qreal h ) const
inline
Since
4.5

This convenience function is equivalent to calling mapRectToItem(item, QRectF(x, y, w, h)).

Definition at line 465 of file qgraphicsitem.h.

References item, and mapRectToItem().

+ Here is the call graph for this function:

◆ mapRectToParent() [1/2]

QRectF QGraphicsItem::mapRectToParent ( const QRectF & rect) const
Since
4.5

Maps the rectangle rect, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped rectangle as a new rectangle (i.e., the bounding rectangle of the resulting polygon).

See also
itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The Graphics View Coordinate System}

Definition at line 5954 of file qgraphicsitem.cpp.

References d_ptr, QTransform::mapRect(), QGraphicsItemPrivate::pos, rect, QGraphicsItemPrivate::transformData, QGraphicsItemPrivate::transformToParent(), and QRectF::translated().

Referenced by mapRectToParent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapRectToParent() [2/2]

QRectF QGraphicsItem::mapRectToParent ( qreal x,
qreal y,
qreal w,
qreal h ) const
inline
Since
4.5

This convenience function is equivalent to calling mapRectToParent(QRectF(x, y, w, h)).

Definition at line 467 of file qgraphicsitem.h.

References mapRectToParent().

+ Here is the call graph for this function:

◆ mapRectToScene() [1/2]

QRectF QGraphicsItem::mapRectToScene ( const QRectF & rect) const
Since
4.5

Maps the rectangle rect, which is in this item's coordinate system, to the scene coordinate system, and returns the mapped rectangle as a new rectangle (i.e., the bounding rectangle of the resulting polygon).

See also
itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The Graphics View Coordinate System}

Definition at line 5979 of file qgraphicsitem.cpp.

References d_ptr, QTransform::dx(), QTransform::dy(), QGraphicsItemPrivate::hasTranslateOnlySceneTransform(), QTransform::mapRect(), rect, QGraphicsItemPrivate::sceneTransform, and QRectF::translated().

Referenced by mapRectToItem(), mapRectToScene(), and remapInputMethodQueryEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapRectToScene() [2/2]

QRectF QGraphicsItem::mapRectToScene ( qreal x,
qreal y,
qreal w,
qreal h ) const
inline
Since
4.5

This convenience function is equivalent to calling mapRectToScene(QRectF(x, y, w, h)).

Definition at line 469 of file qgraphicsitem.h.

References mapRectToScene().

+ Here is the call graph for this function:

◆ mapToItem() [1/6]

QPainterPath QGraphicsItem::mapToItem ( const QGraphicsItem * item,
const QPainterPath & path ) const

Maps the path path, which is in this item's coordinate system, to item's coordinate system, and returns the mapped path.

If item is \nullptr, this function returns the same as mapToScene().

See also
itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The Graphics View Coordinate System}

Definition at line 6125 of file qgraphicsitem.cpp.

References item, itemTransform(), QTransform::map(), and mapToScene().

+ Here is the call graph for this function:

◆ mapToItem() [2/6]

QPointF QGraphicsItem::mapToItem ( const QGraphicsItem * item,
const QPointF & point ) const

Maps the point point, which is in this item's coordinate system, to item's coordinate system, and returns the mapped coordinate.

If item is \nullptr, this function returns the same as mapToScene().

See also
itemTransform(), mapToParent(), mapToScene(), transform(), mapFromItem(), {The Graphics View Coordinate System}

Definition at line 5789 of file qgraphicsitem.cpp.

References item, itemTransform(), QTransform::map(), and mapToScene().

Referenced by QmlJSDebugger::collectItemsAt(), QQuickSwipeDelegatePrivate::handleMouseMoveEvent(), QQuickSwipeDelegatePrivate::handleMousePressEvent(), QmlJSDebugger::itemAt(), mapToItem(), mapToItem(), and QGraphicsItemGroup::removeFromGroup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapToItem() [3/6]

QPolygonF QGraphicsItem::mapToItem ( const QGraphicsItem * item,
const QPolygonF & polygon ) const

Maps the polygon polygon, which is in this item's coordinate system, to item's coordinate system, and returns the mapped polygon.

If item is \nullptr, this function returns the same as mapToScene().

See also
itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The Graphics View Coordinate System}

Definition at line 6078 of file qgraphicsitem.cpp.

References item, itemTransform(), QTransform::map(), and mapToScene().

+ Here is the call graph for this function:

◆ mapToItem() [4/6]

QPolygonF QGraphicsItem::mapToItem ( const QGraphicsItem * item,
const QRectF & rect ) const

Maps the rectangle rect, which is in this item's coordinate system, to item's coordinate system, and returns the mapped rectangle as a polygon.

If item is \nullptr, this function returns the same as mapToScene().

See also
itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The Graphics View Coordinate System}

Definition at line 5859 of file qgraphicsitem.cpp.

References item, itemTransform(), QTransform::map(), mapToScene(), and rect.

+ Here is the call graph for this function:

◆ mapToItem() [5/6]

QPointF QGraphicsItem::mapToItem ( const QGraphicsItem * item,
qreal x,
qreal y ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling mapToItem(item, QPointF(x, y)).

Definition at line 447 of file qgraphicsitem.h.

References item, and mapToItem().

+ Here is the call graph for this function:

◆ mapToItem() [6/6]

QPolygonF QGraphicsItem::mapToItem ( const QGraphicsItem * item,
qreal x,
qreal y,
qreal w,
qreal h ) const
inline
Since
4.3

This convenience function is equivalent to calling mapToItem(item, QRectF(x, y, w, h)).

Definition at line 459 of file qgraphicsitem.h.

References item, and mapToItem().

+ Here is the call graph for this function:

◆ mapToParent() [1/6]

QPainterPath QGraphicsItem::mapToParent ( const QPainterPath & path) const

Maps the path path, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped path.

If the item has no parent, path will be mapped to the scene's coordinate system.

See also
mapToScene(), mapToItem(), mapFromParent(), {The Graphics View Coordinate System}

Definition at line 6141 of file qgraphicsitem.cpp.

References d_ptr, QTransform::map(), QGraphicsItemPrivate::pos, QGraphicsItemPrivate::transformData, and QGraphicsItemPrivate::transformToParent().

+ Here is the call graph for this function:

◆ mapToParent() [2/6]

QPointF QGraphicsItem::mapToParent ( const QPointF & point) const

Maps the point point, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped coordinate.

If the item has no parent, point will be mapped to the scene's coordinate system.

See also
mapToItem(), mapToScene(), transform(), mapFromParent(), {The Graphics View Coordinate System}

Definition at line 5812 of file qgraphicsitem.cpp.

References d_ptr, QTransform::map(), QGraphicsItemPrivate::pos, QGraphicsItemPrivate::transformData, and QGraphicsItemPrivate::transformToParent().

Referenced by mapToParent(), mapToParent(), and mouseMoveEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapToParent() [3/6]

QPolygonF QGraphicsItem::mapToParent ( const QPolygonF & polygon) const

Maps the polygon polygon, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped polygon.

If the item has no parent, polygon will be mapped to the scene's coordinate system.

See also
mapToScene(), mapToItem(), mapFromParent(), {The Graphics View Coordinate System}

Definition at line 6094 of file qgraphicsitem.cpp.

References d_ptr, QTransform::map(), QGraphicsItemPrivate::pos, QGraphicsItemPrivate::transformData, and QGraphicsItemPrivate::transformToParent().

+ Here is the call graph for this function:

◆ mapToParent() [4/6]

QPolygonF QGraphicsItem::mapToParent ( const QRectF & rect) const

Maps the rectangle rect, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped rectangle as a polygon.

If the item has no parent, rect will be mapped to the scene's coordinate system.

See also
mapToScene(), mapToItem(), mapFromParent(), {The Graphics View Coordinate System}

Definition at line 5882 of file qgraphicsitem.cpp.

References d_ptr, QTransform::map(), QGraphicsItemPrivate::pos, rect, QGraphicsItemPrivate::transformData, and QGraphicsItemPrivate::transformToParent().

+ Here is the call graph for this function:

◆ mapToParent() [5/6]

QPointF QGraphicsItem::mapToParent ( qreal x,
qreal y ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling mapToParent(QPointF(x, y)).

Definition at line 449 of file qgraphicsitem.h.

References mapToParent().

+ Here is the call graph for this function:

◆ mapToParent() [6/6]

QPolygonF QGraphicsItem::mapToParent ( qreal x,
qreal y,
qreal w,
qreal h ) const
inline
Since
4.3

This convenience function is equivalent to calling mapToParent(QRectF(x, y, w, h)).

Definition at line 461 of file qgraphicsitem.h.

References mapToParent().

+ Here is the call graph for this function:

◆ mapToScene() [1/6]

QPainterPath QGraphicsItem::mapToScene ( const QPainterPath & path) const

Maps the path path, which is in this item's coordinate system, to the scene's coordinate system, and returns the mapped path.

See also
mapToParent(), mapToItem(), mapFromScene(), {The Graphics View Coordinate System}

Definition at line 6156 of file qgraphicsitem.cpp.

References d_ptr, QTransform::dx(), QTransform::dy(), QGraphicsItemPrivate::hasTranslateOnlySceneTransform(), QTransform::map(), and QGraphicsItemPrivate::sceneTransform.

+ Here is the call graph for this function:

◆ mapToScene() [2/6]

QPointF QGraphicsItem::mapToScene ( const QPointF & point) const

Maps the point point, which is in this item's coordinate system, to the scene's coordinate system, and returns the mapped coordinate.

See also
mapToItem(), mapToParent(), transform(), mapFromScene(), {The Graphics View Coordinate System}

Definition at line 5835 of file qgraphicsitem.cpp.

References d_ptr, QTransform::dx(), QTransform::dy(), QGraphicsItemPrivate::hasTranslateOnlySceneTransform(), QTransform::map(), QGraphicsItemPrivate::sceneTransform, QPointF::x(), and QPointF::y().

Referenced by isObscured(), QQuickVisualTestUtils::mapCenterToWindow(), QQuickItem::mapFromItem(), mapToItem(), mapToItem(), mapToItem(), mapToItem(), mapToScene(), mapToScene(), QQuickVisualTestUtils::mapToWindow(), remapInputMethodQueryEvent(), and scenePos().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapToScene() [3/6]

QPolygonF QGraphicsItem::mapToScene ( const QPolygonF & polygon) const

Maps the polygon polygon, which is in this item's coordinate system, to the scene's coordinate system, and returns the mapped polygon.

See also
mapToParent(), mapToItem(), mapFromScene(), {The Graphics View Coordinate System}

Definition at line 6109 of file qgraphicsitem.cpp.

References d_ptr, QTransform::dx(), QTransform::dy(), QGraphicsItemPrivate::hasTranslateOnlySceneTransform(), QTransform::map(), and QGraphicsItemPrivate::sceneTransform.

+ Here is the call graph for this function:

◆ mapToScene() [4/6]

QPolygonF QGraphicsItem::mapToScene ( const QRectF & rect) const

Maps the rectangle rect, which is in this item's coordinate system, to the scene's coordinate system, and returns the mapped rectangle as a polygon.

See also
mapToParent(), mapToItem(), mapFromScene(), {The Graphics View Coordinate System}

Definition at line 5904 of file qgraphicsitem.cpp.

References d_ptr, QTransform::dx(), QTransform::dy(), QGraphicsItemPrivate::hasTranslateOnlySceneTransform(), QTransform::map(), rect, and QGraphicsItemPrivate::sceneTransform.

+ Here is the call graph for this function:

◆ mapToScene() [5/6]

QPointF QGraphicsItem::mapToScene ( qreal x,
qreal y ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling mapToScene(QPointF(x, y)).

Definition at line 451 of file qgraphicsitem.h.

References mapToScene().

+ Here is the call graph for this function:

◆ mapToScene() [6/6]

QPolygonF QGraphicsItem::mapToScene ( qreal x,
qreal y,
qreal w,
qreal h ) const
inline
Since
4.3

This convenience function is equivalent to calling mapToScene(QRectF(x, y, w, h)).

Definition at line 463 of file qgraphicsitem.h.

References mapToScene().

+ Here is the call graph for this function:

◆ mouseDoubleClickEvent()

void QGraphicsItem::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive mouse double-click events for this item.

When doubleclicking an item, the item will first receive a mouse press event, followed by a release event (i.e., a click), then a double-click event, and finally a release event.

Calling QEvent::ignore() or QEvent::accept() on event has no effect.

The default implementation calls mousePressEvent(). If you want to keep the base implementation when reimplementing this function, call QGraphicsItem::mouseDoubleClickEvent() in your reimplementation.

Note that an item will not receive double click events if it is neither \l {QGraphicsItem::ItemIsSelectable}{selectable} nor \l{QGraphicsItem::ItemIsMovable}{movable} (single mouse clicks are ignored in this case, and that stops the generation of double clicks).

See also
mousePressEvent(), mouseMoveEvent(), mouseReleaseEvent(), sceneEvent()

Reimplemented in QGraphicsTextItem, and QGraphicsProxyWidget.

Definition at line 7240 of file qgraphicsitem.cpp.

References mousePressEvent().

Referenced by QGraphicsTextItem::mouseDoubleClickEvent(), and sceneEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mouseMoveEvent()

void QGraphicsItem::mouseMoveEvent ( QGraphicsSceneMouseEvent * event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive mouse move events for this item.

If you do receive this event, you can be certain that this item also received a mouse press event, and that this item is the current mouse grabber.

Calling QEvent::ignore() or QEvent::accept() on event has no effect.

The default implementation handles basic item interaction, such as selection and moving. If you want to keep the base implementation when reimplementing this function, call QGraphicsItem::mouseMoveEvent() in your reimplementation.

Please note that mousePressEvent() decides which graphics item it is that receives mouse events. See the mousePressEvent() description for details.

See also
mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), sceneEvent()

Reimplemented in QGraphicsTextItem, and QGraphicsProxyWidget.

Definition at line 7075 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::ancestorFlags, QGraphicsItemPrivate::AncestorIgnoresTransformations, QGraphicsItemPrivate::TransformData::computedFullTransform(), d_ptr, deviceTransform(), flags(), i, item, ItemIgnoresTransformations, ItemIsMovable, ItemIsSelectable, itemTransform(), Qt::LeftButton, mapFromScene(), mapToParent(), QGraphicsItemPrivate::movableAncestorIsSelected(), pos, pos(), QGraphicsItemPrivate::pos, QGraphicsItemPrivate::scene, sceneTransform(), QGraphicsScene::selectedItems(), setPos(), setSelected(), QGraphicsItemPrivate::transformData, QTransform::translate(), view, QPointF::x(), and QPointF::y().

Referenced by QGraphicsTextItem::mouseMoveEvent(), and sceneEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mousePressEvent()

void QGraphicsItem::mousePressEvent ( QGraphicsSceneMouseEvent * event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive mouse press events for this item.

Mouse press events are only delivered to items that accept the mouse button that is pressed. By default, an item accepts all mouse buttons, but you can change this by calling setAcceptedMouseButtons().

The mouse press event decides which item should become the mouse grabber (see QGraphicsScene::mouseGrabberItem()). If you do not reimplement this function, the press event will propagate to any topmost item beneath this item, and no other mouse events will be delivered to this item.

If you do reimplement this function, event will by default be accepted (see QEvent::accept()), and this item is then the mouse grabber. This allows the item to receive future move, release and double-click events. If you call QEvent::ignore() on event, this item will lose the mouse grab, and event will propagate to any topmost item beneath. No further mouse events will be delivered to this item unless a new mouse press event is received.

The default implementation handles basic item interaction, such as selection and moving. If you want to keep the base implementation when reimplementing this function, call QGraphicsItem::mousePressEvent() in your reimplementation.

The event is \l{QEvent::ignore()}d for items that are neither \l{QGraphicsItem::ItemIsMovable}{movable} nor \l{QGraphicsItem::ItemIsSelectable}{selectable}.

See also
mouseMoveEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), sceneEvent()

Reimplemented in CustomItem, QGraphicsTextItem, and QGraphicsProxyWidget.

Definition at line 7014 of file qgraphicsitem.cpp.

References QGraphicsScene::clearSelection(), QGraphicsWidget::close(), Qt::ControlModifier, d_ptr, flags(), QGraphicsItemPrivate::isWidget, ItemIsMovable, ItemIsSelectable, Qt::LeftButton, Qt::Popup, scene(), QGraphicsItemPrivate::scene, QGraphicsItemPrivate::selected, and setSelected().

Referenced by mouseDoubleClickEvent(), QGraphicsTextItem::mousePressEvent(), and sceneEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mouseReleaseEvent()

void QGraphicsItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive mouse release events for this item.

Calling QEvent::ignore() or QEvent::accept() on event has no effect.

The default implementation handles basic item interaction, such as selection and moving. If you want to keep the base implementation when reimplementing this function, call QGraphicsItem::mouseReleaseEvent() in your reimplementation.

Please note that mousePressEvent() decides which graphics item it is that receives mouse events. See the mousePressEvent() description for details.

See also
mousePressEvent(), mouseMoveEvent(), mouseDoubleClickEvent(), sceneEvent()

Reimplemented in QGraphicsTextItem, and QGraphicsProxyWidget.

Definition at line 7177 of file qgraphicsitem.cpp.

References QGraphicsScene::clear(), QGraphicsScene::clearSelection(), Qt::ControlModifier, d_ptr, emit, QList< T >::insert(), isSelected(), item, ItemIsSelectable, Qt::LeftButton, QList< T >::remove(), scene(), QGraphicsItemPrivate::scene, QGraphicsItemPrivate::selected, QGraphicsScene::selectedItems(), QGraphicsScene::selectionChanged(), and setSelected().

Referenced by QGraphicsTextItem::mouseReleaseEvent(), and sceneEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ moveBy()

void QGraphicsItem::moveBy ( qreal dx,
qreal dy )
inline

Moves the item by dx points horizontally, and dy point vertically.

This function is equivalent to calling setPos(pos() + QPointF(dx, dy)).

Definition at line 235 of file qgraphicsitem.h.

References pos, and setPos().

+ Here is the call graph for this function:

◆ opacity()

qreal QGraphicsItem::opacity ( ) const
Since
4.5

Returns this item's local opacity, which is between 0.0 (transparent) and 1.0 (opaque). This value is combined with parent and ancestor values into the effectiveOpacity(). The effective opacity decides how the item is rendered and also affects its visibility when queried by functions such as QGraphicsView::items().

The opacity property decides the state of the painter passed to the paint() function. If the item is cached, i.e., ItemCoordinateCache or DeviceCoordinateCache, the effective property will be applied to the item's cache as it is rendered.

The default opacity is 1.0; fully opaque.

See also
setOpacity(), paint(), ItemIgnoresParentOpacity, ItemDoesntPropagateOpacityToChildren

Definition at line 2790 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::opacity.

Referenced by QmlJSDebugger::itemAt(), and setOpacity().

+ Here is the caller graph for this function:

◆ opaqueArea()

QPainterPath QGraphicsItem::opaqueArea ( ) const
virtual

This virtual function returns a shape representing the area where this item is opaque.

An area is opaque if it is filled using an opaque brush or color (i.e., not transparent).

This function is used by isObscuredBy(), which is called by underlying items to determine if they are obscured by this item.

The default implementation returns an empty QPainterPath, indicating that this item is completely transparent and does not obscure any other items.

See also
isObscuredBy(), isObscured(), shape()

Reimplemented in QAbstractGraphicsShapeItem, QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPolygonItem, QGraphicsLineItem, QGraphicsPixmapItem, QGraphicsTextItem, QGraphicsSimpleTextItem, and QGraphicsItemGroup.

Definition at line 5129 of file qgraphicsitem.cpp.

Referenced by QAbstractGraphicsShapeItem::opaqueArea(), QGraphicsLineItem::opaqueArea(), QGraphicsTextItem::opaqueArea(), and QGraphicsItemGroup::opaqueArea().

+ Here is the caller graph for this function:

◆ paint()

void QGraphicsItem::paint ( QPainter * painter,
const QStyleOptionGraphicsItem * option,
QWidget * widget = nullptr )
pure virtual

This function, which is usually called by QGraphicsView, paints the contents of an item in local coordinates.

Reimplement this function in a QGraphicsItem subclass to provide the item's painting implementation, using painter. The option parameter provides style options for the item, such as its state, exposed area and its level-of-detail hints. The widget argument is optional. If provided, it points to the widget that is being painted on; otherwise, it is 0. For cached painting, widget is always 0.

void RoundRectItem::paint(QPainter *painter,
{
painter->drawRoundedRect(-10, -10, 20, 20, 5, 5);
}

The painter's pen is 0-width by default, and its pen is initialized to the QPalette::Text brush from the paint device's palette. The brush is initialized to QPalette::Window.

Make sure to constrain all painting inside the boundaries of boundingRect() to avoid rendering artifacts (as QGraphicsView does not clip the painter for you). In particular, when QPainter renders the outline of a shape using an assigned QPen, half of the outline will be drawn outside, and half inside, the shape you're rendering (e.g., with a pen width of 2 units, you must draw outlines 1 unit inside boundingRect()). QGraphicsItem does not support use of cosmetic pens with a non-zero width.

All painting is done in local coordinates.

Note
It is mandatory that an item will always redraw itself in the exact same way, unless update() was called; otherwise visual artifacts may occur. In other words, two subsequent calls to paint() must always produce the same output, unless update() was called between them.
Enabling caching for an item does not guarantee that paint() will be invoked only once by the Graphics View framework, even without any explicit call to update(). See the documentation of setCacheMode() for more details.
See also
setCacheMode(), QPen::width(), {Item Coordinates}, ItemUsesExtendedStyleOption

Implemented in QtPrivate::PageItem, SimpleItem, QGraphicsPixmapItem, QGraphicsTextItem, QGraphicsSimpleTextItem, QGraphicsProxyWidget, QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPolygonItem, QGraphicsLineItem, QGraphicsItemGroup, QGraphicsWidget, and QGraphicsSvgItem.

Referenced by _q_paintItem(), and QGraphicsScenePrivate::draw().

+ Here is the caller graph for this function:

◆ panel()

QGraphicsItem * QGraphicsItem::panel ( ) const
Since
4.6

Returns the item's panel, or \nullptr if this item does not have a panel. If the item is a panel, it will return itself. Otherwise it will return the closest ancestor that is a panel.

See also
isPanel(), ItemIsPanel

Definition at line 1746 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::flags, ItemIsPanel, panel(), and QGraphicsItemPrivate::parent.

Referenced by QGraphicsScenePrivate::dispatchHoverEvent(), hasFocus(), isActive(), panel(), setActive(), QGraphicsScenePrivate::setActivePanelHelper(), QGraphicsItemPrivate::setFocusHelper(), QGraphicsItemPrivate::setSubFocus(), and window().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ panelModality()

QGraphicsItem::PanelModality QGraphicsItem::panelModality ( ) const
Since
4.6

Returns the modality for this item.

Definition at line 2122 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::panelModality.

Referenced by QGraphicsScene::addItem(), QGraphicsScenePrivate::removeItemHelper(), and setPanelModality().

+ Here is the caller graph for this function:

◆ parentItem()

QGraphicsItem * QGraphicsItem::parentItem ( ) const

Returns a pointer to this item's parent item.

If this item does not have a parent, \nullptr is returned.

See also
setParentItem(), childItems()

Definition at line 1653 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::parent.

Referenced by QQuickSplitViewAttached::QQuickSplitViewAttached(), QQuickStackLayoutAttached::QQuickStackLayoutAttached(), QQuickStackViewAttached::QQuickStackViewAttached(), _qt_movableAncestorIsSelected(), QGraphicsLayoutPrivate::addChildLayoutItem(), QDeclarativeGeoMap::addMapItem_real(), QDeclarativeGeoMap::clearMapItems(), collidesWithItem(), QQuickComboBoxPrivate::createdItem(), QQuickTableViewPrivate::createFxTableItem(), QQuickDeliveryAgentPrivate::deliverKeyEvent(), deviceTransform(), QGraphicsScenePrivate::dispatchHoverEvent(), QGraphicsScene::event(), QQuickOverlay::eventFilter(), QGraphicsScenePrivate::filterDescendantEvent(), findActiveFocusControl(), findAttachedParent(), findFurthestFocusScopeAncestor(), formatGraphicsItemHelper(), QGraphicsScenePrivate::gestureEventHandler(), QQuickFlickablePrivate::isInnermostPressDelay(), QQuickPageIndicatorPrivate::itemAt(), QTreeViewPrivate::layout(), QQuickLayout::maybeSubscribeToBaseLineOffsetChanges(), QQuickItemPrivate::nextPrevItemInTabFocusChain(), operator<<(), QQuickControlPrivate::parentFont(), parentWidget(), QQuickItemViewPrivate::releaseItem(), QGraphicsScenePrivate::removeItemHelper(), QDeclarativeGeoMap::removeMapItem_real(), QGraphicsLayoutPrivate::reparentChildItems(), sceneBoundingRect(), QQuickDeliveryAgentPrivate::sendHoverEvent(), QGraphicsScenePrivate::setActivePanelHelper(), QQuickControlPrivate::setContentItem_helper(), stackBefore(), topLevelItem(), QQuickMultiPointTouchArea::touchEvent(), QGraphicsScenePrivate::updateFont(), QGraphicsWidget::updateGeometry(), and QGraphicsScenePrivate::updatePalette().

+ Here is the caller graph for this function:

◆ parentObject()

QGraphicsObject * QGraphicsItem::parentObject ( ) const
Since
4.6

Returns a pointer to the item's parent, cast to a QGraphicsObject. Returns \nullptr if the parent item is not a QGraphicsObject.

See also
parentItem(), childItems()

Definition at line 1682 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::parent.

◆ parentWidget()

QGraphicsWidget * QGraphicsItem::parentWidget ( ) const
Since
4.4

Returns a pointer to the item's parent widget. The item's parent widget is the closest parent item that is a widget.

See also
parentItem(), childItems()

Definition at line 1696 of file qgraphicsitem.cpp.

References parentItem().

Referenced by QGraphicsProxyWidget::event(), QGraphicsWidget::focusNextPrevChild(), QGraphicsWidgetPrivate::naturalWidgetFont(), QGraphicsWidgetPrivate::naturalWidgetPalette(), QGraphicsWidgetPrivate::resolveFont(), QGraphicsWidgetPrivate::resolveLayoutDirection(), QGraphicsItemPrivate::setEnabledHelper(), setFlags(), QGraphicsItemPrivate::setVisibleHelper(), QGraphicsProxyWidgetPrivate::setWidget_helper(), topLevelWidget(), and QGraphicsWidget::updateGeometry().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pos()

QPointF QGraphicsItem::pos ( ) const

Returns the position of the item in parent coordinates.

If the item has no parent, its position is given in scene coordinates.

The position of the item describes its origin (local coordinate (0, 0)) in parent coordinates; this function returns the same as mapToParent(0, 0).

For convenience, you can also call scenePos() to determine the item's position in scene coordinates, regardless of its parent.

See also
x(), y(), setPos(), transform(), {The Graphics View Coordinate System}

Definition at line 3733 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::pos.

Referenced by QGraphicsItemGroup::addToGroup(), QToolBarAreaLayout::apply(), QDockAreaLayoutInfo::findSeparator(), QDockAreaLayoutInfo::fitItems(), QToolBarAreaLayoutLine::fitLayout(), formatGraphicsItemHelper(), QDockAreaLayoutInfo::gapIndex(), QToolBarAreaLayoutInfo::gapIndex(), QToolBarAreaLayoutInfo::itemRect(), QDockAreaLayoutInfo::itemRect(), mouseMoveEvent(), QGraphicsItemGroup::removeFromGroup(), QToolBarAreaLayout::restoreState(), QDockAreaLayoutInfo::restoreState(), QDockAreaLayoutInfo::saveState(), QToolBarAreaLayout::saveState(), QDockAreaLayoutInfo::separatorMove(), QDockAreaLayoutInfo::separatorRect(), QPrintPreviewWidgetPrivate::setCurrentPage(), QGraphicsItemAnimation::setItem(), and QDockAreaLayoutInfo::unplug().

+ Here is the caller graph for this function:

◆ prepareGeometryChange()

void QGraphicsItem::prepareGeometryChange ( )
protected

Prepares the item for a geometry change.

Call this function before changing the bounding rect of an item to keep QGraphicsScene's index up to date.

prepareGeometryChange() will call update() if this is necessary.

Example:

void CircleItem::setRadius(qreal newRadius)
{
if (radius != newRadius) {
prepareGeometryChange();
radius = newRadius;
}
}
See also
boundingRect()

Definition at line 7454 of file qgraphicsitem.cpp.

References boundingRect(), d_ptr, QTransform::dx(), QTransform::dy(), QGraphicsItemPrivate::geometryChanged, QGraphicsItemPrivate::hasTranslateOnlySceneTransform(), QGraphicsItemPrivate::inDestructor, QGraphicsItemPrivate::inSetPosHelper, QTransform::mapRect(), QGraphicsItemPrivate::markParentDirty(), QGraphicsItemPrivate::notifyBoundingRectChanged, QGraphicsItemPrivate::paintedViewBoundingRectsNeedRepaint, QGraphicsItemPrivate::scene, QGraphicsItemPrivate::sceneTransform, and QGraphicsScene::update().

Referenced by QGraphicsTextItemPrivate::_q_updateBoundingRect(), QGraphicsItemGroup::addToGroup(), QGraphicsItemGroup::removeFromGroup(), QGraphicsTransformPrivate::setItem(), QGraphicsLineItem::setLine(), QGraphicsPixmapItem::setOffset(), QGraphicsItemPrivate::setParentItemHelper(), QGraphicsPathItem::setPath(), QAbstractGraphicsShapeItem::setPen(), QGraphicsLineItem::setPen(), QGraphicsPixmapItem::setPixmap(), QGraphicsPolygonItem::setPolygon(), QGraphicsRectItem::setRect(), QGraphicsEllipseItem::setRect(), setRotation(), setScale(), QGraphicsEllipseItem::setSpanAngle(), QGraphicsEllipseItem::setStartAngle(), setTransformations(), QGraphicsItemPrivate::setTransformHelper(), setTransformOriginPoint(), QGraphicsWidget::setWindowFrameMargins(), QGraphicsTextItemPrivate::textControl(), and QGraphicsTransformPrivate::updateItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeFromIndex()

void QGraphicsItem::removeFromIndex ( )
protected

Removes this item from the scene's index. Called in conjunction with addToIndex() to ensure the index bookkeeping is correct when the item's position, transformation or shape changes.

Definition at line 7430 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::AncestorClipsChildren, QGraphicsItemPrivate::AncestorContainsChildren, QGraphicsItemPrivate::ancestorFlags, d_ptr, QGraphicsScene::removeItem(), and QGraphicsItemPrivate::scene.

+ Here is the call graph for this function:

◆ removeSceneEventFilter()

void QGraphicsItem::removeSceneEventFilter ( QGraphicsItem * filterItem)

Removes an event filter on this item from filterItem.

See also
installSceneEventFilter()

Definition at line 6579 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::scene.

◆ resetTransform()

void QGraphicsItem::resetTransform ( )
Since
4.3

Resets this item's transformation matrix to the identity matrix or all the transformation properties to their default values. This is equivalent to calling setTransform(QTransform()).

See also
setTransform(), transform()

Definition at line 4513 of file qgraphicsitem.cpp.

References setTransform().

+ Here is the call graph for this function:

◆ rotation()

qreal QGraphicsItem::rotation ( ) const
Since
4.6

Returns the clockwise rotation, in degrees, around the Z axis. The default value is 0 (i.e., the item is not rotated).

The rotation is combined with the item's scale(), transform() and transformations() to map the item's coordinate system to the parent item.

See also
setRotation(), transformOriginPoint(), {Transformations}

Definition at line 3962 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::TransformData::rotation, and QGraphicsItemPrivate::transformData.

Referenced by QGraphicsItemGroup::addToGroup(), and QGraphicsItemGroup::removeFromGroup().

+ Here is the caller graph for this function:

◆ scale()

qreal QGraphicsItem::scale ( ) const
Since
4.6

Returns the scale factor of the item. The default scale factor is 1.0 (i.e., the item is not scaled).

The scale is combined with the item's rotation(), transform() and transformations() to map the item's coordinate system to the parent item.

See also
setScale(), rotation(), {Transformations}

Definition at line 4030 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::TransformData::scale, and QGraphicsItemPrivate::transformData.

Referenced by QGraphicsItemGroup::addToGroup(), and QGraphicsItemGroup::removeFromGroup().

+ Here is the caller graph for this function:

◆ scene()

QGraphicsScene * QGraphicsItem::scene ( ) const

Returns the current scene for the item, or \nullptr if the item is not stored in a scene.

To add or move an item to a scene, call QGraphicsScene::addItem().

Definition at line 1605 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::scene.

Referenced by QGraphicsScene::addItem(), QMacStyle::event(), mousePressEvent(), mouseReleaseEvent(), QGraphicsScene::removeItem(), QGraphicsScenePrivate::removeItemHelper(), QGraphicsScene::sendEvent(), PressDelayHandler::sendMouseEvent(), QGraphicsScenePrivate::setActivePanelHelper(), QGraphicsScenePrivate::setFocusItemHelper(), QGraphicsItemPrivate::setParentItemHelper(), QGraphicsWidget::setTabOrder(), and QGraphicsWidget::style().

+ Here is the caller graph for this function:

◆ sceneBoundingRect()

QRectF QGraphicsItem::sceneBoundingRect ( ) const

Returns the bounding rect of this item in scene coordinates, by combining sceneTransform() with boundingRect().

See also
boundingRect(), {The Graphics View Coordinate System}

Definition at line 4764 of file qgraphicsitem.cpp.

References boundingRect(), d_ptr, QScopedPointer< T, Cleanup >::data(), QTransform::dx(), QTransform::dy(), QGraphicsItemPrivate::hasTranslateOnlySceneTransform(), QTransform::mapRect(), parentItem(), QGraphicsItemPrivate::pos, QGraphicsItemPrivate::sceneTransform, and QRectF::translate().

Referenced by QPrintPreviewWidgetPrivate::_q_fit(), QGraphicsView::centerOn(), QGraphicsScene::collidingItems(), QGraphicsView::ensureVisible(), ensureVisible(), and QGraphicsScene::itemsBoundingRect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sceneEvent()

bool QGraphicsItem::sceneEvent ( QEvent * event)
protectedvirtual

This virtual function receives events to this item.

Reimplement this function to intercept events before they are dispatched to the specialized event handlers contextMenuEvent(), focusInEvent(), focusOutEvent(), hoverEnterEvent(), hoverMoveEvent(), hoverLeaveEvent(), keyPressEvent(), keyReleaseEvent(), mousePressEvent(), mouseReleaseEvent(), mouseMoveEvent(), and mouseDoubleClickEvent().

Returns true if the event was recognized and handled; otherwise, (e.g., if the event type was not recognized,) false is returned.

event is the intercepted event.

Reimplemented in QGraphicsTextItem, and QGraphicsWidget.

Definition at line 6623 of file qgraphicsitem.cpp.

References Qt::AltModifier, QGraphicsItemPrivate::ancestorFlags, QGraphicsItemPrivate::AncestorHandlesChildEvents, QList< T >::at(), child, QGraphicsItemPrivate::children, contextMenuEvent(), Qt::ControlModifier, d_ptr, QEvent::DragEnter, dragEnterEvent(), QEvent::DragLeave, dragLeaveEvent(), dragMoveEvent(), dropEvent(), QEvent::FocusIn, focusInEvent(), QGraphicsScene::focusNextPrevChild(), QEvent::FocusOut, focusOutEvent(), QEvent::GraphicsSceneContextMenu, QEvent::GraphicsSceneDragEnter, QEvent::GraphicsSceneDragLeave, QEvent::GraphicsSceneDragMove, QEvent::GraphicsSceneDrop, QEvent::GraphicsSceneHoverEnter, QEvent::GraphicsSceneHoverLeave, QEvent::GraphicsSceneHoverMove, QEvent::GraphicsSceneMouseDoubleClick, QEvent::GraphicsSceneMouseMove, QEvent::GraphicsSceneMousePress, QEvent::GraphicsSceneMouseRelease, QEvent::GraphicsSceneWheel, QEvent::HoverEnter, hoverEnterEvent(), QEvent::HoverLeave, hoverLeaveEvent(), hoverMoveEvent(), i, QEvent::InputMethod, inputMethodEvent(), QGraphicsItemPrivate::isWidget, QKeyEvent::key(), Qt::Key_Backtab, Qt::Key_Tab, QEvent::KeyPress, keyPressEvent(), QEvent::KeyRelease, keyReleaseEvent(), QKeyEvent::modifiers(), mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), QGraphicsItemPrivate::parent, Q_ASSERT, QGraphicsItemPrivate::remapItemPos(), QGraphicsItemPrivate::scene, sceneEvent(), QGraphicsScene::sendEvent(), Qt::ShiftModifier, QList< T >::size(), QGraphicsItemPrivate::visible, wheelEvent(), QEvent::WindowActivate, and QEvent::WindowDeactivate.

Referenced by sceneEvent(), QGraphicsTextItem::sceneEvent(), QGraphicsWidget::sceneEvent(), and QGraphicsScenePrivate::sendEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sceneEventFilter()

bool QGraphicsItem::sceneEventFilter ( QGraphicsItem * watched,
QEvent * event )
protectedvirtual

Filters events for the item watched.

event is the filtered event.

Reimplementing this function in a subclass makes it possible for the item to be used as an event filter for other items, intercepting all the events sent to those items before they are able to respond.

Reimplementations must return true to prevent further processing of a given event, ensuring that it will not be delivered to the watched item, or return false to indicate that the event should be propagated further by the event system.

See also
installSceneEventFilter()

Definition at line 6602 of file qgraphicsitem.cpp.

References Q_UNUSED.

◆ scenePos()

QPointF QGraphicsItem::scenePos ( ) const

Returns the item's position in scene coordinates.

This is equivalent to calling mapToScene(0, 0).

See also
pos(), sceneTransform(), {The Graphics View Coordinate System}

Definition at line 3798 of file qgraphicsitem.cpp.

References mapToScene().

Referenced by QGraphicsItemPrivate::sendScenePosChange().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sceneTransform()

QTransform QGraphicsItem::sceneTransform ( ) const
Since
4.3

Returns this item's scene transformation matrix. This matrix can be used to map coordinates and geometrical shapes from this item's local coordinate system to the scene's coordinate system. To map coordinates from the scene, you must first invert the returned matrix.

Example:

rect.setPos(100, 100);
// returns QPointF(100, 100);
// returns QPointF(0, 0);

Unlike transform(), which returns only an item's local transformation, this function includes the item's (and any parents') position, and all the transformation properties.

See also
transform(), setTransform(), scenePos(), {The Graphics View Coordinate System}, {Transformations}

Definition at line 4258 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::ensureSceneTransform(), and QGraphicsItemPrivate::sceneTransform.

Referenced by QGraphicsViewPrivate::mapToViewRect(), mouseMoveEvent(), QGraphicsView::paintEvent(), QGraphicsItemGroup::removeFromGroup(), QGraphicsItemPrivate::sceneEffectiveBoundingRect(), and updateHelper().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ scroll()

void QGraphicsItem::scroll ( qreal dx,
qreal dy,
const QRectF & rect = QRectF() )
Since
4.4 Scrolls the contents of rect by dx, dy. If rect is a null rect (the default), the item's bounding rect is scrolled.

Scrolling provides a fast alternative to simply redrawing when the contents of the item (or parts of the item) are shifted vertically or horizontally. Depending on the current transformation and the capabilities of the paint device (i.e., the viewport), this operation may consist of simply moving pixels from one location to another using memmove(). In most cases this is faster than rerendering the entire area.

After scrolling, the item will issue an update for the newly exposed areas. If scrolling is not supported (e.g., you are rendering to an OpenGL viewport, which does not benefit from scroll optimizations), this function is equivalent to calling update(rect).

{Note:} Scrolling is only supported when QGraphicsItem::ItemCoordinateCache is enabled; in all other cases calling this function is equivalent to calling update(rect). If you for sure know that the item is opaque and not overlapped by other items, you can map the rect to viewport coordinates and scroll the viewport.

QTransform xform = item->deviceTransform(view->viewportTransform());
QRect deviceRect = xform.mapRect(rect).toAlignedRect();
view->viewport()->scroll(dx, dy, deviceRect);
int type() const override
Returns the type of an item as an int.
The QAbstractGraphicsShapeItem class provides a common base for all path items.
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
The QGraphicsEllipseItem class provides an ellipse item that you can add to a QGraphicsScene.
The QGraphicsItemGroup class provides a container that treats a group of items as a single item.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
QTransform deviceTransform(const QTransform &viewportTransform) const
void setData(int key, const QVariant &value)
Sets this item's custom data for the key key to value.
virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
This event handler, for event event, can be reimplemented to receive drag enter events for this item.
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
This virtual function is called by QGraphicsItem to notify custom items that some part of the item's ...
void installSceneEventFilter(QGraphicsItem *filterItem)
Installs an event filter for this item on filterItem, causing all events for this item to first pass ...
void setPos(const QPointF &pos)
Sets the position of the item to pos, which is in parent coordinates.
QVariant data(int key) const
Returns this item's custom data for the key key as a QVariant.
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
This event handler can be reimplemented in a subclass to process context menu events.
QTransform sceneTransform() const
void setCursor(const QCursor &cursor)
Sets the current cursor shape for the item to cursor.
The QGraphicsLineItem class provides a line item that you can add to a QGraphicsScene.
The QGraphicsRectItem class provides a rectangle item that you can add to a QGraphicsScene.
The QGraphicsSceneContextMenuEvent class provides context menu events in the graphics view framework.
The QGraphicsSceneDragDropEvent class provides events for drag and drop in the graphics view framewor...
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
void destroyItemGroup(QGraphicsItemGroup *group)
Reparents all items in group to group's parent item, then removes group from the scene,...
QGraphicsEllipseItem * addEllipse(const QRectF &rect, const QPen &pen=QPen(), const QBrush &brush=QBrush())
Creates and adds an ellipse item to the scene, and returns the item pointer.
QRectF sceneRect
the scene rectangle; the bounding rectangle of the scene
QGraphicsItemGroup * createItemGroup(const QList< QGraphicsItem * > &items)
Groups all items in items into a new QGraphicsItemGroup, and returns a pointer to the group.
QGraphicsLineItem * addLine(const QLineF &line, const QPen &pen=QPen())
Creates and adds a line item to the scene, and returns the item pointer.
QGraphicsItem * itemAt(const QPointF &pos, const QTransform &deviceTransform) const
\inmodule QtCore
Definition qline.h:182
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
QAction * exec()
Executes this menu synchronously.
Definition qmenu.cpp:2613
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3117
\inmodule QtGui
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
\inmodule QtCore\reentrant
Definition qpoint.h:214
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:333
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:338
constexpr void setY(qreal y) noexcept
Sets the y coordinate of this point to the given finite y coordinate.
Definition qpoint.h:348
constexpr void setX(qreal x) noexcept
Sets the x coordinate of this point to the given finite x coordinate.
Definition qpoint.h:343
\inmodule QtCore\reentrant
Definition qrect.h:483
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem.
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
QPoint map(const QPoint &p) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QTransform inverted(bool *invertible=nullptr) const
Returns an inverted copy of this matrix.
QRect mapRect(const QRect &) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
\inmodule QtCore
Definition qvariant.h:65
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
QRectF boundingRect() const override
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
QPainter paint
rect
[4]
@ IBeamCursor
GLboolean GLuint group
GLuint GLenum option
static const QRectF boundingRect(const QPointF *points, int pointCount)
double qreal
Definition qtypes.h:187
QGraphicsScene scene
[0]
QGraphicsRectItem rect
[3]
static const int ObjectName
[10]
QGraphicsEllipseItem * ellipse
QMenu menu
[5]
QQuickView * view
[0]
Definition moc.h:23
See also
boundingRect()

Definition at line 5699 of file qgraphicsitem.cpp.

References boundingRect(), cache, d, QPixmapCache::find(), i, QPixmapCache::insert(), QRect::intersects(), QRectF::intersects(), ItemCoordinateCache, qFuzzyIsNull(), rect, QPixmapCache::remove(), QRegion::translate(), QRectF::translate(), QRect::translated(), and update().

+ Here is the call graph for this function:

◆ setAcceptDrops()

void QGraphicsItem::setAcceptDrops ( bool on)

If on is true, this item will accept drag and drop events; otherwise, it is transparent for drag and drop events.

By default, items do not accept drag and drop events.

See also
acceptDrops()

Definition at line 3061 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::acceptDrops, and d_ptr.

Referenced by QGraphicsTextItem::QGraphicsTextItem(), and QGraphicsTextItem::QGraphicsTextItem().

+ Here is the caller graph for this function:

◆ setAcceptedMouseButtons()

void QGraphicsItem::setAcceptedMouseButtons ( Qt::MouseButtons buttons)

Sets the mouse buttons that this item accepts mouse events for.

By default, all mouse buttons are accepted. If an item accepts a mouse button, it will become the mouse grabber item when a mouse press event is delivered for that button. However, if the item does not accept the mouse button, QGraphicsScene will forward the mouse events to the first item beneath it that does.

To disable mouse events for an item (i.e., make it transparent for mouse events), call setAcceptedMouseButtons(Qt::NoButton).

See also
acceptedMouseButtons(), mousePressEvent()

Definition at line 3097 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::acceptedMouseButtons, d_ptr, QGraphicsScene::mouseGrabberItem(), QGraphicsItemPrivate::scene, and ungrabMouse().

Referenced by QQuickSwipeDelegateAttached::QQuickSwipeDelegateAttached(), and createDimmer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAcceptHoverEvents()

void QGraphicsItem::setAcceptHoverEvents ( bool enabled)
Since
4.4

If enabled is true, this item will accept hover events; otherwise, it will ignore them. By default, items do not accept hover events.

Hover events are delivered when there is no current mouse grabber item. They are sent when the mouse cursor enters an item, when it moves around inside the item, and when the cursor leaves an item. Hover events are commonly used to highlight an item when it's entered, and for tracking the mouse cursor as it hovers over the item (equivalent to QWidget::mouseTracking).

Parent items receive hover enter events before their children, and leave events after their children. The parent does not receive a hover leave event if the cursor enters a child, though; the parent stays "hovered" until the cursor leaves its area, including its children's areas.

If a parent item handles child events, it will receive hover move, drag move, and drop events as the cursor passes through its children, but it does not receive hover enter and hover leave, nor drag enter and drag leave events on behalf of its children.

A QGraphicsWidget with window decorations will accept hover events regardless of the value of acceptHoverEvents().

See also
acceptHoverEvents(), hoverEnterEvent(), hoverMoveEvent(), hoverLeaveEvent()

Definition at line 3154 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::acceptsHover, d_ptr, and QGraphicsItemPrivate::scene.

Referenced by QGraphicsTextItem::QGraphicsTextItem(), QGraphicsTextItem::QGraphicsTextItem(), and createDimmer().

+ Here is the caller graph for this function:

◆ setAcceptTouchEvents()

void QGraphicsItem::setAcceptTouchEvents ( bool enabled)
Since
4.6

If enabled is true, this item will accept \l{QTouchEvent}{touch events}; otherwise, it will ignore them. By default, items do not accept touch events.

Definition at line 3184 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::acceptTouchEvents, d_ptr, and QGraphicsItemPrivate::scene.

◆ setActive()

void QGraphicsItem::setActive ( bool active)
Since
4.6

If active is true, and the scene is active, this item's panel will be activated. Otherwise, the panel is deactivated.

If the item is not part of an active scene, active will decide what happens to the panel when the scene becomes active or the item is added to the scene. If true, the item's panel will be activated when the item is either added to the scene or the scene is activated. Otherwise, the item will stay inactive independent of the scene's activated state.

See also
isPanel(), QGraphicsScene::setActivePanel(), QGraphicsScene::isActive()

Definition at line 3317 of file qgraphicsitem.cpp.

References QGraphicsScene::activePanel(), d_ptr, QGraphicsItemPrivate::explicitActivate, isAncestorOf(), panel(), QGraphicsItemPrivate::parent, QGraphicsItemPrivate::scene, QGraphicsScene::setActivePanel(), and QGraphicsItemPrivate::wantsActive.

+ Here is the call graph for this function:

◆ setBoundingRegionGranularity()

void QGraphicsItem::setBoundingRegionGranularity ( qreal granularity)
Since
4.4 Sets the bounding region granularity to granularity; a value between and including 0 and 1. The default value is 0 (i.e., the lowest granularity, where the bounding region corresponds to the item's bounding rectangle).

The granularity is used by boundingRegion() to calculate how fine the bounding region of the item should be. The highest achievable granularity is 1, where boundingRegion() will return the finest outline possible for the respective device (e.g., for a QGraphicsView viewport, this gives you a pixel-perfect bounding region). The lowest possible granularity is 0. The value of granularity describes the ratio between device resolution and the resolution of the bounding region (e.g., a value of 0.25 will provide a region where each chunk corresponds to 4x4 device units / pixels).

See also
boundingRegionGranularity()

Definition at line 5246 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::ExtraBoundingRegionGranularity, QGraphicsItemPrivate::hasBoundingRegionGranularity, qWarning, QGraphicsItemPrivate::setExtra(), and QGraphicsItemPrivate::unsetExtra().

+ Here is the call graph for this function:

◆ setCacheMode()

void QGraphicsItem::setCacheMode ( CacheMode mode,
const QSize & logicalCacheSize = QSize() )
Since
4.4 Sets the item's cache mode to mode.

The optional logicalCacheSize argument is used only by ItemCoordinateCache mode, and describes the resolution of the cache buffer; if logicalCacheSize is (100, 100), QGraphicsItem will fit the item into 100x100 pixels in graphics memory, regardless of the logical size of the item itself. By default QGraphicsItem uses the size of boundingRect(). For all other cache modes than ItemCoordinateCache, logicalCacheSize is ignored.

Caching can speed up rendering if your item spends a significant time redrawing itself. In some cases the cache can also slow down rendering, in particular when the item spends less time redrawing than QGraphicsItem spends redrawing from the cache.

When caching is enabled, an item's paint() function will generally draw into an offscreen pixmap cache; for any subsequent repaint requests, the Graphics View framework will redraw from the cache. This approach works particularly well with QGLWidget, which stores all the cache as OpenGL textures.

Be aware that QPixmapCache's cache limit may need to be changed to obtain optimal performance.

You can read more about the different cache modes in the CacheMode documentation.

Note
Enabling caching does not imply that the item's paint() function will be called only in response to an explicit update() call. For instance, under memory pressure, Qt may decide to drop some of the cache information; in such cases an item's paint() function will be called even if there was no update() call (that is, exactly as if there were no caching enabled).
See also
CacheMode, QPixmapCache::setCacheLimit()

Definition at line 2091 of file qgraphicsitem.cpp.

References cache, QGraphicsItemPrivate::cacheMode, d_ptr, DeviceCoordinateCache, QGraphicsItemPrivate::extraItemCache(), ItemCoordinateCache, NoCache, QGraphicsItemPrivate::removeExtraItemCache(), and update().

Referenced by QGraphicsSvgItem::setCachingEnabled().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCursor()

void QGraphicsItem::setCursor ( const QCursor & cursor)

Sets the current cursor shape for the item to cursor.

The mouse cursor will assume this shape when it's over this item. See the \l{Qt::CursorShape}{list of predefined cursor objects} for a range of useful shapes.

An editor item might want to use an I-beam cursor:

If no cursor has been set, the cursor of the item beneath is used.

See also
cursor(), hasCursor(), unsetCursor(), QWidget::cursor, QGuiApplication::overrideCursor()

Definition at line 2260 of file qgraphicsitem.cpp.

References boundingRect(), contains(), cursor(), d_ptr, QGraphicsItemPrivate::ExtraCursor, QGraphicsItemPrivate::hasCursor, QMetaObject::invokeMethod(), itemChange(), ItemCursorChange, ItemCursorHasChanged, mapFromScene(), QCursor::pos(), Q_ARG, QGraphicsItemPrivate::scene, QGraphicsItemPrivate::setExtra(), view, and QGraphicsScene::views().

Referenced by createDimmer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setData()

void QGraphicsItem::setData ( int key,
const QVariant & value )

Sets this item's custom data for the key key to value.

Custom item data is useful for storing arbitrary properties for any item. Qt does not use this feature for storing data; it is provided solely for the convenience of the user.

See also
data()

Definition at line 6498 of file qgraphicsitem.cpp.

Referenced by if(), QComboBox::insertItem(), QComboBox::insertItems(), QStandardItemModel::setData(), QComboBox::setItemData(), QComboBox::setItemIcon(), and QComboBox::setItemText().

+ Here is the caller graph for this function:

◆ setEnabled()

void QGraphicsItem::setEnabled ( bool enabled)

If enabled is true, the item is enabled; otherwise, it is disabled.

Disabled items are visible, but they do not receive any events, and cannot take focus nor be selected. Mouse events are discarded; they are not propagated unless the item is also invisible, or if it does not accept mouse events (see acceptedMouseButtons()). A disabled item cannot become the mouse grabber, and as a result of this, an item loses the grab if it becomes disabled when grabbing the mouse, just like it loses focus if it had focus when it was disabled.

Disabled items are traditionally drawn using grayed-out colors (see \l QPalette::Disabled).

If you disable a parent item, all its children will also be disabled. If you enable a parent item, all children will be enabled, unless they have been explicitly disabled (i.e., if you call setEnabled(false) on a child, it will not be re-enabled if its parent is disabled, and then enabled again).

Items are enabled by default.

Note
If you install an event filter, you can still intercept events before they are delivered to items; this mechanism disregards the item's enabled state.
See also
isEnabled()

Definition at line 2692 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::setEnabledHelper().

Referenced by QMenuPrivate::copyActionToPlatformItem(), and QGraphicsProxyWidget::eventFilter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setExtension()

void QGraphicsItem::setExtension ( Extension extension,
const QVariant & variant )
protectedvirtual

Note: This is provided as a hook to avoid future problems related to adding virtual functions.

Reimplemented in QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPolygonItem, QGraphicsLineItem, QGraphicsPixmapItem, QGraphicsTextItem, and QGraphicsSimpleTextItem.

Definition at line 7387 of file qgraphicsitem.cpp.

References extension(), Q_UNUSED, and variant.

+ Here is the call graph for this function:

◆ setFiltersChildEvents()

void QGraphicsItem::setFiltersChildEvents ( bool enabled)
Since
4.6

If enabled is true, this item is set to filter all events for all its children (i.e., all events intended for any of its children are instead sent to this item); otherwise, if enabled is false, this item will only handle its own events. The default value is false.

See also
filtersChildEvents()

Definition at line 3222 of file qgraphicsitem.cpp.

References d_ptr, enabled, QGraphicsItemPrivate::filtersDescendantEvents, and QGraphicsItemPrivate::updateAncestorFlag().

+ Here is the call graph for this function:

◆ setFlag()

void QGraphicsItem::setFlag ( GraphicsItemFlag flag,
bool enabled = true )

If enabled is true, the item flag flag is enabled; otherwise, it is disabled.

See also
flags(), setFlags()

Definition at line 1877 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::flags, and setFlags().

Referenced by QGraphicsTextItem::QGraphicsTextItem(), QGraphicsWidget::setFocusPolicy(), QGraphicsWidget::setWindowFlags(), and setZValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFlags()

void QGraphicsItem::setFlags ( GraphicsItemFlags flags)

Sets the item flags to flags.

All flags in flags are enabled; all flags not in flags are disabled.

If the item had focus and flags does not enable ItemIsFocusable, the item loses focus as a result of calling this function. Similarly, if the item was selected, and flags does not enabled ItemIsSelectable, the item is automatically unselected.

By default, no flags are enabled. (QGraphicsWidget enables the ItemSendsGeometryChanges flag by default in order to track position changes.)

See also
flags(), setFlag()

Definition at line 1900 of file qgraphicsitem.cpp.

References clearFocus(), d_ptr, QGraphicsItemPrivate::dirtyChildrenBoundingRect, flags(), QGraphicsItemPrivate::flags, hasFocus(), isAncestorOf(), isSelected(), QGraphicsItemPrivate::isWidget, ItemAcceptsInputMethod, itemChange(), ItemClipsChildrenToShape, ItemClipsToShape, ItemContainsChildrenInShape, ItemFlagsChange, ItemFlagsHaveChanged, ItemIgnoresTransformations, ItemIsFocusable, ItemIsPanel, ItemIsSelectable, ItemNegativeZStacksBehindParent, ItemSendsScenePositionChanges, ItemStacksBehindParent, QGraphicsItemPrivate::markParentDirty(), QGraphicsItemPrivate::needSortChildren, QGraphicsScene::NoIndex, NonModal, QGraphicsItemPrivate::panelModality, QGraphicsItemPrivate::parent, parentWidget(), QGraphicsItemPrivate::scene, setSelected(), QGraphicsItemPrivate::updateAncestorFlag(), QGraphicsItemPrivate::updatePaintedViewBoundingRects(), and QGraphicsItemPrivate::z.

Referenced by QGraphicsTextItem::QGraphicsTextItem(), setFlag(), QComboBoxDelegate::setSeparator(), and QGraphicsTextItem::setTextInteractionFlags().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFocus()

void QGraphicsItem::setFocus ( Qt::FocusReason focusReason = Qt::OtherFocusReason)

Gives keyboard input focus to this item.

The focusReason argument will be passed into any \l{QFocusEvent}{focus event} generated by this function; it is used to give an explanation of what caused the item to get focus.

Only enabled items that set the ItemIsFocusable flag can accept keyboard focus.

If this item is not visible, not active, or not associated with a scene, it will not gain immediate input focus. However, it will be registered as the preferred focus item for its subtree of items, should it later become visible.

As a result of calling this function, this item will receive a \l{focusInEvent()}{focus in event} with focusReason. If another item already has focus, that item will first receive a \l{focusOutEvent()} {focus out event} indicating that it has lost input focus.

See also
clearFocus(), hasFocus(), focusItem(), focusProxy()

Definition at line 3384 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::setFocusHelper().

Referenced by QGraphicsScene::addItem(), QGraphicsWidget::focusNextPrevChild(), QQuickStackViewPrivate::setCurrentItem(), QGraphicsScene::setFocusItem(), QGraphicsScenePrivate::setFocusItemHelper(), QGraphicsItemPrivate::setParentItemHelper(), and QGraphicsItemPrivate::setVisibleHelper().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFocusProxy()

void QGraphicsItem::setFocusProxy ( QGraphicsItem * item)
Since
4.6

Sets the item's focus proxy to item.

If an item has a focus proxy, the focus proxy will receive input focus when the item gains input focus. The item itself will still have focus (i.e., hasFocus() will return true), but only the focus proxy will receive the keyboard input.

A focus proxy can itself have a focus proxy, and so on. In such case, keyboard input will be handled by the outermost focus proxy.

The focus proxy item must belong to the same scene as this item.

See also
focusProxy(), setFocus(), hasFocus()

Definition at line 3543 of file qgraphicsitem.cpp.

References d_ptr, focusProxy(), QGraphicsItemPrivate::focusProxy, QGraphicsItemPrivate::focusProxyRefs, item, qWarning, QList< T >::removeOne(), and QGraphicsItemPrivate::scene.

Referenced by ~QGraphicsItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setGroup()

void QGraphicsItem::setGroup ( QGraphicsItemGroup * group)

Adds this item to the item group group.

If group is \nullptr, this item is removed from any current group and added as a child of the previous group's parent.

See also
group(), QGraphicsScene::createItemGroup()

Definition at line 1637 of file qgraphicsitem.cpp.

References group(), and QGraphicsItemGroup::removeFromGroup().

Referenced by QQuickLabsPlatformMenuItemGroup::addItem(), QQuickLabsPlatformMenuItemGroup::clear(), and QQuickLabsPlatformMenuItemGroup::removeItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlesChildEvents()

void QGraphicsItem::setHandlesChildEvents ( bool enabled)
Deprecated

If enabled is true, this item is set to handle all events for all its children (i.e., all events intended for any of its children are instead sent to this item); otherwise, if enabled is false, this item will only handle its own events. The default value is false.

This property is useful for item groups; it allows one item to handle events on behalf of its children, as opposed to its children handling their events individually.

If a child item accepts hover events, its parent will receive hover move events as the cursor passes through the child, but it does not receive hover enter and hover leave events on behalf of its child.

See also
handlesChildEvents()

Definition at line 3273 of file qgraphicsitem.cpp.

References d_ptr, enabled, QGraphicsItemPrivate::handlesChildEvents, and QGraphicsItemPrivate::updateAncestorFlag().

Referenced by QGraphicsItemGroup::QGraphicsItemGroup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setInputMethodHints()

void QGraphicsItem::setInputMethodHints ( Qt::InputMethodHints hints)

Sets the current input method hints of this item to hints.

Since
4.6
See also
inputMethodHints(), inputMethodQuery()

Definition at line 7318 of file qgraphicsitem.cpp.

References d, QApplication::focusWidget(), hasFocus(), Qt::ImHints, and QGuiApplication::inputMethod().

+ Here is the call graph for this function:

◆ setOpacity()

void QGraphicsItem::setOpacity ( qreal opacity)
Since
4.5

Sets this item's local opacity, between 0.0 (transparent) and 1.0 (opaque). The item's local opacity is combined with parent and ancestor opacities into the effectiveOpacity().

By default, opacity propagates from parent to child, so if a parent's opacity is 0.5 and the child is also 0.5, the child's effective opacity will be 0.25.

The opacity property decides the state of the painter passed to the paint() function. If the item is cached, i.e., ItemCoordinateCache or DeviceCoordinateCache, the effective property will be applied to the item's cache as it is rendered.

There are two item flags that affect how the item's opacity is combined with the parent: ItemIgnoresParentOpacity and ItemDoesntPropagateOpacityToChildren.

Note
Setting the opacity of an item to 0 will not make the item invisible (according to isVisible()), but the item will be treated like an invisible one. See the documentation of setVisible() for more information.
See also
opacity(), effectiveOpacity(), setVisible()

Definition at line 2837 of file qgraphicsitem.cpp.

References d_ptr, emit, QGraphicsItemPrivate::flags, QGraphicsItemPrivate::isObject, QGraphicsItemPrivate::isOpacityNull(), itemChange(), ItemDoesntPropagateOpacityToChildren, ItemOpacityChange, ItemOpacityHasChanged, opacity(), QGraphicsItemPrivate::opacity, QGraphicsItemPrivate::paintedViewBoundingRectsNeedRepaint, qBound(), and QGraphicsItemPrivate::scene.

Referenced by QQuickItemParticle::prepareNextFrame().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setPanelModality()

void QGraphicsItem::setPanelModality ( PanelModality panelModality)
Since
4.6

Sets the modality for this item to panelModality.

Changing the modality of a visible item takes effect immediately.

Definition at line 2134 of file qgraphicsitem.cpp.

References d_ptr, isPanel(), isVisible(), NonModal, panelModality(), QGraphicsItemPrivate::panelModality, and QGraphicsItemPrivate::scene.

+ Here is the call graph for this function:

◆ setParentItem()

void QGraphicsItem::setParentItem ( QGraphicsItem * newParent)

Sets this item's parent item to newParent.

If this item already has a parent, it is first removed from the previous parent. If newParent is 0, this item will become a top-level item.

Note that this implicitly adds this graphics item to the scene of the parent. You should not \l{QGraphicsScene::addItem()}{add} the item to the scene yourself.

The behavior when calling this function on an item that is an ancestor of newParent is undefined.

See also
parentItem(), childItems()

Definition at line 1789 of file qgraphicsitem.cpp.

References d_ptr, itemChange(), ItemParentChange, QGraphicsItemPrivate::parent, qWarning, and QGraphicsItemPrivate::setParentItemHelper().

Referenced by QGraphicsItem(), QGraphicsItem(), ~QGraphicsItem(), QQuick3DItem2D::addChildItem(), QGraphicsLayoutPrivate::addChildLayoutItem(), QGraphicsScene::addItem(), QDeclarativeGeoMap::addMapItem_real(), QGraphicsItemGroup::addToGroup(), QQuickTextAreaPrivate::attachFlickable(), QQuickMenuBarPrivate::beginCreateItem(), QQuickContainerPrivate::contentData_append(), QQuickMenuPrivate::contentData_append(), QQuickItemViewPrivate::createComponentItem(), QQuickSwipePrivate::createDelegateItem(), createDimmer(), QQuickComboBoxPrivate::createdItem(), QQuickTableViewPrivate::createFxTableItem(), QQuickPathViewPrivate::createHighlight(), QQuickItemViewPrivate::createItem(), QQuickItemPrivate::data_append(), QQuick3DObjectPrivate::data_append(), QQuickItemView::destroyingItem(), QQuickItemGenerator::generateRootNode(), QQuickPathViewPrivate::getItem(), QQuickControlPrivate::hideOldItem(), QQuickItemView::initItem(), QQuickTableViewPrivate::initItemCallback(), QQuickContainerPrivate::insertItem(), QQuickMenuPrivate::insertItem(), qquick3dobject_autoParent(), qquickitem_autoParent(), QQuickItemViewPrivate::releaseItem(), QQuickPathViewPrivate::releaseItem(), QGraphicsItemGroup::removeFromGroup(), QQuickContainerPrivate::removeItem(), QQuickMenuPrivate::removeItem(), QGraphicsScenePrivate::removeItemHelper(), QDeclarativeGeoMap::removeMapItem_real(), QmlJSDebugger::reparentQmlObject(), QQuickSwipe::setBehindItem(), QQuickControlPrivate::setContentItem_helper(), QQuickSwipe::setLeftItem(), QQuickSwipe::setRightItem(), and QQuickControlPrivate::unhideOldItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setPos() [1/2]

void QGraphicsItem::setPos ( const QPointF & pos)

Sets the position of the item to pos, which is in parent coordinates.

For items with no parent, pos is in scene coordinates.

The position of the item describes its origin (local coordinate (0, 0)) in parent coordinates.

See also
pos(), scenePos(), {The Graphics View Coordinate System}

Definition at line 3849 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::flags, QGraphicsItemPrivate::inDestructor, QGraphicsItemPrivate::isWidget, itemChange(), ItemPositionChange, ItemPositionHasChanged, ItemSendsGeometryChanges, ItemSendsScenePositionChanges, pos, QGraphicsItemPrivate::pos, QGraphicsItemPrivate::scenePosDescendants, QGraphicsItemPrivate::sendScenePosChange(), and QGraphicsItemPrivate::setPosHelper().

Referenced by QGraphicsItemGroup::addToGroup(), QPrintPreviewWidgetPrivate::layoutPages(), mouseMoveEvent(), QGraphicsItemGroup::removeFromGroup(), setPos(), QGraphicsItemAnimation::setStep(), setX(), and setY().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setPos() [2/2]

void QGraphicsItem::setPos ( qreal x,
qreal y )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling setPos(QPointF(x, y)).

Definition at line 439 of file qgraphicsitem.h.

References setPos().

+ Here is the call graph for this function:

◆ setRotation()

void QGraphicsItem::setRotation ( qreal angle)
Since
4.6

Sets the clockwise rotation angle, in degrees, around the Z axis. The default value is 0 (i.e., the item is not rotated). Assigning a negative value will rotate the item counter-clockwise. Normally the rotation angle is in the range (-360, 360), but it's also possible to assign values outside of this range (e.g., a rotation of 370 degrees is the same as a rotation of 10 degrees).

The item is rotated around its transform origin point, which by default is (0, 0). You can select a different transformation origin by calling setTransformOriginPoint().

The rotation is combined with the item's scale(), transform() and transformations() to map the item's coordinate system to the parent item.

See also
rotation(), setTransformOriginPoint(), {Transformations}

Definition at line 3988 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::dirtySceneTransform, emit, QGraphicsItemPrivate::flags, QGraphicsItemPrivate::isObject, itemChange(), ItemRotationChange, ItemRotationHasChanged, ItemSendsGeometryChanges, QGraphicsItemPrivate::TransformData::onlyTransform, prepareGeometryChange(), QGraphicsItemPrivate::TransformData::rotation, QGraphicsItemPrivate::transformChanged(), and QGraphicsItemPrivate::transformData.

+ Here is the call graph for this function:

◆ setScale()

void QGraphicsItem::setScale ( qreal factor)
Since
4.6

Sets the scale factor of the item. The default scale factor is 1.0 (i.e., the item is not scaled). A scale factor of 0.0 will collapse the item to a single point. If you provide a negative scale factor, the item will be flipped and mirrored (i.e., rotated 180 degrees).

The item is scaled around its transform origin point, which by default is (0, 0). You can select a different transformation origin by calling setTransformOriginPoint().

The scale is combined with the item's rotation(), transform() and transformations() to map the item's coordinate system to the parent item.

See also
scale(), setTransformOriginPoint(), {Transformations Example}

Definition at line 4054 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::dirtySceneTransform, emit, QGraphicsItemPrivate::flags, QGraphicsItemPrivate::isObject, itemChange(), ItemScaleChange, ItemScaleHasChanged, ItemSendsGeometryChanges, QGraphicsItemPrivate::TransformData::onlyTransform, prepareGeometryChange(), QGraphicsItemPrivate::TransformData::scale, QGraphicsItemPrivate::transformChanged(), and QGraphicsItemPrivate::transformData.

+ Here is the call graph for this function:

◆ setSelected()

void QGraphicsItem::setSelected ( bool selected)

If selected is true and this item is selectable, this item is selected; otherwise, it is unselected.

If the item is in a group, the whole group's selected state is toggled by this function. If the group is selected, all items in the group are also selected, and if the group is not selected, no item in the group is selected.

Only visible, enabled, selectable items can be selected. If selected is true and this item is either invisible or disabled or unselectable, this function does nothing.

By default, items cannot be selected. To enable selection, set the ItemIsSelectable flag.

This function is provided for convenience, allowing individual toggling of the selected state of an item. However, a more common way of selecting items is to call QGraphicsScene::setSelectionArea(), which will call this function for all visible, enabled, and selectable items within a specified area on the scene.

See also
isSelected(), QGraphicsScene::selectedItems()

Definition at line 2737 of file qgraphicsitem.cpp.

References d_ptr, emit, QGraphicsItemPrivate::enabled, QGraphicsItemPrivate::flags, group(), itemChange(), ItemIsSelectable, ItemSelectedChange, ItemSelectedHasChanged, QGraphicsItemPrivate::scene, QGraphicsItemPrivate::selected, QGraphicsScene::selectedItems(), QGraphicsScene::selectionChanged(), update(), and QGraphicsItemPrivate::visible.

Referenced by QGraphicsScene::clearSelection(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), QGraphicsItemPrivate::setEnabledHelper(), setFlags(), QGraphicsScene::setSelectionArea(), and QGraphicsItemPrivate::setVisibleHelper().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTransform()

void QGraphicsItem::setTransform ( const QTransform & matrix,
bool combine = false )
Since
4.3

Sets the item's current transformation matrix to matrix.

If combine is true, then matrix is combined with the current matrix; otherwise, matrix replaces the current matrix. combine is false by default.

To simplify interaction with items using a transformed view, QGraphicsItem provides mapTo... and mapFrom... functions that can translate between items' and the scene's coordinates. For example, you can call mapToScene() to map an item coordinate to a scene coordinate, or mapFromScene() to map from scene coordinates to item coordinates.

The transformation matrix is combined with the item's rotation(), scale() and transformations() into a combined transformation that maps the item's coordinate system to its parent.

See also
transform(), setRotation(), setScale(), setTransformOriginPoint(), {The Graphics View Coordinate System}, {Transformations}

Definition at line 4472 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::flags, itemChange(), ItemSendsGeometryChanges, ItemSendsScenePositionChanges, ItemTransformChange, ItemTransformHasChanged, QGraphicsItemPrivate::scenePosDescendants, QGraphicsItemPrivate::sendScenePosChange(), QGraphicsItemPrivate::setTransformHelper(), QGraphicsItemPrivate::TransformData::transform, and QGraphicsItemPrivate::transformData.

Referenced by QGraphicsItemGroup::addToGroup(), QGraphicsItemGroup::removeFromGroup(), resetTransform(), and QGraphicsItemAnimation::setStep().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTransformations()

void QGraphicsItem::setTransformations ( const QList< QGraphicsTransform * > & transformations)
Since
4.6

Sets a list of graphics transformations (QGraphicsTransform) that currently apply to this item.

If all you want is to rotate or scale an item, you should call setRotation() or setScale() instead. If you want to set an arbitrary transformation on an item, you can call setTransform().

QGraphicsTransform is for applying and controlling a chain of individual transformation operations on an item. It's particularly useful in animations, where each transform operation needs to be interpolated independently, or differently.

The transformations are combined with the item's rotation(), scale() and transform() to map the item's coordinate system to the parent item.

See also
scale(), setTransformOriginPoint(), {Transformations}

Definition at line 4128 of file qgraphicsitem.cpp.

References QList< T >::at(), d_ptr, QGraphicsItemPrivate::dirtySceneTransform, QGraphicsItemPrivate::TransformData::graphicsTransforms, i, QGraphicsItemPrivate::TransformData::onlyTransform, prepareGeometryChange(), QList< T >::size(), transformations(), QGraphicsItemPrivate::transformChanged(), and QGraphicsItemPrivate::transformData.

+ Here is the call graph for this function:

◆ setTransformOriginPoint() [1/2]

void QGraphicsItem::setTransformOriginPoint ( const QPointF & origin)
Since
4.6

Sets the origin point for the transformation in item coordinates.

See also
transformOriginPoint(), {Transformations}

Definition at line 4198 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::dirtySceneTransform, QGraphicsItemPrivate::flags, itemChange(), ItemSendsGeometryChanges, ItemTransformOriginPointChange, ItemTransformOriginPointHasChanged, QGraphicsItemPrivate::TransformData::onlyTransform, prepareGeometryChange(), QGraphicsItemPrivate::transformData, QGraphicsItemPrivate::TransformData::xOrigin, and QGraphicsItemPrivate::TransformData::yOrigin.

+ Here is the call graph for this function:

◆ setTransformOriginPoint() [2/2]

void QGraphicsItem::setTransformOriginPoint ( qreal x,
qreal y )
inline
Since
4.6 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Sets the origin point for the transformation in item coordinates. This is equivalent to calling setTransformOriginPoint(QPointF(x, y)).

See also
setTransformOriginPoint(), {Transformations}

Definition at line 258 of file qgraphicsitem.h.

◆ setVisible()

void QGraphicsItem::setVisible ( bool visible)

If visible is true, the item is made visible.

Otherwise, the item is made invisible. Invisible items are not painted, nor do they receive any events. In particular, mouse events pass right through invisible items, and are delivered to any item that may be behind. Invisible items are also unselectable, they cannot take input focus, and are not detected by QGraphicsScene's item location functions.

If an item becomes invisible while grabbing the mouse, (i.e., while it is receiving mouse events,) it will automatically lose the mouse grab, and the grab is not regained by making the item visible again; it must receive a new mouse press to regain the mouse grab.

Similarly, an invisible item cannot have focus, so if the item has focus when it becomes invisible, it will lose focus, and the focus is not regained by simply making the item visible again.

If you hide a parent item, all its children will also be hidden. If you show a parent item, all children will be shown, unless they have been explicitly hidden (i.e., if you call setVisible(false) on a child, it will not be reshown even if its parent is hidden, and then shown again).

Items are visible by default; it is unnecessary to call setVisible() on a new item.

Note
An item with opacity set to 0 will still be considered visible, although it will be treated like an invisible item: mouse events will pass through it, it will not be included in the items returned by QGraphicsView::items(), and so on. However, the item will retain the focus.
See also
isVisible(), show(), hide(), setOpacity()

Definition at line 2563 of file qgraphicsitem.cpp.

References d_ptr, isPanel(), and QGraphicsItemPrivate::setVisibleHelper().

Referenced by QMenuPrivate::copyActionToPlatformItem(), QGraphicsProxyWidget::eventFilter(), QQuickControlPrivate::hideOldItem(), QQuickTableViewPrivate::layoutTopLeftItem(), QQuickGridViewPrivate::layoutVisibleItems(), QQuickListViewPrivate::layoutVisibleItems(), QQuickItemParticle::prepareNextFrame(), QQuickItemViewPrivate::releaseItem(), and QQuickControlPrivate::unhideOldItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setX()

void QGraphicsItem::setX ( qreal x)
Since
4.6

Set's the x coordinate of the item's position. Equivalent to calling setPos(x, y()).

See also
x(), setPos()

Definition at line 3754 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::inDestructor, QGraphicsItemPrivate::pos, qIsNaN(), setPos(), and QPointF::y().

Referenced by QQuickSplitViewPrivate::layoutPositionItems(), QQuickItemParticle::prepareNextFrame(), QQuickListViewPrivate::repositionPackageItemAt(), and QQuickPathViewPrivate::updateItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setY()

void QGraphicsItem::setY ( qreal y)
Since
4.6

Set's the y coordinate of the item's position. Equivalent to calling setPos(x(), y).

See also
x(), setPos()

Definition at line 3781 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::inDestructor, QGraphicsItemPrivate::pos, qIsNaN(), setPos(), and QPointF::x().

Referenced by layoutItem(), QQuickSplitViewPrivate::layoutPositionItems(), QQuickItemParticle::prepareNextFrame(), QQuickListViewPrivate::repositionPackageItemAt(), QQuickPathViewPrivate::updateItem(), and QQuickTabBarPrivate::updateLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setZValue()

void QGraphicsItem::setZValue ( qreal z)

Sets the Z-value of the item to z.

The Z value decides the stacking order of sibling (neighboring) items. A sibling item of high Z value will always be drawn on top of another sibling item with a lower Z value.

If you restore the Z value, the item's insertion order will decide its stacking order.

The Z-value does not affect the item's size in any way.

The default Z-value is 0.

See also
zValue(), {QGraphicsItem::Sorting}{Sorting}, stackBefore(), ItemStacksBehindParent

Definition at line 4566 of file qgraphicsitem.cpp.

References d_ptr, emit, QGraphicsItemPrivate::flags, QGraphicsItemPrivate::isObject, itemChange(), ItemNegativeZStacksBehindParent, ItemStacksBehindParent, ItemZValueChange, ItemZValueHasChanged, QGraphicsItemPrivate::needSortChildren, QGraphicsScene::NoIndex, QGraphicsItemPrivate::parent, QGraphicsItemPrivate::scene, setFlag(), and QGraphicsItemPrivate::z.

+ Here is the call graph for this function:

◆ shape()

QPainterPath QGraphicsItem::shape ( ) const
virtual

Returns the shape of this item as a QPainterPath in local coordinates.

The shape is used for many things, including collision detection, hit tests, and for the QGraphicsScene::items() functions.

The default implementation calls boundingRect() to return a simple rectangular shape, but subclasses can reimplement this function to return a more accurate shape for non-rectangular items. For example, a round item may choose to return an elliptic shape for better collision detection. For example:

QPainterPath RoundItem::shape() const
{
path.addEllipse(boundingRect());
return path;
}

The outline of a shape can vary depending on the width and style of the pen used when drawing. If you want to include this outline in the item's shape, you can create a shape from the stroke using QPainterPathStroker.

This function is called by the default implementations of contains() and collidesWithPath().

See also
boundingRect(), contains(), prepareGeometryChange(), QPainterPathStroker

Reimplemented in QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPolygonItem, QGraphicsLineItem, QGraphicsPixmapItem, QGraphicsTextItem, QGraphicsSimpleTextItem, and QGraphicsWidget.

Definition at line 4811 of file qgraphicsitem.cpp.

References boundingRect().

Referenced by clipPath(), collidesWithPath(), contains(), QGraphicsView::fitInView(), QAbstractGraphicsShapeItem::opaqueArea(), QGraphicsSceneIndexPrivate::recursive_items_helper(), and setClip().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ show()

void QGraphicsItem::show ( )
inline

Shows the item (items are visible by default).

This convenience function is equivalent to calling setVisible(true).

See also
hide(), setVisible()

Definition at line 174 of file qgraphicsitem.h.

Referenced by QMainWindowLayout::animationFinished(), QStatusBar::hideOrShow(), main(), and doc_src_richtext::wrapper2().

+ Here is the caller graph for this function:

◆ stackBefore()

void QGraphicsItem::stackBefore ( const QGraphicsItem * sibling)
Since
4.6

Stacks this item before sibling, which must be a sibling item (i.e., the two items must share the same parent item, or must both be toplevel items). The sibling must have the same Z value as this item, otherwise calling this function will have no effect.

By default, all sibling items are stacked by insertion order (i.e., the first item you add is drawn before the next item you add). If two items' Z values are different, then the item with the highest Z value is drawn on top. When the Z values are the same, the insertion order will decide the stacking order.

See also
setZValue(), ItemStacksBehindParent, {QGraphicsItem::Sorting}{Sorting}

Definition at line 4653 of file qgraphicsitem.cpp.

References QGraphicsItemPrivate::children, d_ptr, QGraphicsItemPrivate::ensureSequentialSiblingIndex(), i, QGraphicsItemPrivate::parent, parentItem(), qWarning, QGraphicsItemPrivate::scene, QGraphicsItemPrivate::siblingIndex, and QGraphicsItemPrivate::siblingOrderChange().

Referenced by createDimmer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ supportsExtension()

bool QGraphicsItem::supportsExtension ( Extension extension) const
protectedvirtual

Note: This is provided as a hook to avoid future problems related to adding virtual functions.

Reimplemented in QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPolygonItem, QGraphicsLineItem, QGraphicsPixmapItem, QGraphicsTextItem, and QGraphicsSimpleTextItem.

Definition at line 7375 of file qgraphicsitem.cpp.

References extension(), and Q_UNUSED.

+ Here is the call graph for this function:

◆ toGraphicsObject() [1/2]

QGraphicsObject * QGraphicsItem::toGraphicsObject ( )
Since
4.6

Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object, 0 otherwise.

Definition at line 1759 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::isObject.

Referenced by QGraphicsScenePrivate::cancelGesturesForChildren(), QGraphicsScenePrivate::gestureEventHandler(), QGraphicsScenePrivate::gestureTargetsAtHotSpots(), QGraphicsItemPrivate::initStyleOption(), operator<<(), QGraphicsScenePrivate::removeItemHelper(), and QGraphicsScenePrivate::sendEvent().

+ Here is the caller graph for this function:

◆ toGraphicsObject() [2/2]

const QGraphicsObject * QGraphicsItem::toGraphicsObject ( ) const
Since
4.6

Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object, 0 otherwise.

Definition at line 1770 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::isObject.

◆ topLevelItem()

QGraphicsItem * QGraphicsItem::topLevelItem ( ) const

Returns this item's top-level item.

The top-level item is the item's topmost ancestor item whose parent is \nullptr. If an item has no parent, its own pointer is returned (i.e., a top-level item is its own top-level item).

See also
parentItem()

Definition at line 1666 of file qgraphicsitem.cpp.

References parentItem().

Referenced by QGraphicsSceneBspTreeIndexPrivate::estimateItems(), and QGraphicsSceneBspTree::items().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ topLevelWidget()

QGraphicsWidget * QGraphicsItem::topLevelWidget ( ) const
Since
4.4

Returns a pointer to the item's top level widget (i.e., the item's ancestor whose parent is \nullptr, or whose parent is not a widget), or \nullptr if this item does not have a top level widget. If the item is its own top level widget, this function returns a pointer to the item itself.

Definition at line 1713 of file qgraphicsitem.cpp.

References isWidget(), parentWidget(), and topLevelWidget().

Referenced by topLevelWidget().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ transform()

QTransform QGraphicsItem::transform ( ) const
Since
4.3

Returns this item's transformation matrix.

The transformation matrix is combined with the item's rotation(), scale() and transformations() into a combined transformations for the item.

The default transformation matrix is an identity matrix.

See also
setTransform(), sceneTransform()

Definition at line 3944 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::TransformData::transform, and QGraphicsItemPrivate::transformData.

◆ transformations()

QList< QGraphicsTransform * > QGraphicsItem::transformations ( ) const
Since
4.6

Returns a list of graphics transforms that currently apply to this item.

QGraphicsTransform is for applying and controlling a chain of individual transformation operations on an item. It's particularly useful in animations, where each transform operation needs to be interpolated independently, or differently.

The transformations are combined with the item's rotation(), scale() and transform() to map the item's coordinate system to the parent item.

See also
scale(), rotation(), transformOriginPoint(), {Transformations}

Definition at line 4101 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::TransformData::graphicsTransforms, and QGraphicsItemPrivate::transformData.

Referenced by QGraphicsItemGroup::addToGroup(), QGraphicsItemGroup::removeFromGroup(), and setTransformations().

+ Here is the caller graph for this function:

◆ transformOriginPoint()

QPointF QGraphicsItem::transformOriginPoint ( ) const
Since
4.6

Returns the origin point for the transformation in item coordinates.

The default is QPointF(0,0).

See also
setTransformOriginPoint(), {Transformations}

Definition at line 4184 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::transformData, QGraphicsItemPrivate::TransformData::xOrigin, and QGraphicsItemPrivate::TransformData::yOrigin.

Referenced by QGraphicsItemGroup::addToGroup(), QGraphicsItemGroup::removeFromGroup(), and QQuickWindowPrivate::updateDirtyNode().

+ Here is the caller graph for this function:

◆ type()

int QGraphicsItem::type ( ) const
virtual

Returns the type of an item as an int.

All standard graphicsitem classes are associated with a unique value; see QGraphicsItem::Type. This type information is used by qgraphicsitem_cast() to distinguish between types.

The default implementation (in QGraphicsItem) returns UserType.

To enable use of qgraphicsitem_cast() with a custom item, reimplement this function and declare a Type enum value equal to your custom item's type. Custom items must return a value larger than or equal to UserType (65536).

For example:

class CustomItem : public QGraphicsItem
{
public:
enum { Type = UserType + 1 };
int type() const override
{
// Enable the use of qgraphicsitem_cast with this item.
return Type;
}
...
};
See also
UserType

Reimplemented in CustomItem, QGraphicsPathItem, CustomItem, QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPolygonItem, QGraphicsLineItem, QGraphicsPixmapItem, QGraphicsTextItem, QGraphicsSimpleTextItem, QGraphicsItemGroup, QGraphicsProxyWidget, QGraphicsWidget, and QGraphicsSvgItem.

Definition at line 6535 of file qgraphicsitem.cpp.

References UserType.

Referenced by QTextEngine::calculateTabWidth(), QMacStyle::event(), qgraphicsitem_cast(), qgraphicsitem_cast(), qt_graphicsItem_highlightSelected(), and QFFmpeg::streamSideData().

+ Here is the caller graph for this function:

◆ ungrabKeyboard()

void QGraphicsItem::ungrabKeyboard ( )
Since
4.4 Releases the keyboard grab.
See also
grabKeyboard(), ungrabMouse()

Definition at line 3711 of file qgraphicsitem.cpp.

References d_ptr, qWarning, and QGraphicsItemPrivate::scene.

◆ ungrabMouse()

void QGraphicsItem::ungrabMouse ( )
Since
4.4 Releases the mouse grab.
See also
grabMouse(), ungrabKeyboard()

Definition at line 3649 of file qgraphicsitem.cpp.

References d_ptr, qWarning, and QGraphicsItemPrivate::scene.

Referenced by QGraphicsScenePrivate::clearMouseGrabber(), QGraphicsScenePrivate::grabMouse(), setAcceptedMouseButtons(), and QGraphicsItemPrivate::setEnabledHelper().

+ Here is the caller graph for this function:

◆ unsetCursor()

void QGraphicsItem::unsetCursor ( )

Clears the cursor from this item.

See also
hasCursor(), setCursor()

Definition at line 2310 of file qgraphicsitem.cpp.

References d_ptr, QGraphicsItemPrivate::ExtraCursor, QGraphicsItemPrivate::hasCursor, QMetaObject::invokeMethod(), QCursor::pos(), QGraphicsItemPrivate::scene, QGraphicsItemPrivate::unsetExtra(), view, and QGraphicsScene::views().

+ Here is the call graph for this function:

◆ update() [1/2]

void QGraphicsItem::update ( const QRectF & rect = QRectF())

Schedules a redraw of the area covered by rect in this item.

You can call this function whenever your item needs to be redrawn, such as if it changes appearance or size.

This function does not cause an immediate paint; instead it schedules a paint request that is processed by QGraphicsView after control reaches the event loop. The item will only be redrawn if it is visible in any associated view.

As a side effect of the item being repainted, other items that overlap the area rect may also be repainted.

If the item is invisible (i.e., isVisible() returns false), this function does nothing.

See also
paint(), boundingRect()

Definition at line 5642 of file qgraphicsitem.cpp.

References cache, QGraphicsItemPrivate::cacheMode, d_ptr, QGraphicsItemPrivate::extraItemCache(), QGraphicsItemPrivate::fullUpdatePending, NoCache, rect, and QGraphicsItemPrivate::scene.

Referenced by QGraphicsTextItemPrivate::_q_update(), QGraphicsTextItemPrivate::_q_updateBoundingRect(), QGraphicsItemGroup::addToGroup(), QGraphicsWidget::changeEvent(), QGraphicsObject::event(), QGraphicsWidget::event(), focusInEvent(), QGraphicsTextItem::focusInEvent(), QGraphicsWidget::focusInEvent(), focusOutEvent(), QGraphicsTextItem::focusOutEvent(), QGraphicsWidget::focusOutEvent(), forceUpdate(), hoverEnterEvent(), hoverLeaveEvent(), scroll(), QGraphicsWidget::setAutoFillBackground(), QAbstractGraphicsShapeItem::setBrush(), setCacheMode(), QGraphicsTextItem::setDefaultTextColor(), QGraphicsSvgItem::setElementId(), QGraphicsItemPrivate::setEnabledHelper(), QGraphicsPolygonItem::setFillRule(), QGraphicsLineItem::setLine(), QGraphicsSvgItem::setMaximumCacheSize(), QGraphicsPixmapItem::setOffset(), QGraphicsPathItem::setPath(), QAbstractGraphicsShapeItem::setPen(), QGraphicsLineItem::setPen(), QGraphicsPixmapItem::setPixmap(), QGraphicsPolygonItem::setPolygon(), QGraphicsRectItem::setRect(), QGraphicsEllipseItem::setRect(), setSelected(), QGraphicsSvgItem::setSharedRenderer(), QGraphicsEllipseItem::setSpanAngle(), QGraphicsEllipseItem::setStartAngle(), QGraphicsSimpleTextItem::setText(), QGraphicsPixmapItem::setTransformationMode(), QGraphicsTextItemPrivate::textControl(), and update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update() [2/2]

void QGraphicsItem::update ( qreal x,
qreal y,
qreal width,
qreal height )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling update(QRectF(x, y, width, height)).

Definition at line 443 of file qgraphicsitem.h.

References update().

+ Here is the call graph for this function:

◆ updateMicroFocus()

void QGraphicsItem::updateMicroFocus ( )
protected

Updates the item's micro focus.

Since
4.7
See also
QInputMethod

Definition at line 7338 of file qgraphicsitem.cpp.

Referenced by QGraphicsObject::updateMicroFocus().

+ Here is the caller graph for this function:

◆ wheelEvent()

void QGraphicsItem::wheelEvent ( QGraphicsSceneWheelEvent * event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive wheel events for this item.

If you reimplement this function, event will be accepted by default.

If you ignore the event, (i.e., by calling QEvent::ignore(),) it will propagate to any item beneath this item. If no items accept the event, it will be ignored by the scene, and propagate to the view (e.g., the view's vertical scroll bar).

The default implementation ignores the event.

See also
sceneEvent()

Definition at line 7259 of file qgraphicsitem.cpp.

Referenced by sceneEvent().

+ Here is the caller graph for this function:

◆ window()

QGraphicsWidget * QGraphicsItem::window ( ) const
Since
4.4

Returns the item's window, or \nullptr if this item does not have a window. If the item is a window, it will return itself. Otherwise it will return the closest ancestor that is a window.

See also
QGraphicsWidget::isWindow()

Definition at line 1729 of file qgraphicsitem.cpp.

References panel().

Referenced by QQuickAnimatorProxyJob::QQuickAnimatorProxyJob(), QQuickApplicationWindowAttached::QQuickApplicationWindowAttached(), QQuickGraphicsInfo::QQuickGraphicsInfo(), QQuickMaterialBusyIndicatorNode::QQuickMaterialBusyIndicatorNode(), QQuickOverlayAttached::QQuickOverlayAttached(), QQuickControlPrivate::calcLocale(), QQuickItemPrivate::canAcceptTabFocus(), QQuickStackView::childMouseEventFilter(), QQuickDeliveryAgentPrivate::deliverTouchAsMouse(), QQuickShapeGenericRenderer::endSync(), findAttachedParent(), QQuickLabsPlatformDialog::findParentWindow(), QQuickLabsPlatformMenuBar::findWindow(), QQuickLabsPlatformMenu::findWindow(), QQuickItemPrivate::focusNextPrev(), QuickTestResult::grabImage(), QQuickDeliveryAgentPrivate::handleWindowDeactivate(), QGraphicsWidget::initStyleOption(), isBlockedByPopup(), QQuickItem::mapFromItem(), QQuickItem::mapToItem(), QQuickShortcutContext::matcher(), QGraphicsScenePrivate::mousePressEventHandler(), QQuickItemPrivate::nextPrevItemInTabFocusChain(), QGraphicsWidget::paintWindowFrame(), QQuickControlPrivate::parentFont(), qQuickShortcutContextMatcher(), QQuickTableViewPrivate::releaseItem(), QDockAreaLayoutInfo::saveState(), QQuickMaterialProgressBarNode::sync(), QQuickUniversalProgressBarNode::sync(), QQuickDesignerSupport::updateDirtyNode(), and QuickTestResult::waitForRendering().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ x()

QGraphicsItem::x ( ) const
inline

This convenience function is equivalent to calling pos().x().

See also
y()

Definition at line 228 of file qgraphicsitem.h.

References pos.

Referenced by QGraphicsItemGroup::addToGroup(), QPainter::drawStaticText(), QuickTestResult::grabImage(), QQuickBasePositioner::PositionedItem::itemX(), QQuickVisualTestUtils::mapToWindow(), QStatusBarPrivate::messageRect(), QGraphicsItemGroup::removeFromGroup(), QQuickGridViewPrivate::repositionPackageItemAt(), QQuickListViewPrivate::repositionPackageItemAt(), and QDockAreaLayoutInfo::saveState().

+ Here is the caller graph for this function:

◆ y()

QGraphicsItem::y ( ) const
inline

This convenience function is equivalent to calling pos().y().

See also
x()

Definition at line 230 of file qgraphicsitem.h.

References pos.

Referenced by QGraphicsItemGroup::addToGroup(), QuickTestResult::grabImage(), QQuickBasePositioner::PositionedItem::itemY(), QGraphicsItemGroup::removeFromGroup(), QQuickGridViewPrivate::repositionPackageItemAt(), and QQuickListViewPrivate::repositionPackageItemAt().

+ Here is the caller graph for this function:

◆ zValue()

qreal QGraphicsItem::zValue ( ) const

Returns the Z-value of the item.

The Z-value affects the stacking order of sibling (neighboring) items.

The default Z-value is 0.

See also
setZValue(), {QGraphicsItem::Sorting}{Sorting}, stackBefore(), ItemStacksBehindParent

Definition at line 4547 of file qgraphicsitem.cpp.

References d_ptr, and QGraphicsItemPrivate::z.

Referenced by formatGraphicsItemHelper().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ ::tst_QGraphicsItem

friend class ::tst_QGraphicsItem
friend

Definition at line 429 of file qgraphicsitem.h.

◆ QGestureManager

friend class QGestureManager
friend

Definition at line 427 of file qgraphicsitem.h.

◆ qgraphicsitem_cast()

template< class T > qgraphicsitem_cast ( QGraphicsItem * item)
related
Since
4.2

Returns the given item cast to type T if item is of type T; otherwise, \nullptr is returned.

Note
To make this function work correctly with custom items, reimplement the \l{QGraphicsItem::}{type()} function for each custom QGraphicsItem subclass.
See also
QGraphicsItem::type(), QGraphicsItem::UserType

Definition at line 969 of file qgraphicsitem.h.

References item, Type, and type().

+ Here is the call graph for this function:

◆ QGraphicsItemEffectSourcePrivate

friend class QGraphicsItemEffectSourcePrivate
friend

Definition at line 424 of file qgraphicsitem.h.

◆ QGraphicsItemGroup

friend class QGraphicsItemGroup
friend

Definition at line 409 of file qgraphicsitem.h.

◆ QGraphicsObject

friend class QGraphicsObject
friend

Definition at line 416 of file qgraphicsitem.h.

◆ QGraphicsProxyWidgetPrivate

friend class QGraphicsProxyWidgetPrivate
friend

Definition at line 419 of file qgraphicsitem.h.

◆ QGraphicsScene

friend class QGraphicsScene
friend

Definition at line 410 of file qgraphicsitem.h.

◆ QGraphicsSceneBspTree

friend class QGraphicsSceneBspTree
friend

Definition at line 413 of file qgraphicsitem.h.

◆ QGraphicsSceneBspTreeIndex

friend class QGraphicsSceneBspTreeIndex
friend

Definition at line 422 of file qgraphicsitem.h.

◆ QGraphicsSceneBspTreeIndexPrivate

friend class QGraphicsSceneBspTreeIndexPrivate
friend

Definition at line 423 of file qgraphicsitem.h.

◆ QGraphicsSceneFindItemBspTreeVisitor

friend class QGraphicsSceneFindItemBspTreeVisitor
friend

Definition at line 412 of file qgraphicsitem.h.

◆ QGraphicsSceneIndex

friend class QGraphicsSceneIndex
friend

Definition at line 420 of file qgraphicsitem.h.

◆ QGraphicsSceneIndexPrivate

friend class QGraphicsSceneIndexPrivate
friend

Definition at line 421 of file qgraphicsitem.h.

◆ QGraphicsScenePrivate

friend class QGraphicsScenePrivate
friend

Definition at line 411 of file qgraphicsitem.h.

◆ QGraphicsTransformPrivate

friend class QGraphicsTransformPrivate
friend

Definition at line 425 of file qgraphicsitem.h.

◆ QGraphicsView

friend class QGraphicsView
friend

Definition at line 414 of file qgraphicsitem.h.

◆ QGraphicsViewPrivate

friend class QGraphicsViewPrivate
friend

Definition at line 415 of file qgraphicsitem.h.

◆ QGraphicsWidget

friend class QGraphicsWidget
friend

Definition at line 417 of file qgraphicsitem.h.

◆ QGraphicsWidgetPrivate

friend class QGraphicsWidgetPrivate
friend

Definition at line 418 of file qgraphicsitem.h.

◆ qt_closestItemFirst

bool qt_closestItemFirst ( const QGraphicsItem * item1,
const QGraphicsItem * item2 )
friend

Returns true if item1 is on top of item2.

The items don't need to be siblings.

Definition at line 560 of file qgraphicsitem_p.h.

Referenced by isObscuredBy().

◆ qt_closestLeaf

bool qt_closestLeaf ( const QGraphicsItem * item1,
const QGraphicsItem * item2 )
friend

Definition at line 622 of file qgraphicsitem_p.h.

Member Data Documentation

◆ d_ptr

QScopedPointer<QGraphicsItemPrivate> QGraphicsItem::d_ptr
protected

Definition at line 400 of file qgraphicsitem.h.

Referenced by QGraphicsItem(), QGraphicsItem(), QGraphicsObject::QGraphicsObject(), ~QGraphicsItem(), QGraphicsSceneBspTreeIndex::~QGraphicsSceneBspTreeIndex(), QGraphicsScenePrivate::_q_polishItems(), QGraphicsSceneBspTreeIndexPrivate::_q_updateIndex(), QGraphicsScenePrivate::_q_updateScenePosDescendants(), QGraphicsSceneBspTreeIndexPrivate::_q_updateSortCache(), acceptDrops(), acceptedMouseButtons(), acceptHoverEvents(), acceptTouchEvents(), QGraphicsScene::addItem(), QGraphicsSceneBspTreeIndexPrivate::addItem(), addToIndex(), boundingRegionGranularity(), cacheMode(), QGraphicsItemPrivate::calcEffectiveOpacity(), childItems(), childrenBoundingRect(), QGraphicsSceneBspTreeIndex::clear(), clearFocus(), QGraphicsItemPrivate::clearFocusHelper(), QGraphicsItemPrivate::clearSubFocus(), QGraphicsSceneBspTreeIndexPrivate::climbTree(), clipPath(), collidesWithItem(), collidesWithPath(), collidingItems(), commonAncestorItem(), QGraphicsScene::contextMenuEvent(), cursor(), deviceTransform(), QGraphicsScenePrivate::draw(), QGraphicsScenePrivate::drawItemHelper(), QGraphicsScene::drawItems(), QGraphicsScenePrivate::drawSubtreeRecursive(), effectiveOpacity(), QGraphicsItemPrivate::ensureSceneTransformRecursive(), QGraphicsItemPrivate::ensureSortedChildren(), ensureVisible(), QGraphicsSceneBspTreeIndexPrivate::estimateItems(), QGraphicsScenePrivate::filterDescendantEvent(), filtersChildEvents(), QGraphicsView::fitInView(), flags(), focusItem(), focusProxy(), focusScopeItem(), QGraphicsItemPrivate::get(), QGraphicsItemPrivate::get(), grabKeyboard(), grabMouse(), group(), handlesChildEvents(), hasCursor(), hasFocus(), installSceneEventFilter(), QGraphicsItemPrivate::invalidateDepthRecursively(), isActive(), isAncestorOf(), isBlockedByModalPanel(), isEnabled(), isPanel(), isSelected(), isVisible(), isVisibleTo(), isWidget(), isWindow(), QGraphicsScenePrivate::itemAcceptsHoverEvents_helper(), QGraphicsSceneBspTreeIndex::itemChange(), QGraphicsSceneBspTree::items(), itemTransform(), mapFromParent(), mapFromParent(), mapFromParent(), mapFromParent(), mapFromScene(), mapFromScene(), mapFromScene(), mapFromScene(), mapRectFromParent(), mapRectFromScene(), mapRectToParent(), mapRectToScene(), mapToParent(), mapToParent(), mapToParent(), mapToParent(), mapToScene(), mapToScene(), mapToScene(), mapToScene(), QGraphicsViewPrivate::mapToViewRect(), QGraphicsScenePrivate::markDirty(), QGraphicsSvgItem::maximumCacheSize(), QStandardItemModel::mimeData(), mouseMoveEvent(), mousePressEvent(), QGraphicsTextItem::mousePressEvent(), QGraphicsScenePrivate::mousePressEventHandler(), mouseReleaseEvent(), QGraphicsItemPrivate::movableAncestorIsSelected(), opacity(), QGraphicsView::paintEvent(), panel(), panelModality(), parentItem(), parentObject(), pos(), QGraphicsSceneBspTreeIndex::prepareBoundingRectChange(), prepareGeometryChange(), QGraphicsScenePrivate::processDirtyItemsRecursive(), QGraphicsSceneIndexPrivate::recursive_items_helper(), QGraphicsScenePrivate::registerTopLevelItem(), QGraphicsItemGroup::removeFromGroup(), removeFromIndex(), QGraphicsSceneBspTreeIndexPrivate::removeItem(), QGraphicsScenePrivate::removeItemHelper(), removeSceneEventFilter(), QGraphicsScenePrivate::resetDirtyItem(), QGraphicsSceneBspTreeIndexPrivate::resetIndex(), QGraphicsItemPrivate::resolveDepth(), rotation(), scale(), scene(), sceneBoundingRect(), QGraphicsItemPrivate::sceneEffectiveBoundingRect(), sceneEvent(), sceneTransform(), QGraphicsScenePrivate::sendDragDropEvent(), QGraphicsScenePrivate::sendHoverEvent(), QGraphicsScenePrivate::sendMouseEvent(), QGraphicsScenePrivate::sendTouchBeginEvent(), setAcceptDrops(), setAcceptedMouseButtons(), setAcceptHoverEvents(), setAcceptTouchEvents(), setActive(), setBoundingRegionGranularity(), setCacheMode(), setCursor(), setEnabled(), setFiltersChildEvents(), setFlag(), setFlags(), setFocus(), QGraphicsItemPrivate::setFocusHelper(), setFocusProxy(), setHandlesChildEvents(), QGraphicsTransformPrivate::setItem(), QGraphicsSvgItem::setMaximumCacheSize(), setOpacity(), setPanelModality(), setParentItem(), QGraphicsItemPrivate::setParentItemHelper(), setPos(), setRotation(), setScale(), QGraphicsScenePrivate::setScenePosItemEnabled(), setSelected(), QGraphicsItemPrivate::setSubFocus(), setTransform(), setTransformations(), setTransformOriginPoint(), QGraphicsViewPrivate::setUpdateClip(), setVisible(), QGraphicsItemPrivate::setVisibleHelper(), setX(), setY(), setZValue(), stackBefore(), QGraphicsScenePrivate::storeMouseButtonsForMouseGrabber(), toGraphicsObject(), toGraphicsObject(), QGraphicsScenePrivate::touchEventHandler(), transform(), transformations(), transformOriginPoint(), QGraphicsScenePrivate::ungrabGesture(), ungrabKeyboard(), ungrabMouse(), QGraphicsScenePrivate::unregisterTopLevelItem(), unsetCursor(), update(), QGraphicsItemPrivate::updateAncestorFlag(), QGraphicsItemPrivate::updateAncestorFlags(), QGraphicsItemPrivate::updateChildWithGraphicsEffectFlagRecursively(), QGraphicsScenePrivate::updateFont(), QGraphicsWidgetPrivate::updateFont(), QGraphicsViewPrivate::updateInputMethodSensitivity(), QGraphicsTransformPrivate::updateItem(), QGraphicsItemPrivate::updatePaintedViewBoundingRects(), QGraphicsScenePrivate::updatePalette(), QGraphicsWidgetPrivate::updatePalette(), QGraphicsItemPrivate::updateSceneTransformFromParent(), QGraphicsScenePrivate::updateTouchPointsForItem(), QGraphicsScene::wheelEvent(), and zValue().


The documentation for this class was generated from the following files: