Qt 4.8
Public Types | Public Functions | Protected Types | Protected Functions | Protected Variables | Friends | Related Functions | List of all members
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:
QAbstractGraphicsShapeItem QDeclarativeItemAccessor QGraphicsItemGroup QGraphicsLineItem QGraphicsObject QGraphicsPixmapItem QGraphicsEllipseItem QGraphicsPathItem QGraphicsPolygonItem QGraphicsRectItem QGraphicsSimpleTextItem QDeclarativeItem QGraphicsSvgItem QGraphicsTextItem QGraphicsWidget QmlJSDebugger::LiveLayerItem

Public Types

enum  { Type = 1, UserType = 65536 }
 
enum  CacheMode { NoCache, ItemCoordinateCache, DeviceCoordinateCache }
 This enum describes QGraphicsItem's cache modes. More...
 
enum  GraphicsItemChange {
  ItemPositionChange, ItemMatrixChange, 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
}
 This enum describes the state changes that are notified by QGraphicsItem::itemChange(). More...
 
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
}
 This enum describes different flags that you can set on an item to toggle different features in the item's behavior. More...
 
enum  PanelModality { NonModal, PanelModal, SceneModal }
 This enum specifies the behavior of a modal panel. More...
 

Public Functions

bool acceptDrops () const
 Returns true if this item can accept drag and drop events; otherwise, returns false. More...
 
Qt::MouseButtons acceptedMouseButtons () const
 Returns the mouse buttons that this item accepts mouse events for. More...
 
bool acceptHoverEvents () const
 Returns true if an item accepts hover events (QGraphicsSceneHoverEvent); otherwise, returns false. More...
 
bool acceptsHoverEvents () const
 Call acceptHoverEvents() instead. More...
 
bool acceptTouchEvents () const
 Returns true if an item accepts touch events; otherwise, returns false. More...
 
virtual void advance (int phase)
 This virtual function is called twice for all items by the QGraphicsScene::advance() slot. More...
 
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. More...
 
QRegion boundingRegion (const QTransform &itemToDeviceTransform) const
 Returns the bounding region for this item. More...
 
qreal boundingRegionGranularity () const
 Returns the item's bounding region granularity; a value between and including 0 and 1. More...
 
CacheMode cacheMode () const
 Returns the cache mode for this item. More...
 
QList< QGraphicsItem * > childItems () const
 Returns a list of this item's children. More...
 
QList< QGraphicsItem * > children () const
 Use childItems() instead. More...
 
QRectF childrenBoundingRect () const
 Returns the bounding rect of this item's descendants (i.e., its children, their children, etc.) in local coordinates. More...
 
void clearFocus ()
 Takes keyboard input focus from the item. More...
 
QPainterPath clipPath () const
 Returns this item's clip path, or an empty QPainterPath if this item is not clipped. More...
 
virtual bool collidesWithItem (const QGraphicsItem *other, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 Returns true if this item collides with other; otherwise returns false. More...
 
virtual bool collidesWithPath (const QPainterPath &path, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 Returns true if this item collides with path. More...
 
QList< QGraphicsItem * > collidingItems (Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 Returns a list of all items that collide with this item. More...
 
QGraphicsItemcommonAncestorItem (const QGraphicsItem *other) const
 Returns the closest common ancestor item of this item and other, or 0 if either other is 0, or there is no common ancestor. More...
 
virtual bool contains (const QPointF &point) const
 Returns true if this item contains point, which is in local coordinates; otherwise, false is returned. More...
 
QCursor cursor () const
 Returns the current cursor shape for the item. More...
 
QVariant data (int key) const
 Returns this item's custom data for the key key as a QVariant. More...
 
QTransform deviceTransform (const QTransform &viewportTransform) const
 Returns this item's device transformation matrix, using viewportTransform to map from scene to device coordinates. More...
 
qreal effectiveOpacity () const
 Returns this item's effective opacity, which is between 0. More...
 
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. More...
 
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): More...
 
bool filtersChildEvents () const
 Returns true if this item filters child events (i. More...
 
GraphicsItemFlags flags () const
 Returns this item's flags. More...
 
QGraphicsItemfocusItem () const
 If this item, a child or descendant of this item currently has input focus, this function will return a pointer to that item. More...
 
QGraphicsItemfocusProxy () const
 Returns this item's focus proxy, or 0 if this item has no focus proxy. More...
 
QGraphicsItemfocusScopeItem () const
 Returns this item's focus scope item. More...
 
void grabKeyboard ()
 Grabs the keyboard input. More...
 
void grabMouse ()
 Grabs the mouse input. More...
 
QGraphicsEffectgraphicsEffect () const
 Returns a pointer to this item's effect if it has one; otherwise 0. More...
 
QGraphicsItemGroupgroup () const
 Returns a pointer to this item's item group, or 0 if this item is not member of a group. More...
 
bool handlesChildEvents () const
 Returns true if this item handles child events (i. More...
 
bool hasCursor () const
 Returns true if this item has a cursor set; otherwise, false is returned. More...
 
bool hasFocus () const
 Returns true if this item is active, and it or its focus proxy has keyboard input focus; otherwise, returns false. More...
 
void hide ()
 Hides the item. More...
 
Qt::InputMethodHints inputMethodHints () const
 Returns the current input method hints of this item. More...
 
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. More...
 
bool isActive () const
 Returns true if this item is active; otherwise returns false. More...
 
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). More...
 
bool isBlockedByModalPanel (QGraphicsItem **blockingPanel=0) const
 Returns true if this item is blocked by a modal panel, false otherwise. More...
 
bool isClipped () const
 Returns true if this item is clipped. More...
 
bool isEnabled () const
 Returns true if the item is enabled; otherwise, false is returned. More...
 
bool isObscured () const
 Returns true if this item's bounding 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). More...
 
bool isObscured (const QRectF &rect) const
 Returns true if rect is completely obscured by the opaque shape of any of colliding items above it (i. More...
 
bool isObscured (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling isObscured(QRectF(x, y, w, h)). More...
 
virtual bool isObscuredBy (const QGraphicsItem *item) const
 Returns true if this item's bounding rect is completely obscured by the opaque shape of item. More...
 
bool isPanel () const
 Returns true if the item is a panel; otherwise returns false. More...
 
bool isSelected () const
 Returns true if this item is selected; otherwise, false is returned. More...
 
bool isUnderMouse () const
 Returns true if this item is currently under the mouse cursor in one of the views; otherwise, false is returned. More...
 
bool isVisible () const
 Returns true if the item is visible; otherwise, false is returned. More...
 
bool isVisibleTo (const QGraphicsItem *parent) const
 Returns true if the item is visible to parent; otherwise, false is returned. More...
 
bool isWidget () const
 Returns true if this item is a widget (i. More...
 
bool isWindow () const
 Returns true if the item is a QGraphicsWidget window, otherwise returns false. More...
 
QTransform itemTransform (const QGraphicsItem *other, bool *ok=0) const
 Returns a QTransform that maps coordinates from this item to other. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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)). More...
 
QPolygonF mapFromItem (const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
QPointF mapFromParent (qreal x, qreal y) const
 This convenience function is equivalent to calling mapFromParent(QPointF(x, y)). More...
 
QPolygonF mapFromParent (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling mapFromItem(QRectF(x, y, w, h)). More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
QPointF mapFromScene (qreal x, qreal y) const
 This convenience function is equivalent to calling mapFromScene(QPointF(x, y)). More...
 
QPolygonF mapFromScene (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling mapFromScene(QRectF(x, y, w, h)). More...
 
QRectF mapRectFromItem (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 new rectangle (i. More...
 
QRectF mapRectFromItem (const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
 
QRectF mapRectFromParent (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 new rectangle (i. More...
 
QRectF mapRectFromParent (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling mapRectFromParent(QRectF(x, y, w, h)). More...
 
QRectF mapRectFromScene (const QRectF &rect) const
 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. More...
 
QRectF mapRectFromScene (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling mapRectFromScene(QRectF(x, y, w, h)). More...
 
QRectF mapRectToItem (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 new rectangle (i. More...
 
QRectF mapRectToItem (const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
 
QRectF mapRectToParent (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 new rectangle (i. More...
 
QRectF mapRectToParent (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling mapRectToParent(QRectF(x, y, w, h)). More...
 
QRectF mapRectToScene (const QRectF &rect) const
 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. More...
 
QRectF mapRectToScene (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling mapRectToScene(QRectF(x, y, w, h)). More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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)). More...
 
QPolygonF mapToItem (const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
QPointF mapToParent (qreal x, qreal y) const
 This convenience function is equivalent to calling mapToParent(QPointF(x, y)). More...
 
QPolygonF mapToParent (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling mapToParent(QRectF(x, y, w, h)). More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
QPointF mapToScene (qreal x, qreal y) const
 This convenience function is equivalent to calling mapToScene(QPointF(x, y)). More...
 
QPolygonF mapToScene (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling mapToScene(QRectF(x, y, w, h)). More...
 
QMatrix matrix () const
 Returns the item's affine transformation matrix. More...
 
void moveBy (qreal dx, qreal dy)
 Moves the item by dx points horizontally, and dy point vertically. More...
 
qreal opacity () const
 Returns this item's local opacity, which is between 0. More...
 
virtual QPainterPath opaqueArea () const
 This virtual function returns a shape representing the area where this item is opaque. More...
 
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)=0
 This function, which is usually called by QGraphicsView, paints the contents of an item in local coordinates. More...
 
QGraphicsItempanel () const
 Returns the item's panel, or 0 if this item does not have a panel. More...
 
PanelModality panelModality () const
 Returns the modality for this item. More...
 
QGraphicsItemparentItem () const
 Returns a pointer to this item's parent item. More...
 
QGraphicsObjectparentObject () const
 Returns a pointer to the item's parent, cast to a QGraphicsObject. More...
 
QGraphicsWidgetparentWidget () const
 Returns a pointer to the item's parent widget. More...
 
QPointF pos () const
 Returns the position of the item in parent coordinates. More...
 
 QGraphicsItem (QGraphicsItem *parent=0)
 Constructs a QGraphicsItem with the given parent item. More...
 
void removeSceneEventFilter (QGraphicsItem *filterItem)
 Removes an event filter on this item from filterItem. More...
 
void resetMatrix ()
 Use resetTransform() instead. More...
 
void resetTransform ()
 Resets this item's transformation matrix to the identity matrix or all the transformation properties to their default values. More...
 
void rotate (qreal angle)
 Use. More...
 
qreal rotation () const
 Returns the clockwise rotation, in degrees, around the Z axis. More...
 
void scale (qreal sx, qreal sy)
 Use. More...
 
qreal scale () const
 Returns the scale factor of the item. More...
 
QGraphicsScenescene () const
 Returns the current scene for the item, or 0 if the item is not stored in a scene. More...
 
QRectF sceneBoundingRect () const
 Returns the bounding rect of this item in scene coordinates, by combining sceneTransform() with boundingRect(). More...
 
QMatrix sceneMatrix () const
 Use sceneTransform() instead. More...
 
QPointF scenePos () const
 Returns the item's position in scene coordinates. More...
 
QTransform sceneTransform () const
 Returns this item's scene transformation matrix. More...
 
void scroll (qreal dx, qreal dy, const QRectF &rect=QRectF())
 Scrolls the contents of rect by dx, dy. More...
 
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. More...
 
void setAcceptedMouseButtons (Qt::MouseButtons buttons)
 Sets the mouse buttons that this item accepts mouse events for. More...
 
void setAcceptHoverEvents (bool enabled)
 If enabled is true, this item will accept hover events; otherwise, it will ignore them. More...
 
void setAcceptsHoverEvents (bool enabled)
 Use setAcceptHoverEvents(enabled) instead. More...
 
void setAcceptTouchEvents (bool enabled)
 If enabled is true, this item will accept touch events; otherwise, it will ignore them. More...
 
void setActive (bool active)
 If active is true, and the scene is active, this item's panel will be activated. More...
 
void setBoundingRegionGranularity (qreal granularity)
 Sets the bounding region granularity to granularity; a value between and including 0 and 1. More...
 
void setCacheMode (CacheMode mode, const QSize &cacheSize=QSize())
 Sets the item's cache mode to mode. More...
 
void setCursor (const QCursor &cursor)
 Sets the current cursor shape for the item to cursor. More...
 
void setData (int key, const QVariant &value)
 Sets this item's custom data for the key key to value. More...
 
void setEnabled (bool enabled)
 If enabled is true, the item is enabled; otherwise, it is disabled. More...
 
void setFiltersChildEvents (bool enabled)
 If enabled is true, this item is set to filter all events for all its children (i. More...
 
void setFlag (GraphicsItemFlag flag, bool enabled=true)
 If enabled is true, the item flag flag is enabled; otherwise, it is disabled. More...
 
void setFlags (GraphicsItemFlags flags)
 Sets the item flags to flags. More...
 
void setFocus (Qt::FocusReason focusReason=Qt::OtherFocusReason)
 Gives keyboard input focus to this item. More...
 
void setFocusProxy (QGraphicsItem *item)
 Sets the item's focus proxy to item. More...
 
void setGraphicsEffect (QGraphicsEffect *effect)
 Sets effect as the item's effect. More...
 
void setGroup (QGraphicsItemGroup *group)
 Adds this item to the item group group. More...
 
void setHandlesChildEvents (bool enabled)
 If enabled is true, this item is set to handle all events for all its children (i. More...
 
void setInputMethodHints (Qt::InputMethodHints hints)
 Sets the current input method hints of this item to hints. More...
 
void setMatrix (const QMatrix &matrix, bool combine=false)
 Sets the item's affine transformation matrix. More...
 
void setOpacity (qreal opacity)
 Sets this item's local opacity, between 0. More...
 
void setPanelModality (PanelModality panelModality)
 Sets the modality for this item to panelModality. More...
 
void setParentItem (QGraphicsItem *parent)
 Sets this item's parent item to newParent. More...
 
void setPos (const QPointF &pos)
 Sets the position of the item to pos, which is in parent coordinates. More...
 
void setPos (qreal x, qreal y)
 This convenience function is equivalent to calling setPos(QPointF(x, y)). More...
 
void setRotation (qreal angle)
 Sets the clockwise rotation angle, in degrees, around the Z axis. More...
 
void setScale (qreal scale)
 Sets the scale factor of the item. More...
 
void setSelected (bool selected)
 If selected is true and this item is selectable, this item is selected; otherwise, it is unselected. More...
 
void setToolTip (const QString &toolTip)
 Sets the item's tool tip to toolTip. More...
 
void setTransform (const QTransform &matrix, bool combine=false)
 Sets the item's current transformation matrix to matrix. More...
 
void setTransformations (const QList< QGraphicsTransform *> &transformations)
 Sets a list of graphics transformations (QGraphicsTransform) that currently apply to this item. More...
 
void setTransformOriginPoint (const QPointF &origin)
 Sets the origin point for the transformation in item coordinates. More...
 
void setTransformOriginPoint (qreal ax, qreal ay)
 Sets the origin point for the transformation in item coordinates. More...
 
void setVisible (bool visible)
 If visible is true, the item is made visible. More...
 
void setX (qreal x)
 Set's the x coordinate of the item's position. More...
 
void setY (qreal y)
 Set's the y coordinate of the item's position. More...
 
void setZValue (qreal z)
 Sets the Z-value of the item to z. More...
 
virtual QPainterPath shape () const
 Returns the shape of this item as a QPainterPath in local coordinates. More...
 
void shear (qreal sh, qreal sv)
 Use. More...
 
void show ()
 Shows the item. More...
 
void stackBefore (const QGraphicsItem *sibling)
 Stacks this item before sibling, which must be a sibling item (i. More...
 
QGraphicsObjecttoGraphicsObject ()
 Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object, 0 otherwise. More...
 
const QGraphicsObjecttoGraphicsObject () const
 Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object, 0 otherwise. More...
 
QString toolTip () const
 Returns the item's tool tip, or an empty QString if no tool tip has been set. More...
 
QGraphicsItemtopLevelItem () const
 Returns this item's top-level item. More...
 
QGraphicsWidgettopLevelWidget () const
 Returns a pointer to the item's top level widget (i. More...
 
QTransform transform () const
 Returns this item's transformation matrix. More...
 
QList< QGraphicsTransform * > transformations () const
 Returns a list of graphics transforms that currently apply to this item. More...
 
QPointF transformOriginPoint () const
 Returns the origin point for the transformation in item coordinates. More...
 
void translate (qreal dx, qreal dy)
 Use setPos() or setTransformOriginPoint() instead. More...
 
virtual int type () const
 Returns the type of an item as an int. More...
 
void ungrabKeyboard ()
 Releases the keyboard grab. More...
 
void ungrabMouse ()
 Releases the mouse grab. More...
 
void unsetCursor ()
 Clears the cursor from this item. More...
 
void update (const QRectF &rect=QRectF())
 Schedules a redraw of the area covered by rect in this item. More...
 
void update (qreal x, qreal y, qreal width, qreal height)
 This convenience function is equivalent to calling update(QRectF(x, y, width, height)). More...
 
QGraphicsWidgetwindow () const
 Returns the item's window, or 0 if this item does not have a window. More...
 
qreal x () const
 This convenience function is equivalent to calling pos(). More...
 
qreal y () const
 This convenience function is equivalent to calling pos(). More...
 
qreal zValue () const
 Returns the Z-value of the item. More...
 
virtual ~QGraphicsItem ()
 Destroys the QGraphicsItem and all its children. More...
 

Protected Types

enum  Extension { UserExtension = 0x80000000 }
 Note: This is provided as a hook to avoid future problems related to adding virtual functions. More...
 

Protected Functions

void addToIndex ()
 Adds this item to the scene's index. More...
 
virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *event)
 This event handler can be reimplemented in a subclass to process context menu events. More...
 
virtual void dragEnterEvent (QGraphicsSceneDragDropEvent *event)
 This event handler, for event event, can be reimplemented to receive drag enter events for this item. More...
 
virtual void dragLeaveEvent (QGraphicsSceneDragDropEvent *event)
 This event handler, for event event, can be reimplemented to receive drag leave events for this item. More...
 
virtual void dragMoveEvent (QGraphicsSceneDragDropEvent *event)
 This event handler, for event event, can be reimplemented to receive drag move events for this item. More...
 
virtual void dropEvent (QGraphicsSceneDragDropEvent *event)
 This event handler, for event event, can be reimplemented to receive drop events for this item. More...
 
virtual QVariant extension (const QVariant &variant) const
 Note: This is provided as a hook to avoid future problems related to adding virtual functions. More...
 
virtual void focusInEvent (QFocusEvent *event)
 This event handler, for event event, can be reimplemented to receive focus in events for this item. More...
 
virtual void focusOutEvent (QFocusEvent *event)
 This event handler, for event event, can be reimplemented to receive focus out events for this item. More...
 
virtual void hoverEnterEvent (QGraphicsSceneHoverEvent *event)
 This event handler, for event event, can be reimplemented to receive hover enter events for this item. More...
 
virtual void hoverLeaveEvent (QGraphicsSceneHoverEvent *event)
 This event handler, for event event, can be reimplemented to receive hover leave events for this item. More...
 
virtual void hoverMoveEvent (QGraphicsSceneHoverEvent *event)
 This event handler, for event event, can be reimplemented to receive hover move events for this item. More...
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 This event handler, for event event, can be reimplemented to receive input method events for this item. More...
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 This method is only relevant for input items. More...
 
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. More...
 
virtual void keyPressEvent (QKeyEvent *event)
 This event handler, for event event, can be reimplemented to receive key press events for this item. More...
 
virtual void keyReleaseEvent (QKeyEvent *event)
 This event handler, for event event, can be reimplemented to receive key release events for this item. More...
 
virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event)
 This event handler, for event event, can be reimplemented to receive mouse doubleclick events for this item. More...
 
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event)
 This event handler, for event event, can be reimplemented to receive mouse move events for this item. More...
 
virtual void mousePressEvent (QGraphicsSceneMouseEvent *event)
 This event handler, for event event, can be reimplemented to receive mouse press events for this item. More...
 
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event)
 This event handler, for event event, can be reimplemented to receive mouse release events for this item. More...
 
void prepareGeometryChange ()
 Prepares the item for a geometry change. More...
 
 QGraphicsItem (QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene)
 
void removeFromIndex ()
 Removes this item from the scene's index. More...
 
virtual bool sceneEvent (QEvent *event)
 This virtual function receives events to this item. More...
 
virtual bool sceneEventFilter (QGraphicsItem *watched, QEvent *event)
 Filters events for the item watched. More...
 
virtual void setExtension (Extension extension, const QVariant &variant)
 Note: This is provided as a hook to avoid future problems related to adding virtual functions. More...
 
virtual bool supportsExtension (Extension extension) const
 Note: This is provided as a hook to avoid future problems related to adding virtual functions. More...
 
void updateMicroFocus ()
 Updates the item's micro focus. More...
 
virtual void wheelEvent (QGraphicsSceneWheelEvent *event)
 This event handler, for event event, can be reimplemented to receive wheel events for this item. More...
 

Protected Variables

QScopedPointer< QGraphicsItemPrivated_ptr
 

Friends

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

Related Functions

(Note that these are not member functions.)

qgraphicsitem_cast (QGraphicsItem *item)
 

Detailed Description

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

Since
4.2

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 Graphics View Framework

graphicsview-items.png

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

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. 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:
{
qreal penWidth = 1;
return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,
20 + penWidth, 20 + penWidth);
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
{
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:

  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.

  2. Reimplement collidesWithItem() to provide your own custom item and shape collision algorithm.

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.

graphicsview-parentchild.png

Transformations

QGraphicsItem supports projective transformations in addition to its base position, pos(). There are several ways to change an item's transformation. For simple transformations, you can call either of the convenience functions setRotation() or setScale(), or you can pass any transformation matrix to setTransform(). For advanced transformation control you also have the option of setting several combined transformations by calling setTransformations().

Item transformations accumulate from parent to child, so if both a parent and child item are rotated 90 degrees, the child's total transformation will be 180 degrees. Similarly, if the item's parent is scaled to 2x its original size, its children will also be twice as large. An item's transformation does not affect its own local geometry; all geometry functions (e.g., contains(), update(), and all the mapping functions) still operate in local coordinates. For convenience, QGraphicsItem provides the functions sceneTransform(), which returns the item's total transformation matrix (including its position and all parents' positions and transformations), and scenePos(), which returns its position in scene coordinates. To reset an item's matrix, call resetTransform().

Certain transformation operations produce a different outcome depending on the order in which they are applied. For example, if you scale an transform, and then rotate it, you may get a different result than if the transform was rotated first. However, the order you set the transformation properties on QGraphicsItem does not affect the resulting transformation; QGraphicsItem always applies the properties in a fixed, defined order:

Painting

The paint() function is called by QGraphicsView to paint the item's contents. The item has no background or default fill of its own; whatever is behind the item will shine through all areas that are not explicitly painted in this function. You can call update() to schedule a repaint, optionally passing the rectangle that needs a repaint. Depending on whether or not the item is visible in a view, the item may or may not be repainted; there is no equivalent to QWidget::repaint() in QGraphicsItem.

Items are painted by the view, starting with the parent items and then drawing children, in ascending stacking order. You can set an item's stacking order by calling setZValue(), and test it by calling zValue(), where items with low z-values are painted before items with high z-values. Stacking order applies to sibling items; parents are always drawn before their children.

Sorting

All items are drawn in a defined, stable order, and this same order decides which items will receive mouse input first when you click on the scene. Normally you don't have to worry about sorting, as the items follow a "natural order", following the logical structure of the scene.

An item's children are stacked on top of the parent, and sibling items are stacked by insertion order (i.e., in the same order that they were either added to the scene, or added to the same parent). If you add item A, and then B, then B will be on top of A. If you then add C, the items' stacking order will be A, then B, then C.

graphicsview-zorder.png

This example shows the stacking order of all limbs of the robot from the Drag and Drop Robot example. The torso is the root item (all other items are children or descendants of the torso), so it is drawn first. Next, the head is drawn, as it is the first item in the torso's list of children. Then the upper left arm is drawn. As the lower arm is a child of the upper arm, the lower arm is then drawn, followed by the upper arm's next sibling, which is the upper right arm, and so on.

For advanced users, there are ways to alter how your items are sorted:

The stacking order of two sibling items also counts for each item's children and descendant items. So if one item is on top of another, then all its children will also be on top of all the other item's children as well.

Events

QGraphicsItem receives events from QGraphicsScene through the virtual function sceneEvent(). This function distributes the most common events to a set of convenience event handlers:

You can filter events for any other item by installing event filters. This functionality is separate from Qt's regular event filters (see QObject::installEventFilter()), which only work on subclasses of QObject. After installing your item as an event filter for another item by calling installSceneEventFilter(), the filtered events will be received by the virtual function sceneEventFilter(). You can remove item event filters by calling removeSceneEventFilter().

Custom Data

Sometimes it's useful to register custom data with an item, be it a custom item, or a standard item. You can call setData() on any item to store data in it using a key-value pair (the key being an integer, and the value is a QVariant). To get custom data from an item, call data(). This functionality is completely untouched by Qt itself; it is provided for the user's convenience.

See also
QGraphicsScene, QGraphicsView, {Graphics View Framework}

Definition at line 89 of file qgraphicsitem.h.

Enumerations

◆ anonymous enum

anonymous enum
Enumerator
Type 

The type value returned by the virtual type() function in standard graphics item classes in Qt.

All such standard graphics item classes in Qt are associated with a unique value for Type, e.g. the value returned by QGraphicsPathItem::type() is 2.

{
public:
enum { Type = 2 };
int type() const { return Type; }
...
};
UserType 

The lowest permitted type value for custom items (subclasses of QGraphicsItem or any of the standard items).

This value is used in conjunction with a reimplementation of QGraphicsItem::type() and declaring a Type enum value. Example:

class CustomItem : public QGraphicsItem
{
...
enum { Type = UserType + 1 };
int type() const
{
// Enable the use of qgraphicsitem_cast with this item.
return Type;
}
...
};
Note
UserType = 65536

Definition at line 419 of file qgraphicsitem.h.

419  {
420  Type = 1,
421  UserType = 65536
422  };
The type value returned by the virtual type() function in standard graphics item classes in Qt...
The lowest permitted type value for custom items (subclasses of QGraphicsItem or any of the standard ...

◆ CacheMode

This enum describes QGraphicsItem's cache modes.

Since
4.4

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.

  • NoCache The default; all item caching is disabled. QGraphicsItem::paint() is called every time the item needs redrawing.
  • 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.
  • 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 153 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.

Warning
This function is not part of the public interface.

See also extension(), supportsExtension() and setExtension().

Enumerator
UserExtension 

Definition at line 454 of file qgraphicsitem.h.

454  {
455  UserExtension = 0x80000000
456  };

◆ 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().

  • 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().
  • 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.
  • ItemMatrixChange The item's affine transformation matrix is changing. This value is obsolete; you can use ItemTransformChange instead.
  • 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.
  • 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).
  • ItemTransformChange The item's transformation matrix changes. This notification is send 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.
  • 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).
  • 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().
  • 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.
  • 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().
  • 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.
  • 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().
  • 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.
  • 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().
  • 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.
  • 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().
  • 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.
  • 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.
  • 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.
  • 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.
  • 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 0 if the item has not been added to a scene yet). The value argument is the new scene (i.e., a QGraphicsScene pointer), or a null pointer 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.
  • 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.
  • 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().
  • 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.
  • 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().
  • 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.
  • 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().
  • 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.
  • 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().
  • 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.
  • 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().
  • 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.
  • 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 
ItemMatrixChange 
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 116 of file qgraphicsitem.h.

116  {
151  };

◆ 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.

  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • ItemSendsGeometryChanges The item enables itemChange() notifications for ItemPositionChange, ItemPositionHasChanged, ItemMatrixChange, 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.
  • ItemAcceptsInputMethod The item supports input methods typically used for Asian languages. This flag was introduced in Qt 4.6.
  • 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.
  • 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.
  • ItemIsFocusScope
    Warning
    This function is not part of the public interface. Internal only (for now).
  • 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.
  • ItemStopsClickFocusPropagation
    Warning
    This function is not part of the public interface. 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.
  • ItemStopsFocusHandling
    Warning
    This function is not part of the public interface. 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.
Enumerator
ItemIsMovable 
ItemIsSelectable 
ItemIsFocusable 
ItemClipsToShape 
ItemClipsChildrenToShape 
ItemIgnoresTransformations 
ItemIgnoresParentOpacity 
ItemDoesntPropagateOpacityToChildren 
ItemStacksBehindParent 
ItemUsesExtendedStyleOption 
ItemHasNoContents 
ItemSendsGeometryChanges 
ItemAcceptsInputMethod 
ItemNegativeZStacksBehindParent 
ItemIsPanel 
ItemIsFocusScope 
ItemSendsScenePositionChanges 
ItemStopsClickFocusPropagation 
ItemStopsFocusHandling 

Definition at line 92 of file qgraphicsitem.h.

92  {
93  ItemIsMovable = 0x1,
94  ItemIsSelectable = 0x2,
95  ItemIsFocusable = 0x4,
96  ItemClipsToShape = 0x8,
101  ItemStacksBehindParent = 0x100,
103  ItemHasNoContents = 0x400,
104  ItemSendsGeometryChanges = 0x800,
105  ItemAcceptsInputMethod = 0x1000,
107  ItemIsPanel = 0x4000,
108  ItemIsFocusScope = 0x8000, // internal
111  ItemStopsFocusHandling = 0x40000
112  // NB! Don't forget to increase the d_ptr->flags bit field by 1 when adding a new flag.
113  };

◆ PanelModality

This enum specifies the behavior of a modal panel.

Since
4.6

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:

  • NonModal The panel is not modal and does not block input to other panels. This is the default value for panels.
  • 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.
  • 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 159 of file qgraphicsitem.h.

Constructors and Destructors

◆ QGraphicsItem() [1/2]

QGraphicsItem::QGraphicsItem ( QGraphicsItem parent = 0)

Constructs a QGraphicsItem with the given parent item.

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

If parent is 0, 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 1461 of file qgraphicsitem.cpp.

1468 {
1469  d_ptr->q_ptr = this;
1470  setParentItem(parent);
1471 
1472  if (scene && parent && parent->scene() != scene) {
1473  qWarning("QGraphicsItem::QGraphicsItem: ignoring scene (%p), which is"
1474  " different from parent's scene (%p)",
1475  scene, parent->scene());
1476  return;
1477  }
1478  if (scene && !parent)
1479  scene->addItem(this);
1480 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
void setParentItem(QGraphicsItem *parent)
Sets this item&#39;s parent item to newParent.
QGraphicsItem * q_ptr
void addItem(QGraphicsItem *item)
Adds or moves the item and all its childen to this scene.
Q_CORE_EXPORT void qWarning(const char *,...)
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.

◆ ~QGraphicsItem()

QGraphicsItem::~QGraphicsItem ( )
virtual

Destroys the QGraphicsItem and all its children.

If this item is currently associated with a scene, the item will be removed from the scene before it is deleted.

Note
It is more efficient to remove the item from the QGraphicsScene before destroying the item.

Definition at line 1510 of file qgraphicsitem.cpp.

1511 {
1512  if (d_ptr->isObject) {
1513  QGraphicsObject *o = static_cast<QGraphicsObject *>(this);
1515  p->wasDeleted = true;
1516  if (p->declarativeData) {
1518  p->declarativeData = 0;
1519  }
1520  }
1521 
1522  d_ptr->inDestructor = 1;
1524 
1525 #ifndef QT_NO_GESTURES
1526  if (d_ptr->isObject && !d_ptr->gestureContext.isEmpty()) {
1527  QGraphicsObject *o = static_cast<QGraphicsObject *>(this);
1528  if (QGestureManager *manager = QGestureManager::instance()) {
1530  manager->cleanupCachedGestures(o, type);
1531  }
1532  }
1533 #endif
1534 
1535  clearFocus();
1536 
1537  // Update focus scope item ptr.
1538  QGraphicsItem *p = d_ptr->parent;
1539  while (p) {
1540  if (p->flags() & ItemIsFocusScope) {
1541  if (p->d_ptr->focusScopeItem == this)
1542  p->d_ptr->focusScopeItem = 0;
1543  break;
1544  }
1545  p = p->d_ptr->parent;
1546  }
1547 
1548  if (!d_ptr->children.isEmpty()) {
1549  while (!d_ptr->children.isEmpty())
1550  delete d_ptr->children.first();
1552  }
1553 
1554  if (d_ptr->scene) {
1555  d_ptr->scene->d_func()->removeItemHelper(this);
1556  } else {
1558  setParentItem(0);
1559  }
1560 
1561 #ifndef QT_NO_GRAPHICSEFFECT
1562  delete d_ptr->graphicsEffect;
1563 #endif //QT_NO_GRAPHICSEFFECT
1564  if (d_ptr->transformData) {
1565  for(int i = 0; i < d_ptr->transformData->graphicsTransforms.size(); ++i) {
1567  static_cast<QGraphicsTransformPrivate *>(t->d_ptr.data())->item = 0;
1568  delete t;
1569  }
1570  }
1571  delete d_ptr->transformData;
1572 
1573  if (QGraphicsItemCustomDataStore *dataStore = qt_dataStore())
1574  dataStore->data.remove(this);
1575 }
QGraphicsItem * parent
void resetFocusProxy()
Sets the focusProxy pointer to 0 for all items that have this item as their focusProxy.
QScopedPointer< QGraphicsItemPrivate > d_ptr
T * data() const
Returns the value of the pointer referenced by this object.
void clearFocus()
Takes keyboard input focus from the item.
void setParentItem(QGraphicsItem *parent)
Sets this item&#39;s parent item to newParent.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QGraphicsScene * scene
uint wasDeleted
Definition: qobject.h:98
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:177
static QGestureManager * instance()
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QGraphicsEffect * graphicsEffect
virtual int type() const
Returns the type of an item as an int.
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
Definition: qmap.h:818
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
QAbstractDeclarativeData * declarativeData
Definition: qobject_p.h:214
GestureType
Definition: qnamespace.h:1759
QMap< Qt::GestureType, Qt::GestureFlags > gestureContext
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
QList< QGraphicsTransform * > graphicsTransforms
QGraphicsItem * focusScopeItem
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool isEmpty() const
Returns true if the map contains no items; otherwise returns false.
Definition: qmap.h:203
static void(* destroyed)(QAbstractDeclarativeData *, QObject *)
Definition: qobject_p.h:93
QScopedPointer< QObjectData > d_ptr
Definition: qobject.h:320
TransformData * transformData
QList< QGraphicsItem * > children
The QGraphicsObject class provides a base class for all graphics items that require signals...
The QGraphicsTransform class is an abstract base class for building advanced transformations on QGrap...

◆ QGraphicsItem() [2/2]

QGraphicsItem::QGraphicsItem ( QGraphicsItemPrivate dd,
QGraphicsItem parent,
QGraphicsScene scene 
)
protected
Warning
This function is not part of the public interface.

Definition at line 1485 of file qgraphicsitem.cpp.

1487  : d_ptr(&dd)
1488 {
1489  d_ptr->q_ptr = this;
1490  setParentItem(parent);
1491 
1492  if (scene && parent && parent->scene() != scene) {
1493  qWarning("QGraphicsItem::QGraphicsItem: ignoring scene (%p), which is"
1494  " different from parent's scene (%p)",
1495  scene, parent->scene());
1496  return;
1497  }
1498  if (scene && !parent)
1499  scene->addItem(this);
1500 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
void setParentItem(QGraphicsItem *parent)
Sets this item&#39;s parent item to newParent.
QGraphicsItem * q_ptr
void addItem(QGraphicsItem *item)
Adds or moves the item and all its childen to this scene.
Q_CORE_EXPORT void qWarning(const char *,...)
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.

Functions

◆ 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 3064 of file qgraphicsitem.cpp.

Referenced by QGraphicsScene::dragMoveEvent().

3065 {
3066  return d_ptr->acceptDrops;
3067 }
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ 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 3093 of file qgraphicsitem.cpp.

Referenced by QGraphicsScenePrivate::mousePressEventHandler(), QDeclarativeMouseArea::setAcceptedButtons(), and QDeclarativeMouseArea::setHovered().

3094 {
3095  return Qt::MouseButtons(d_ptr->acceptedMouseButtons);
3096 }
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ acceptHoverEvents()

bool QGraphicsItem::acceptHoverEvents ( ) const

Returns true if an item accepts hover events (QGraphicsSceneHoverEvent); otherwise, returns false.

Since
4.4

By default, items do not accept hover events.

See also
setAcceptedMouseButtons()

Definition at line 3135 of file qgraphicsitem.cpp.

Referenced by QDeclarativeMouseArea::itemChange(), QDeclarativeMouseArea::mouseReleaseEvent(), and QDeclarativeMouseArea::setHoverEnabled().

3136 {
3137  return d_ptr->acceptsHover;
3138 }
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ acceptsHoverEvents()

bool QGraphicsItem::acceptsHoverEvents ( ) const

Call acceptHoverEvents() instead.

Definition at line 3148 of file qgraphicsitem.cpp.

Referenced by QGraphicsWidget::event().

3149 {
3150  return d_ptr->acceptsHover;
3151 }
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ acceptTouchEvents()

bool QGraphicsItem::acceptTouchEvents ( ) const

Returns true if an item accepts touch events; otherwise, returns false.

Since
4.6

By default, items do not accept touch events.

See also
setAcceptTouchEvents()

Definition at line 3221 of file qgraphicsitem.cpp.

Referenced by QGraphicsScenePrivate::sendTouchBeginEvent().

3222 {
3223  return d_ptr->acceptTouchEvents;
3224 }
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ addToIndex()

void QGraphicsItem::addToIndex ( )
protected

Adds this item to the scene's index.

Warning
This function is not part of the public interface.

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

Definition at line 7936 of file qgraphicsitem.cpp.

7937 {
7939  // ### add to child index only if applicable
7940  return;
7941  }
7942  if (d_ptr->scene)
7943  d_ptr->scene->d_func()->index->addItem(this);
7944 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsScene * scene
void addItem(QGraphicsItem *item)
Adds or moves the item and all its childen to this scene.

◆ 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.

For individual item animation, an alternative to this function is to either use QGraphicsItemAnimation, or to multiple-inherit from QObject and QGraphicsItem, and animate your item using QObject::startTimer() and QObject::timerEvent().

See also
QGraphicsItemAnimation, QTimeLine

Definition at line 4882 of file qgraphicsitem.cpp.

Referenced by QGraphicsScene::advance().

4883 {
4884  Q_UNUSED(phase);
4885 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ 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 its 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 around in 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:

{
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 QGraphicsItemGroup, QGraphicsSimpleTextItem, QGraphicsTextItem, QGraphicsPixmapItem, QGraphicsLineItem, QGraphicsPolygonItem, QGraphicsEllipseItem, QGraphicsRectItem, QGraphicsPathItem, QDeclarativeTextEdit, QDeclarativeTextInput, QDeclarativeText, QGraphicsWidget, QDeclarativeRectangle, QDeclarativeItem, QDeclarativePaintedItem, QGraphicsSvgItem, QDeclarativeImage, and QmlJSDebugger::LiveLayerItem.

Referenced by QGraphicsItemGroup::addToGroup(), adjustedItemBoundingRect(), boundingRegion(), clipPath(), collidesWithPath(), QGraphicsScenePrivate::drawItemHelper(), QmlJSDebugger::BoundingRectHighlighter::highlightAll(), QGraphicsSceneIndexRectIntersector::intersect(), QGraphicsSceneIndexPointIntersector::intersect(), QGraphicsSceneIndexPathIntersector::intersect(), isObscured(), isObscuredBy(), prepareGeometryChange(), QGraphicsScenePrivate::processDirtyItemsRecursive(), qt_graphicsItem_highlightSelected(), sceneBoundingRect(), scroll(), QmlJSDebugger::SubcomponentMaskLayerItem::setCurrentItem(), QmlJSDebugger::LiveSelectionIndicator::setItems(), QGraphicsLineItem::setLine(), QGraphicsViewPrivate::setUpdateClip(), and shape().

◆ boundingRegion()

QRegion QGraphicsItem::boundingRegion ( const QTransform itemToDeviceTransform) const

Returns the bounding region for this item.

Since
4.4

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 5545 of file qgraphicsitem.cpp.

Referenced by QGraphicsViewPrivate::mapToViewRegion().

5546 {
5547  // ### Ideally we would have a better way to generate this region,
5548  // preferably something in the lines of QPainterPath::toRegion(QTransform)
5549  // coupled with a way to generate a painter path from a set of painter
5550  // operations (e.g., QPicture::toPainterPath() or so). The current
5551  // approach generates a bitmap with the size of the item's bounding rect
5552  // in device coordinates, scaled by b.r.granularity, then paints the item
5553  // into the bitmap, converts the result to a QRegion and scales the region
5554  // back to device space with inverse granularity.
5555  qreal granularity = boundingRegionGranularity();
5556  QRect deviceRect = itemToDeviceTransform.mapRect(boundingRect()).toRect();
5557  _q_adjustRect(&deviceRect);
5558  if (granularity == 0.0)
5559  return QRegion(deviceRect);
5560 
5561  int pad = 1;
5562  QSize bitmapSize(qMax(1, int(deviceRect.width() * granularity) + pad * 2),
5563  qMax(1, int(deviceRect.height() * granularity) + pad * 2));
5564  QImage mask(bitmapSize, QImage::Format_ARGB32_Premultiplied);
5565  mask.fill(0);
5566  QPainter p(&mask);
5567  p.setRenderHints(QPainter::Antialiasing);
5568 
5569  // Transform painter (### this code is from QGraphicsScene::drawItemHelper
5570  // and doesn't work properly with perspective transformations).
5571  QPointF viewOrigo = itemToDeviceTransform.map(QPointF(0, 0));
5572  QPointF offset = viewOrigo - deviceRect.topLeft();
5573  p.scale(granularity, granularity);
5574  p.translate(offset);
5575  p.translate(pad, pad);
5576  p.setWorldTransform(itemToDeviceTransform, true);
5577  p.translate(itemToDeviceTransform.inverted().map(QPointF(0, 0)));
5578 
5579  // Render
5580  QStyleOptionGraphicsItem option;
5581  const_cast<QGraphicsItem *>(this)->paint(&p, &option, 0);
5582  p.end();
5583 
5584  // Transform QRegion back to device space
5585  QTransform unscale = QTransform::fromScale(1 / granularity, 1 / granularity);
5586  QRegion r;
5587  QBitmap colorMask = QBitmap::fromImage(mask.createMaskFromColor(0));
5588  foreach (const QRect &rect, QRegion( colorMask ).rects()) {
5589  QRect xrect = unscale.mapRect(rect).translated(deviceRect.topLeft() - QPoint(pad, pad));
5590  r += xrect.adjusted(-1, -1, 1, 1) & deviceRect;
5591  }
5592  return r;
5593 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
double qreal
Definition: qglobal.h:1193
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
static void _q_adjustRect(QRect *rect)
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
qreal boundingRegionGranularity() const
Returns the item&#39;s bounding region granularity; a value between and including 0 and 1...
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static QBitmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Returns a copy of the given image converted to a bitmap using the specified image conversion flags...
Definition: qbitmap.cpp:281
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)=0
This function, which is usually called by QGraphicsView, paints the contents of an item in local coor...
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static QTransform fromScale(qreal dx, qreal dy)
Creates a matrix which corresponds to a scaling of sx horizontally and sy vertically.
Definition: qtransform.cpp:528
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem...
Definition: qstyleoption.h:867
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288

◆ boundingRegionGranularity()

qreal QGraphicsItem::boundingRegionGranularity ( ) const

Returns the item's bounding region granularity; a value between and including 0 and 1.

Since
4.4

The default value is 0 (i.e., the lowest granularity, where the bounding region corresponds to the item's bounding rectangle).

Warning
This function is not part of the public interface.

NOTE

\sa setBoundingRegionGranularity()

Definition at line 5611 of file qgraphicsitem.cpp.

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

5612 {
5615  : 0;
5616 }
double qreal
Definition: qglobal.h:1193
QScopedPointer< QGraphicsItemPrivate > d_ptr
quint32 hasBoundingRegionGranularity
QVariant extra(Extra type) const
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ cacheMode()

QGraphicsItem::CacheMode QGraphicsItem::cacheMode ( ) const

Returns the cache mode for this item.

Since
4.4 The default mode is NoCache (i.e., cache is disabled and all painting is immediate).
See also
setCacheMode()

Definition at line 2061 of file qgraphicsitem.cpp.

Referenced by QGraphicsSvgItem::isCachingEnabled().

2062 {
2064 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
CacheMode
This enum describes QGraphicsItem&#39;s cache modes.

◆ childItems()

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

Returns a list of this item's children.

Since
4.4

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 1833 of file qgraphicsitem.cpp.

Referenced by QDeclarativeContents::calcHeight(), QDeclarativeContents::calcWidth(), QDeclarativeItem::childAt(), children(), QDeclarativeContents::complete(), QDeclarativeFlickablePrivate::data_at(), QDeclarativeFlickablePrivate::data_clear(), QDeclarativeFlickablePrivate::data_count(), QmlJSDebugger::LiveLayerItem::findAllChildItems(), QGraphicsProxyWidgetPrivate::setWidget_helper(), QDeclarativeContents::~QDeclarativeContents(), and QGraphicsWidget::~QGraphicsWidget().

1834 {
1835  const_cast<QGraphicsItem *>(this)->d_ptr->ensureSortedChildren();
1836  return d_ptr->children;
1837 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QList< QGraphicsItem * > children

◆ children()

QList< QGraphicsItem * > QGraphicsItem::children ( ) const

◆ 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 5068 of file qgraphicsitem.cpp.

Referenced by QGraphicsItemGroup::addToGroup(), QmlJSDebugger::LiveLayerItem::boundingRect(), QGraphicsItemGroup::removeFromGroup(), and QmlJSDebugger::SubcomponentMaskLayerItem::setCurrentItem().

5069 {
5071  return d_ptr->childrenBoundingRect;
5072 
5076  return d_ptr->childrenBoundingRect;
5077 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void childrenBoundingRectHelper(QTransform *x, QRectF *rect, QGraphicsItem *topMostEffectItem)
Returns the bounding rect of this item&#39;s children (excluding itself).

◆ clearFocus()

void QGraphicsItem::clearFocus ( )

Takes keyboard input focus from the item.

If it has focus, a 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 3521 of file qgraphicsitem.cpp.

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

3522 {
3523  d_ptr->clearFocusHelper(/* giveFocusToParent = */ true);
3524 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
void clearFocusHelper(bool giveFocusToParent)

◆ clipPath()

QPainterPath QGraphicsItem::clipPath ( ) const

Returns this item's clip path, or an empty QPainterPath if this item is not clipped.

Since
4.5

The clip path constrains the item's appearance and interaction (i.e., restricts the area the item can draw, and it also restricts the area that the item receives events).

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 5215 of file qgraphicsitem.cpp.

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

5216 {
5217  Q_D(const QGraphicsItem);
5218  if (!isClipped())
5219  return QPainterPath();
5220 
5221  const QRectF thisBoundingRect(boundingRect());
5222  if (thisBoundingRect.isEmpty())
5223  return QPainterPath();
5224 
5225  QPainterPath clip;
5226  // Start with the item's bounding rect.
5227  clip.addRect(thisBoundingRect);
5228 
5229  if (d->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren) {
5230  const QGraphicsItem *parent = this;
5231  const QGraphicsItem *lastParent = this;
5232 
5233  // Intersect any in-between clips starting at the top and moving downwards.
5234  while ((parent = parent->d_ptr->parent)) {
5235  if (parent->d_ptr->flags & ItemClipsChildrenToShape) {
5236  // Map clip to the current parent and intersect with its shape/clipPath
5237  clip = lastParent->itemTransform(parent).map(clip);
5238  clip = clip.intersected(parent->shape());
5239  if (clip.isEmpty())
5240  return clip;
5241  lastParent = parent;
5242  }
5243 
5245  break;
5246  }
5247 
5248  if (lastParent != this) {
5249  // Map clip back to the item's transform.
5250  // ### what if itemtransform fails
5251  clip = lastParent->itemTransform(this).map(clip);
5252  }
5253  }
5254 
5255  if (d->flags & ItemClipsToShape)
5256  clip = clip.intersected(shape());
5257 
5258  return clip;
5259 }
double d
Definition: qnumeric_p.h:62
bool isClipped() const
Returns true if this item is clipped.
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr
QTransform itemTransform(const QGraphicsItem *other, bool *ok=0) const
Returns a QTransform that maps coordinates from this item to other.
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QPainterPath intersected(const QPainterPath &r) const
Returns a path which is the intersection of this path&#39;s fill area and p&#39;s fill area.
#define Q_D(Class)
Definition: qglobal.h:2482
virtual QPainterPath shape() const
Returns the shape of this item as a QPainterPath in local coordinates.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.

◆ 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 noticably 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 5307 of file qgraphicsitem.cpp.

Referenced by QGraphicsScene::collidingItems().

5308 {
5309  if (other == this)
5310  return true;
5311  if (!other)
5312  return false;
5313  // The items share the same clip if their closest clipper is the same, or
5314  // if one clips the other.
5316  bool otherClips = (other->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren);
5317  if (clips || otherClips) {
5318  const QGraphicsItem *closestClipper = isAncestorOf(other) ? this : parentItem();
5319  while (closestClipper && !(closestClipper->flags() & ItemClipsChildrenToShape))
5320  closestClipper = closestClipper->parentItem();
5321  const QGraphicsItem *otherClosestClipper = other->isAncestorOf(this) ? other : other->parentItem();
5322  while (otherClosestClipper && !(otherClosestClipper->flags() & ItemClipsChildrenToShape))
5323  otherClosestClipper = otherClosestClipper->parentItem();
5324  if (closestClipper == otherClosestClipper) {
5326  bool res = collidesWithPath(mapFromItem(other, other->shape()), mode);
5328  return res;
5329  }
5330  }
5331 
5332  QPainterPath otherShape = other->isClipped() ? other->clipPath() : other->shape();
5333  return collidesWithPath(mapFromItem(other, otherShape), mode);
5334 }
bool isClipped() const
Returns true if this item is clipped.
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QPointF mapFromItem(const QGraphicsItem *item, const QPointF &point) const
Maps the point point, which is in item&#39;s coordinate system, to this item&#39;s coordinate system...
virtual bool collidesWithPath(const QPainterPath &path, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
Returns true if this item collides with path.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
virtual QPainterPath shape() const
Returns the shape of this item as a QPainterPath in local coordinates.
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
bool isAncestorOf(const QGraphicsItem *child) const
Returns true if this item is an ancestor of child (i.e., if this item is child&#39;s parent, or one of child&#39;s parent&#39;s ancestors).
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
QPainterPath clipPath() const
Returns this item&#39;s clip path, or an empty QPainterPath if this item is not clipped.

◆ 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 5350 of file qgraphicsitem.cpp.

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

5351 {
5352  if (path.isEmpty()) {
5353  // No collision with empty paths.
5354  return false;
5355  }
5356 
5357  QRectF rectA(boundingRect());
5358  _q_adjustRect(&rectA);
5359  QRectF rectB(path.controlPointRect());
5360  _q_adjustRect(&rectB);
5361  if (!rectA.intersects(rectB)) {
5362  // This we can determine efficiently. If the two rects neither
5363  // intersect nor contain eachother, then the two items do not collide.
5364  return false;
5365  }
5366 
5367  // For further testing, we need this item's shape or bounding rect.
5368  QPainterPath thisShape;
5369  if (mode == Qt::IntersectsItemShape || mode == Qt::ContainsItemShape)
5370  thisShape = (isClipped() && !d_ptr->localCollisionHack) ? clipPath() : shape();
5371  else
5372  thisShape.addRect(rectA);
5373 
5374  if (thisShape == QPainterPath()) {
5375  // Empty shape? No collision.
5376  return false;
5377  }
5378 
5379  // Use QPainterPath boolean operations to determine the collision, O(N*logN).
5381  return path.intersects(thisShape);
5382  return path.contains(thisShape);
5383 }
bool isClipped() const
Returns true if this item is clipped.
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
bool intersects(const QRectF &rect) const
Returns true if any point in the given rectangle intersects the path; otherwise returns false...
bool contains(const QPointF &pt) const
Returns true if the given point is inside the path, otherwise returns false.
virtual QPainterPath shape() const
Returns the shape of this item as a QPainterPath in local coordinates.
static void _q_adjustRect(QRect *rect)
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
QRectF controlPointRect() const
Returns the rectangle containing all the points and control points in this path.
QPainterPath clipPath() const
Returns this item&#39;s clip path, or an empty QPainterPath if this item is not clipped.

◆ 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 5395 of file qgraphicsitem.cpp.

5396 {
5397  if (d_ptr->scene)
5398  return d_ptr->scene->collidingItems(this, mode);
5399  return QList<QGraphicsItem *>();
5400 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsScene * scene
QList< QGraphicsItem * > collidingItems(const QGraphicsItem *item, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
Returns a list of all items that collide with item.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ commonAncestorItem()

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

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

Since
4.4
See also
isAncestorOf()

Definition at line 6897 of file qgraphicsitem.cpp.

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

6898 {
6899  if (!other)
6900  return 0;
6901  if (other == this)
6902  return const_cast<QGraphicsItem *>(this);
6903  const QGraphicsItem *thisw = this;
6904  const QGraphicsItem *otherw = other;
6905  int thisDepth = d_ptr->depth();
6906  int otherDepth = other->d_ptr->depth();
6907  while (thisDepth > otherDepth) {
6908  thisw = thisw->d_ptr->parent;
6909  --thisDepth;
6910  }
6911  while (otherDepth > thisDepth) {
6912  otherw = otherw->d_ptr->parent;
6913  --otherDepth;
6914  }
6915  while (thisw && thisw != otherw) {
6916  thisw = thisw->d_ptr->parent;
6917  otherw = otherw->d_ptr->parent;
6918  }
6919  return const_cast<QGraphicsItem *>(thisw);
6920 }
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89

◆ 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 QGraphicsSimpleTextItem, QGraphicsTextItem, QGraphicsPixmapItem, QGraphicsLineItem, QGraphicsPolygonItem, QGraphicsEllipseItem, QGraphicsRectItem, and QGraphicsPathItem.

Definition at line 5273 of file qgraphicsitem.cpp.

Referenced by QGraphicsPathItem::contains(), QGraphicsRectItem::contains(), QGraphicsEllipseItem::contains(), QGraphicsPolygonItem::contains(), QGraphicsLineItem::contains(), QGraphicsPixmapItem::contains(), QGraphicsScenePrivate::gestureEventHandler(), QGraphicsObject::grabGesture(), QGraphicsProxyWidget::hoverMoveEvent(), QGraphicsSceneIndexPointIntersector::intersect(), isUnderMouse(), QDeclarativeMouseArea::mouseMoveEvent(), QDeclarativeTextInput::mouseReleaseEvent(), QDeclarativeTextEdit::mouseReleaseEvent(), QGraphicsWidget::paintWindowFrame(), QDeclarativeTextEdit::positionAt(), qt_QGraphicsItem_isObscured(), and QGraphicsLineItem::setLine().

5274 {
5275  return isClipped() ? clipPath().contains(point) : shape().contains(point);
5276 }
bool isClipped() const
Returns true if this item is clipped.
bool contains(const QPointF &pt) const
Returns true if the given point is inside the path, otherwise returns false.
virtual QPainterPath shape() const
Returns the shape of this item as a QPainterPath in local coordinates.
QPainterPath clipPath() const
Returns this item&#39;s clip path, or an empty QPainterPath if this item is not clipped.

◆ 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:

void CustomItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
QMenu menu;
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, QDeclarativeMouseArea, and QGraphicsProxyWidget.

Definition at line 7248 of file qgraphicsitem.cpp.

Referenced by QDeclarativeMouseArea::contextMenuEvent(), and sceneEvent().

7249 {
7250  event->ignore();
7251 }

◆ 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 list of predefined cursor objects for a range of useful shapes.

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

item->setCursor(Qt::IBeamCursor);

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

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

Definition at line 2256 of file qgraphicsitem.cpp.

Referenced by QGraphicsViewPrivate::_q_unsetViewportCursor(), QDeclarativeTextInput::mouseDoubleClickEvent(), QGraphicsViewPrivate::mouseMoveEventHandler(), QDeclarativeTextInput::mousePressEvent(), QDeclarativeTextInput::moveCursorSelection(), QDeclarativeTextEdit::moveCursorSelection(), QDeclarativeTextInput::positionAt(), QDeclarativeTextEdit::positionAt(), QDeclarativeTextEdit::select(), setCursor(), QDeclarativeTextEdit::setCursorPosition(), and QDeclarativeTextEditPrivate::updateSelection().

2257 {
2259 }
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition: qcursor.h:89
QScopedPointer< QGraphicsItemPrivate > d_ptr
QVariant extra(Extra type) const
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ 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;
QGraphicsItem *item = scene.itemAt(100, 50);
if (item->data(ObjectName).toString().isEmpty()) {
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 6959 of file qgraphicsitem.cpp.

Referenced by QGraphicsWidget::close(), QDeclarativeImplicitSizePaintedItem::drawContents(), QmlJSDebugger::isEditorItem(), QDeclarativeGestureAreaParser::setCustomData(), and QmlJSDebugger::LiveSelectionIndicator::setItems().

6960 {
6961  QGraphicsItemCustomDataStore *store = qt_dataStore();
6962  if (!store->data.contains(this))
6963  return QVariant();
6964  return store->data.value(this).value(key);
6965 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QMap< const QGraphicsItem *, QMap< int, QVariant > > data
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
#define store(x)
int key
bool contains(const Key &key) const
Returns true if the map contains an item with key key; otherwise returns false.
Definition: qmap.h:553

◆ deviceTransform()

QTransform QGraphicsItem::deviceTransform ( const QTransform viewportTransform) const

Returns this item's device transformation matrix, using viewportTransform to map from scene to device coordinates.

Since
4.3

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 4463 of file qgraphicsitem.cpp.

Referenced by QGraphicsScenePrivate::drawSubtreeRecursive(), QGraphicsSceneIndexRectIntersector::intersect(), QGraphicsSceneIndexPointIntersector::intersect(), QGraphicsSceneIndexPathIntersector::intersect(), QGraphicsViewPrivate::mapToViewRect(), QGraphicsViewPrivate::mapToViewRegion(), mouseMoveEvent(), QGraphicsView::paintEvent(), QGraphicsViewPrivate::setUpdateClip(), and updateHelper().

4464 {
4465  // Ensure we return the standard transform if we're not untransformable.
4466  if (!d_ptr->itemIsUntransformable()) {
4468  return d_ptr->sceneTransform * viewportTransform;
4469  }
4470 
4471  // Find the topmost item that ignores view transformations.
4472  const QGraphicsItem *untransformedAncestor = this;
4474  while (untransformedAncestor && ((untransformedAncestor->d_ptr->ancestorFlags
4476  parents.prepend(untransformedAncestor);
4477  untransformedAncestor = untransformedAncestor->parentItem();
4478  }
4479 
4480  if (!untransformedAncestor) {
4481  // Assert in debug mode, continue in release.
4482  Q_ASSERT_X(untransformedAncestor, "QGraphicsItem::deviceTransform",
4483  "Invalid object structure!");
4484  return QTransform();
4485  }
4486 
4487  // Determine the inherited origin. Find the parent of the topmost untransformable.
4488  // Use its scene transform to map the position of the untransformable. Then use
4489  // that viewport position as the anchoring point for the untransformable subtree.
4490  QGraphicsItem *parentOfUntransformedAncestor = untransformedAncestor->parentItem();
4491  QTransform inheritedMatrix;
4492  if (parentOfUntransformedAncestor)
4493  inheritedMatrix = parentOfUntransformedAncestor->sceneTransform();
4494  QPointF mappedPoint = (inheritedMatrix * viewportTransform).map(untransformedAncestor->pos());
4495 
4496  // COMBINE
4497  QTransform matrix = QTransform::fromTranslate(mappedPoint.x(), mappedPoint.y());
4498  if (untransformedAncestor->d_ptr->transformData)
4499  matrix = untransformedAncestor->d_ptr->transformData->computedFullTransform(&matrix);
4500 
4501  // Then transform and translate all children.
4502  for (int i = 0; i < parents.size(); ++i) {
4503  const QGraphicsItem *parent = parents.at(i);
4504  parent->d_ptr->combineTransformFromParent(&matrix);
4505  }
4506 
4507  return matrix;
4508 }
QTransform computedFullTransform(QTransform *postmultiplyTransform=0) const
QScopedPointer< QGraphicsItemPrivate > d_ptr
QTransform sceneTransform() const
Returns this item&#39;s scene transformation matrix.
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QPointF pos() const
Returns the position of the item in parent coordinates.
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QMatrix matrix() const
Returns the item&#39;s affine transformation matrix.
QFuture< void > map(Sequence &sequence, MapFunction function)
bool itemIsUntransformable() const
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
void combineTransformFromParent(QTransform *x, const QTransform *viewTransform=0) const
Combines this item&#39;s position and transform onto transform.
TransformData * transformData
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis...
Definition: qtransform.cpp:462
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ 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()
{
...
}
void CustomItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
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, and QGraphicsProxyWidget.

Definition at line 7276 of file qgraphicsitem.cpp.

Referenced by sceneEvent().

7277 {
7278  Q_D(QGraphicsItem);
7279  // binary compatibility workaround between 4.4 and 4.5
7280  if (d->isProxyWidget())
7281  static_cast<QGraphicsProxyWidget*>(this)->dragEnterEvent(event);
7282 }
double d
Definition: qnumeric_p.h:62
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_D(Class)
Definition: qglobal.h:2482

◆ 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, and QGraphicsProxyWidget.

Definition at line 7300 of file qgraphicsitem.cpp.

Referenced by sceneEvent().

7301 {
7302  Q_D(QGraphicsItem);
7303  // binary compatibility workaround between 4.4 and 4.5
7304  if (d->isProxyWidget())
7305  static_cast<QGraphicsProxyWidget*>(this)->dragLeaveEvent(event);
7306 }
double d
Definition: qnumeric_p.h:62
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_D(Class)
Definition: qglobal.h:2482

◆ 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, and QGraphicsProxyWidget.

Definition at line 7327 of file qgraphicsitem.cpp.

Referenced by sceneEvent().

7328 {
7329  Q_D(QGraphicsItem);
7330  // binary compatibility workaround between 4.4 and 4.5
7331  if (d->isProxyWidget())
7332  static_cast<QGraphicsProxyWidget*>(this)->dragMoveEvent(event);
7333 }
double d
Definition: qnumeric_p.h:62
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_D(Class)
Definition: qglobal.h:2482

◆ 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, and QGraphicsProxyWidget.

Definition at line 7349 of file qgraphicsitem.cpp.

Referenced by sceneEvent().

7350 {
7351  Q_D(QGraphicsItem);
7352  // binary compatibility workaround between 4.4 and 4.5
7353  if (d->isProxyWidget())
7354  static_cast<QGraphicsProxyWidget*>(this)->dropEvent(event);
7355 }
double d
Definition: qnumeric_p.h:62
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_D(Class)
Definition: qglobal.h:2482

◆ effectiveOpacity()

qreal QGraphicsItem::effectiveOpacity ( ) const

Returns this item's effective opacity, which is between 0.

Since
4.5

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 2819 of file qgraphicsitem.cpp.

Referenced by ShaderEffectItem::updateEffectState().

2820 {
2821  return d_ptr->effectiveOpacity();
2822 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
qreal effectiveOpacity() const

◆ 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 4015 of file qgraphicsitem.cpp.

4016 {
4017  if (d_ptr->scene) {
4018  QRectF sceneRect;
4019  if (!rect.isNull())
4020  sceneRect = sceneTransform().mapRect(rect);
4021  else
4022  sceneRect = sceneBoundingRect();
4023  foreach (QGraphicsView *view, d_ptr->scene->d_func()->views)
4024  view->ensureVisible(sceneRect, xmargin, ymargin);
4025  }
4026 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QTransform sceneTransform() const
Returns this item&#39;s scene transformation matrix.
QGraphicsScene * scene
void ensureVisible(const QRectF &rect, int xmargin=50, int ymargin=50)
Scrolls the contents of the viewport so that the scene rectangle rect is visible, with margins specif...
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QList< QGraphicsView * > views() const
Returns a list of all the views that display this scene.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655
QRectF sceneBoundingRect() const
Returns the bounding rect of this item in scene coordinates, by combining sceneTransform() with bound...

◆ 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 503 of file qgraphicsitem.h.

504 { ensureVisible(QRectF(ax, ay, w, h), xmargin, ymargin); }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
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 att...

◆ 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.

Warning
This function is not part of the public interface.

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

Definition at line 7920 of file qgraphicsitem.cpp.

7921 {
7922  Q_UNUSED(variant);
7923  return QVariant();
7924 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ filtersChildEvents()

bool QGraphicsItem::filtersChildEvents ( ) const

Returns true if this item filters child events (i.

Since
4.6

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 3261 of file qgraphicsitem.cpp.

3262 {
3264 }
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ 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 1890 of file qgraphicsitem.cpp.

Referenced by _q_qgraphicsItemSetFlag(), _qt_movableAncestorIsSelected(), QGraphicsItemPrivate::clearFocusHelper(), QGraphicsSceneBspTreeIndexPrivate::climbTree(), collidesWithItem(), QDeclarativeKeysAttached::componentComplete(), QDeclarativeItemPrivate::data(), QDeclarativeTextInput::drawContents(), QGraphicsScene::focusNextPrevChild(), QDeclarativeItem::forceActiveFocus(), QDeclarativeItem::hasFocus(), QDeclarativeKeysAttached::inputMethodEvent(), QDeclarativeKeysAttached::inputMethodQuery(), mouseMoveEvent(), mousePressEvent(), QGraphicsTextItem::mousePressEvent(), QGraphicsScenePrivate::mousePressEventHandler(), mouseReleaseEvent(), QGraphicsItemPrivate::movableAncestorIsSelected(), operator<<(), QGraphicsScenePrivate::removeItemHelper(), QGraphicsItemPrivate::sendScenePosChange(), QGraphicsScenePrivate::sendTouchBeginEvent(), setFlags(), QGraphicsItemPrivate::setFocusHelper(), QGraphicsScenePrivate::setFocusItemHelper(), QDeclarativeTextEdit::setReadOnly(), QGraphicsScene::setSelectionArea(), QGraphicsTextItem::setTextInteractionFlags(), QGraphicsItemPrivate::setVisibleHelper(), QmlJSDebugger::AbstractLiveEditTool::topMovableGraphicsItem(), QGraphicsScene::wheelEvent(), and ~QGraphicsItem().

1891 {
1892  return GraphicsItemFlags(d_ptr->flags);
1893 }
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ 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, QDeclarativeTextEdit, QDeclarativeTextInput, QGraphicsWidget, and QGraphicsProxyWidget.

Definition at line 7364 of file qgraphicsitem.cpp.

Referenced by QDeclarativeTextInput::focusInEvent(), QDeclarativeTextEdit::focusInEvent(), and sceneEvent().

7365 {
7366  Q_UNUSED(event);
7367  update();
7368 }
void update(const QRectF &rect=QRectF())
Schedules a redraw of the area covered by rect in this item.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ focusItem()

QGraphicsItem * QGraphicsItem::focusItem ( ) const

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

Since
4.6

If no descendant has input focus, 0 is returned.

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

Definition at line 3646 of file qgraphicsitem.cpp.

Referenced by QGraphicsScene::addItem(), QDeclarativeItemPrivate::focusChanged(), QDeclarativeItem::hasActiveFocus(), QGraphicsScenePrivate::mousePressEventHandler(), QGraphicsScenePrivate::sendTouchBeginEvent(), QGraphicsScenePrivate::setActivePanelHelper(), QGraphicsItemPrivate::setEnabledHelper(), QGraphicsItemPrivate::setFocusHelper(), QGraphicsItemPrivate::setParentItemHelper(), and QGraphicsItemPrivate::setVisibleHelper().

3647 {
3648  return d_ptr->subFocusItem;
3649 }
QGraphicsItem * subFocusItem
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ 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, QGraphicsWidget, and QGraphicsProxyWidget.

Definition at line 7376 of file qgraphicsitem.cpp.

Referenced by sceneEvent().

7377 {
7378  Q_UNUSED(event);
7379  update();
7380 }
void update(const QRectF &rect=QRectF())
Schedules a redraw of the area covered by rect in this item.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ focusProxy()

QGraphicsItem * QGraphicsItem::focusProxy ( ) const

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

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

Definition at line 3578 of file qgraphicsitem.cpp.

Referenced by QDeclarativeKeysAttachedPrivate::finalFocusProxy(), and setFocusProxy().

3579 {
3580  return d_ptr->focusProxy;
3581 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsItem * focusProxy

◆ focusScopeItem()

QGraphicsItem * QGraphicsItem::focusScopeItem ( ) const

Returns this item's focus scope item.

Warning
This function is not part of the public interface.

Definition at line 3659 of file qgraphicsitem.cpp.

Referenced by QDeclarativeItem::hasFocus().

3660 {
3661  return d_ptr->focusScopeItem;
3662 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsItem * focusScopeItem

◆ grabKeyboard()

void QGraphicsItem::grabKeyboard ( )

Grabs the keyboard input.

Since
4.4

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

  • 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().

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 3769 of file qgraphicsitem.cpp.

3770 {
3771  if (!d_ptr->scene) {
3772  qWarning("QGraphicsItem::grabKeyboard: cannot grab keyboard without scene");
3773  return;
3774  }
3775  if (!d_ptr->visible) {
3776  qWarning("QGraphicsItem::grabKeyboard: cannot grab keyboard while invisible");
3777  return;
3778  }
3779  d_ptr->scene->d_func()->grabKeyboard(this);
3780 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsScene * scene
Q_CORE_EXPORT void qWarning(const char *,...)

◆ grabMouse()

void QGraphicsItem::grabMouse ( )

Grabs the mouse input.

Since
4.4

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

  • 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().

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 3701 of file qgraphicsitem.cpp.

Referenced by QDeclarativePathView::sendMouseEvent(), QDeclarativeMouseArea::sendMouseEvent(), QDeclarativeFlickable::sendMouseEvent(), QDeclarativePinchArea::sendMouseEvent(), and QDeclarativePinchArea::updatePinch().

3702 {
3703  if (!d_ptr->scene) {
3704  qWarning("QGraphicsItem::grabMouse: cannot grab mouse without scene");
3705  return;
3706  }
3707  if (!d_ptr->visible) {
3708  qWarning("QGraphicsItem::grabMouse: cannot grab mouse while invisible");
3709  return;
3710  }
3711  d_ptr->scene->d_func()->grabMouse(this);
3712 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsScene * scene
Q_CORE_EXPORT void qWarning(const char *,...)

◆ graphicsEffect()

QGraphicsEffect * QGraphicsItem::graphicsEffect ( ) const

Returns a pointer to this item's effect if it has one; otherwise 0.

Since
4.6

Definition at line 2892 of file qgraphicsitem.cpp.

Referenced by ShaderEffectSource::attachSourceItem(), ShaderEffectSource::detachSourceItem(), QGraphicsItemPrivate::effectiveBoundingRect(), and ShaderEffectSource::markSourceItemDirty().

2893 {
2894  return d_ptr->graphicsEffect;
2895 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsEffect * graphicsEffect

◆ group()

QGraphicsItemGroup * QGraphicsItem::group ( ) const

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

See also
QGraphicsItemGroup, QGraphicsScene::createItemGroup()

Definition at line 1594 of file qgraphicsitem.cpp.

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

1595 {
1596  if (!d_ptr->isMemberOfGroup)
1597  return 0;
1598  QGraphicsItem *parent = const_cast<QGraphicsItem *>(this);
1599  while ((parent = parent->d_ptr->parent)) {
1600  if (QGraphicsItemGroup *group = qgraphicsitem_cast<QGraphicsItemGroup *>(parent))
1601  return group;
1602  }
1603  // Unreachable; if d_ptr->isMemberOfGroup is != 0, then one parent of this
1604  // item is a group item.
1605  return 0;
1606 }
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsItemGroup * group() const
Returns a pointer to this item&#39;s item group, or 0 if this item is not member of a group...
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
The QGraphicsItemGroup class provides a container that treats a group of items as a single item...

◆ handlesChildEvents()

bool QGraphicsItem::handlesChildEvents ( ) const

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 3309 of file qgraphicsitem.cpp.

3310 {
3311  return d_ptr->handlesChildEvents;
3312 }
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ 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 2309 of file qgraphicsitem.cpp.

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

2310 {
2311  return d_ptr->hasCursor;
2312 }
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ hasFocus()

bool QGraphicsItem::hasFocus ( ) const

Returns true if this item is active, and it or its focus proxy has keyboard input focus; otherwise, returns false.

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

Definition at line 3409 of file qgraphicsitem.cpp.

Referenced by QGraphicsItemPrivate::clearFocusHelper(), QGraphicsWidget::close(), QGraphicsProxyWidget::contextMenuEvent(), QGraphicsWidget::focusNextPrevChild(), hasFocus(), QWidget::hasFocus(), QGraphicsWidget::initStyleOption(), QGraphicsTextItem::mouseDoubleClickEvent(), QGraphicsWidget::paintWindowFrame(), setFlags(), QGraphicsWidget::setFocusPolicy(), setInputMethodHints(), and QGraphicsItemPrivate::setVisibleHelper().

3410 {
3411  if (!d_ptr->scene || !d_ptr->scene->isActive())
3412  return false;
3413 
3414  if (d_ptr->focusProxy)
3415  return d_ptr->focusProxy->hasFocus();
3416 
3417  if (d_ptr->scene->d_func()->focusItem != this)
3418  return false;
3419 
3420  return panel() == d_ptr->scene->d_func()->activePanel;
3421 }
bool hasFocus() const
Returns true if this item is active, and it or its focus proxy has keyboard input focus; otherwise...
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsScene * scene
QGraphicsItem * focusItem() const
When the scene is active, this functions returns the scene&#39;s current focus item, or 0 if no item curr...
QGraphicsItem * panel() const
Returns the item&#39;s panel, or 0 if this item does not have a panel.
QGraphicsItem * activePanel() const
Returns the current active panel, or 0 if no panel is currently active.
bool isActive() const
Returns true if the scene is active (e.
QGraphicsItem * focusProxy

◆ 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 222 of file qgraphicsitem.h.

Referenced by QGraphicsWidget::close(), QmlJSDebugger::BoundingRectHighlighter::freeBoundingBox(), QmlJSDebugger::LiveSelectionRectangle::hide(), QmlJSDebugger::LiveSelectionIndicator::hide(), ShaderEffectSource::hideSource(), and ShaderEffectSource::setHideSource().

222 { setVisible(false); }
void setVisible(bool visible)
If visible is true, the item is made visible.

◆ 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, QDeclarativeMouseArea, and QGraphicsProxyWidget.

Definition at line 7391 of file qgraphicsitem.cpp.

Referenced by QDeclarativeMouseArea::hoverEnterEvent(), and sceneEvent().

7392 {
7393  Q_UNUSED(event);
7394  update();
7395 }
void update(const QRectF &rect=QRectF())
Schedules a redraw of the area covered by rect in this item.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ 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, QGraphicsWidget, QDeclarativeMouseArea, and QGraphicsProxyWidget.

Definition at line 7419 of file qgraphicsitem.cpp.

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

7420 {
7421  Q_UNUSED(event);
7422  update();
7423 }
void update(const QRectF &rect=QRectF())
Schedules a redraw of the area covered by rect in this item.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ 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, QGraphicsWidget, QDeclarativeMouseArea, and QGraphicsProxyWidget.

Definition at line 7405 of file qgraphicsitem.cpp.

Referenced by QDeclarativeMouseArea::hoverMoveEvent(), and sceneEvent().

7406 {
7407  Q_UNUSED(event);
7408 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ 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, QDeclarativeTextEdit, QDeclarativeTextInput, and QDeclarativeItem.

Definition at line 7752 of file qgraphicsitem.cpp.

Referenced by sceneEvent().

7753 {
7754  event->ignore();
7755 }

◆ 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(), QInputContext

Definition at line 7793 of file qgraphicsitem.cpp.

Referenced by QDeclarativeTextInputPrivate::updateInputMethodHints().

7794 {
7795  Q_D(const QGraphicsItem);
7796  return d->imHints;
7797 }
double d
Definition: qnumeric_p.h:62
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_D(Class)
Definition: qglobal.h:2482

◆ 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, QInputContext

Reimplemented in QGraphicsTextItem, QDeclarativeTextInput, QDeclarativeTextEdit, and QDeclarativeItem.

Definition at line 7766 of file qgraphicsitem.cpp.

Referenced by QDeclarativeItemAccessor::doInputMethodQuery(), and QDeclarativeItem::inputMethodQuery().

7767 {
7768  if (isWidget()) {
7769  // ### Qt 5: Remove. The reimplementation in
7770  // QGraphicsProxyWidget solves this problem (but requires a
7771  // recompile to take effect).
7772  return d_ptr->inputMethodQueryHelper(query);
7773  }
7774 
7775  Q_UNUSED(query);
7776  return QVariant();
7777 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QScopedPointer< QGraphicsItemPrivate > d_ptr
bool isWidget() const
Returns true if this item is a widget (i.
virtual QVariant inputMethodQueryHelper(Qt::InputMethodQuery query) const
This helper function helped us add input method query support in Qt 4.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ 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:

QGraphicsEllipseItem *ellipse = scene.addEllipse(QRectF(-10, -10, 20, 20));
QGraphicsLineItem *line = scene.addLine(QLineF(-10, -10, 20, 20));
line->installSceneEventFilter(ellipse);
// line's events are filtered by ellipse's sceneEventFilter() function.
ellipse->installSceneEventFilter(line);
// 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 7037 of file qgraphicsitem.cpp.

7038 {
7039  if (!d_ptr->scene) {
7040  qWarning("QGraphicsItem::installSceneEventFilter: event filters can only be installed"
7041  " on items in a scene.");
7042  return;
7043  }
7044  if (d_ptr->scene != filterItem->scene()) {
7045  qWarning("QGraphicsItem::installSceneEventFilter: event filters can only be installed"
7046  " on items in the same scene.");
7047  return;
7048  }
7049  d_ptr->scene->d_func()->installSceneEventFilter(this, filterItem);
7050 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsScene * scene
Q_CORE_EXPORT void qWarning(const char *,...)
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.

◆ isActive()

bool QGraphicsItem::isActive ( ) const

Returns true if this item is active; otherwise returns false.

Since
4.6

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 3363 of file qgraphicsitem.cpp.

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

3364 {
3365  if (!d_ptr->scene || !d_ptr->scene->isActive())
3366  return false;
3367  return panel() == d_ptr->scene->activePanel();
3368 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsScene * scene
QGraphicsItem * panel() const
Returns the item&#39;s panel, or 0 if this item does not have a panel.
QGraphicsItem * activePanel() const
Returns the current active panel, or 0 if no panel is currently active.
bool isActive() const
Returns true if the scene is active (e.

◆ 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 6872 of file qgraphicsitem.cpp.

Referenced by QGraphicsScenePrivate::cancelGesturesForChildren(), QGraphicsItemPrivate::clearSubFocus(), collidesWithItem(), QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(), QGraphicsScene::focusNextPrevChild(), isBlockedByModalPanel(), itemTransform(), QGraphicsItemPrivate::setParentItemHelper(), and QGraphicsItemPrivate::setVisibleHelper().

6873 {
6874  if (!child || child == this)
6875  return false;
6876  if (child->d_ptr->depth() < d_ptr->depth())
6877  return false;
6878  const QGraphicsItem *ancestor = child;
6879  while ((ancestor = ancestor->d_ptr->parent)) {
6880  if (ancestor == this)
6881  return true;
6882  }
6883  return false;
6884 }
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89

◆ isBlockedByModalPanel()

bool QGraphicsItem::isBlockedByModalPanel ( QGraphicsItem **  blockingPanel = 0) const

Returns true if this item is blocked by a modal panel, false otherwise.

Since
4.6

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 2175 of file qgraphicsitem.cpp.

Referenced by QGraphicsScenePrivate::enterModal(), QGraphicsScenePrivate::itemAcceptsHoverEvents_helper(), QGraphicsScene::keyPressEvent(), QGraphicsScene::keyReleaseEvent(), QGraphicsScenePrivate::leaveModal(), QGraphicsScenePrivate::mousePressEventHandler(), and QGraphicsScenePrivate::sendMouseEvent().

2176 {
2177  if (!d_ptr->scene)
2178  return false;
2179 
2180 
2181  QGraphicsItem *dummy = 0;
2182  if (!blockingPanel)
2183  blockingPanel = &dummy;
2184 
2185  QGraphicsScenePrivate *scene_d = d_ptr->scene->d_func();
2186  if (scene_d->modalPanels.isEmpty())
2187  return false;
2188 
2189  // ###
2190  if (!scene_d->popupWidgets.isEmpty() && scene_d->popupWidgets.first() == this)
2191  return false;
2192 
2193  for (int i = 0; i < scene_d->modalPanels.count(); ++i) {
2194  QGraphicsItem *modalPanel = scene_d->modalPanels.at(i);
2195  if (modalPanel->panelModality() == QGraphicsItem::SceneModal) {
2196  // Scene modal panels block all non-descendents.
2197  if (modalPanel != this && !modalPanel->isAncestorOf(this)) {
2198  *blockingPanel = modalPanel;
2199  return true;
2200  }
2201  } else {
2202  // Window modal panels block ancestors and siblings/cousins.
2203  if (modalPanel != this
2204  && !modalPanel->isAncestorOf(this)
2205  && commonAncestorItem(modalPanel)) {
2206  *blockingPanel = modalPanel;
2207  return true;
2208  }
2209  }
2210  }
2211  return false;
2212 }
QGraphicsItem * commonAncestorItem(const QGraphicsItem *other) const
Returns the closest common ancestor item of this item and other, or 0 if either other is 0...
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QGraphicsScene * scene
QList< QGraphicsItem * > modalPanels
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
PanelModality panelModality() const
Returns the modality for this item.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool isAncestorOf(const QGraphicsItem *child) const
Returns true if this item is an ancestor of child (i.e., if this item is child&#39;s parent, or one of child&#39;s parent&#39;s ancestors).
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
QList< QGraphicsWidget * > popupWidgets

◆ isClipped()

bool QGraphicsItem::isClipped ( ) const

Returns true if this item is clipped.

An item is clipped if it has either set the ItemClipsToShape flag, or if it or any of its ancestors has set the 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 5185 of file qgraphicsitem.cpp.

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

5186 {
5187  Q_D(const QGraphicsItem);
5188  return (d->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren)
5189  || (d->flags & QGraphicsItem::ItemClipsToShape);
5190 }
double d
Definition: qnumeric_p.h:62
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_D(Class)
Definition: qglobal.h:2482

◆ isEnabled()

bool QGraphicsItem::isEnabled ( ) const

◆ isObscured() [1/3]

bool QGraphicsItem::isObscured ( ) const

Returns true if this item's bounding 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).

Its implementation is based on calling isObscuredBy(), which you can reimplement to provide a custom obscurity algorithm.

See also
opaqueArea()

Definition at line 5412 of file qgraphicsitem.cpp.

5413 {
5414  return isObscured(QRectF());
5415 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
bool isObscured() const
Returns true if this item&#39;s bounding rect is completely obscured by the opaque shape of any of collid...

◆ isObscured() [2/3]

bool QGraphicsItem::isObscured ( const QRectF rect) const

Returns true if rect is completely obscured by the opaque shape of any of colliding items above it (i.

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

e., with a higher Z value than this item).

Unlike the default isObscured() function, this function does not call
isObscuredBy().

\sa opaqueArea()

Definition at line 5452 of file qgraphicsitem.cpp.

5453 {
5454  Q_D(const QGraphicsItem);
5455  if (!d->scene)
5456  return false;
5457 
5458  QRectF br = boundingRect();
5459  QRectF testRect = rect.isNull() ? br : rect;
5460 
5461  foreach (QGraphicsItem *item, d->scene->items(mapToScene(br), Qt::IntersectsItemBoundingRect)) {
5462  if (item == this)
5463  break;
5464  if (qt_QGraphicsItem_isObscured(this, item, testRect))
5465  return true;
5466  }
5467  return false;
5468 }
double d
Definition: qnumeric_p.h:62
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_D(Class)
Definition: qglobal.h:2482
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
static bool qt_QGraphicsItem_isObscured(const QGraphicsItem *item, const QGraphicsItem *other, const QRectF &rect)
Item obscurity helper function.
QPointF mapToScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to the scene&#39;s coordinate system...
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655

◆ isObscured() [3/3]

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

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

Since
4.3

Definition at line 507 of file qgraphicsitem.h.

508 { return isObscured(QRectF(ax, ay, w, h)); }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
bool isObscured() const
Returns true if this item&#39;s bounding rect is completely obscured by the opaque shape of any of collid...

◆ 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 QGraphicsItemGroup, QGraphicsSimpleTextItem, QGraphicsTextItem, QGraphicsPixmapItem, QGraphicsLineItem, QGraphicsPolygonItem, QGraphicsEllipseItem, QGraphicsRectItem, QGraphicsPathItem, and QAbstractGraphicsShapeItem.

Definition at line 5493 of file qgraphicsitem.cpp.

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

5494 {
5495  if (!item)
5496  return false;
5497  return qt_closestItemFirst(item, this)
5498  && qt_QGraphicsItem_isObscured(this, item, boundingRect());
5499 }
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
static bool qt_QGraphicsItem_isObscured(const QGraphicsItem *item, const QGraphicsItem *other, const QRectF &rect)
Item obscurity helper function.
friend bool qt_closestItemFirst(const QGraphicsItem *, const QGraphicsItem *)
Returns true if item1 is on top of item2.

◆ isPanel()

bool QGraphicsItem::isPanel ( ) const

◆ 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 2714 of file qgraphicsitem.cpp.

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

2715 {
2716  if (QGraphicsItemGroup *group = this->group())
2717  return group->isSelected();
2718  return d_ptr->selected;
2719 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsItemGroup * group() const
Returns a pointer to this item&#39;s item group, or 0 if this item is not member of a group...
bool isSelected() const
Returns true if this item is selected; otherwise, false is returned.
The QGraphicsItemGroup class provides a container that treats a group of items as a single item...

◆ isUnderMouse()

bool QGraphicsItem::isUnderMouse ( ) const

Returns true if this item is currently under the mouse cursor in one of the views; otherwise, false is returned.

Since
4,4
See also
QGraphicsScene::views(), QCursor::pos()

Definition at line 6932 of file qgraphicsitem.cpp.

Referenced by QGraphicsWidget::initStyleOption(), QDeclarativeMouseArea::itemChange(), and QDeclarativeMouseArea::setHoverEnabled().

6933 {
6934  Q_D(const QGraphicsItem);
6935  if (!d->scene)
6936  return false;
6937 
6938  QPoint cursorPos = QCursor::pos();
6939  foreach (QGraphicsView *view, d->scene->views()) {
6940  if (contains(mapFromScene(view->mapToScene(view->mapFromGlobal(cursorPos)))))
6941  return true;
6942  }
6943  return false;
6944 }
double d
Definition: qnumeric_p.h:62
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_D(Class)
Definition: qglobal.h:2482
QPointF mapFromScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s scene&#39;s coordinate system, to this item&#39;s coordinate sy...
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
virtual bool contains(const QPointF &point) const
Returns true if this item contains point, which is in local coordinates; otherwise, false is returned.
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310

◆ 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 2343 of file qgraphicsitem.cpp.

Referenced by QGraphicsScene::addItem(), QGraphicsWidget::close(), QShortcutMap::correctGraphicsWidgetContext(), QDeclarativeGrid::doPositioning(), QGraphicsScene::event(), QDeclarativePinchArea::event(), ShaderEffectItem::handleVisibilityChange(), QDeclarativeItem::hasActiveFocus(), QDeclarativeKeysAttached::inputMethodEvent(), QDeclarativeKeysAttached::inputMethodQuery(), QGraphicsProxyWidget::itemChange(), QDeclarativeMouseArea::itemChange(), QDeclarativeKeysAttached::keyPressed(), QDeclarativeKeysAttached::keyReleased(), QGraphicsScenePrivate::removeItemHelper(), QGraphicsScenePrivate::removePopup(), sceneEvent(), QDeclarativePathView::sceneEventFilter(), QDeclarativeFlickable::sceneEventFilter(), QDeclarativeMouseArea::sceneEventFilter(), QDeclarativePinchArea::sceneEventFilter(), QGraphicsScenePrivate::setActivePanelHelper(), QGraphicsItemPrivate::setFocusHelper(), QGraphicsScenePrivate::setFocusItemHelper(), QDeclarativeKeyNavigationAttached::setFocusNavigation(), setPanelModality(), QGraphicsItemPrivate::setVisibleHelper(), QGraphicsWidget::setWindowFlags(), ShaderEffectItem::ShaderEffectItem(), and QGraphicsWidget::updateGeometry().

2344 {
2345  return d_ptr->visible;
2346 }
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ isVisibleTo()

bool QGraphicsItem::isVisibleTo ( const QGraphicsItem parent) const

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

Since
4.4 parent can be 0, 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 2364 of file qgraphicsitem.cpp.

Referenced by QGraphicsScene::focusNextPrevChild().

2365 {
2366  const QGraphicsItem *p = this;
2367  if (d_ptr->explicitlyHidden)
2368  return false;
2369  do {
2370  if (p == parent)
2371  return true;
2372  if (p->d_ptr->explicitlyHidden)
2373  return false;
2374  } while ((p = p->d_ptr->parent));
2375  return parent == 0;
2376 }
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89

◆ isWidget()

bool QGraphicsItem::isWidget ( ) const

Returns true if this item is a widget (i.

Since
4.4 e., QGraphicsWidget); otherwise, returns false.

Definition at line 1847 of file qgraphicsitem.cpp.

Referenced by _q_paintItem(), QDeclarativeLoaderPrivate::_q_updateSize(), QGraphicsLayoutPrivate::addChildLayoutItem(), QGraphicsScene::addItem(), QShortcutMap::correctGraphicsWidgetContext(), QGraphicsScenePrivate::drawItemHelper(), QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(), QGraphicsScene::focusNextPrevChild(), QDeclarativeLoaderPrivate::initResize(), inputMethodQuery(), QGraphicsWidget::itemChange(), QGraphicsSceneIndexPrivate::itemCollidesWithPath(), QGraphicsScenePrivate::mousePressEventHandler(), parentWidget(), QGraphicsLayout::QGraphicsLayout(), QGraphicsLayoutPrivate::reparentChildItems(), QGraphicsScenePrivate::sendTouchBeginEvent(), QGraphicsItemPrivate::setEnabledHelper(), QGraphicsWidgetPrivate::setLayoutDirection_helper(), QGraphicsItemPrivate::setParentItemHelper(), QGraphicsScene::setStyle(), QGraphicsItemPrivate::setVisibleHelper(), QGraphicsGridLayoutPrivate::styleInfo(), QGraphicsLinearLayoutPrivate::styleInfo(), QGraphicsAnchorLayoutPrivate::styleInfo(), topLevelWidget(), QGraphicsProxyWidgetPrivate::unembedSubWindow(), QGraphicsWidgetPrivate::updateFont(), QGraphicsWidgetPrivate::updatePalette(), QGraphicsScene::wheelEvent(), and QGraphicsWidget::~QGraphicsWidget().

1848 {
1849  return d_ptr->isWidget;
1850 }
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ isWindow()

bool QGraphicsItem::isWindow ( ) const

Returns true if the item is a QGraphicsWidget window, otherwise returns false.

Since
4.4
See also
QGraphicsWidget::windowFlags()

Definition at line 1862 of file qgraphicsitem.cpp.

Referenced by _q_paintItem(), QGraphicsProxyWidget::event(), QGraphicsWidget::focusNextPrevChild(), QGraphicsWidget::initStyleOption(), QGraphicsSceneIndexPrivate::itemCollidesWithPath(), QGraphicsScene::setActiveWindow(), QGraphicsWidgetPrivate::updateFont(), QGraphicsWidgetPrivate::updatePalette(), and window().

1863 {
1864  return d_ptr->isWidget && (static_cast<const QGraphicsWidget *>(this)->windowType() & Qt::Window);
1865 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ 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, your 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();
QRectF rect = scene()->sceneRect();
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;
}
}
return QGraphicsItem::itemChange(change, value);
}

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 QDeclarativePinchArea, QDeclarativeMouseArea, QGraphicsWidget, QDeclarativeItem, QDeclarativePaintedItem, QDeclarativeLoader, QDeclarativeRepeater, QDeclarativeBasePositioner, and QGraphicsProxyWidget.

Definition at line 7875 of file qgraphicsitem.cpp.

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

7876 {
7877  Q_UNUSED(change);
7878  return value;
7879 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ itemTransform()

QTransform QGraphicsItem::itemTransform ( const QGraphicsItem other,
bool *  ok = 0 
) const

Returns a QTransform that maps coordinates from this item to other.

Since
4.5

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 4530 of file qgraphicsitem.cpp.

Referenced by QGraphicsItemGroup::addToGroup(), clipPath(), QDeclarativeParentChangePrivate::doChange(), itemTransform(), mapFromItem(), mapRectFromItem(), mapRectToItem(), mapToItem(), mouseMoveEvent(), QGraphicsItemGroup::removeFromGroup(), and QDeclarativeParentAnimation::transition().

4531 {
4532  // Catch simple cases first.
4533  if (other == 0) {
4534  qWarning("QGraphicsItem::itemTransform: null pointer passed");
4535  return QTransform();
4536  }
4537  if (other == this) {
4538  if (ok)
4539  *ok = true;
4540  return QTransform();
4541  }
4542 
4543  QGraphicsItem *parent = d_ptr->parent;
4544  const QGraphicsItem *otherParent = other->d_ptr->parent;
4545 
4546  // This is other's child
4547  if (parent == other) {
4548  if (ok)
4549  *ok = true;
4550  QTransform x;
4552  return x;
4553  }
4554 
4555  // This is other's parent
4556  if (otherParent == this) {
4557  const QPointF &otherPos = other->d_ptr->pos;
4558  if (other->d_ptr->transformData) {
4559  QTransform otherToParent;
4560  other->d_ptr->combineTransformFromParent(&otherToParent);
4561  return otherToParent.inverted(ok);
4562  }
4563  if (ok)
4564  *ok = true;
4565  return QTransform::fromTranslate(-otherPos.x(), -otherPos.y());
4566  }
4567 
4568  // Siblings
4569  if (parent == otherParent) {
4570  // COMBINE
4571  const QPointF &itemPos = d_ptr->pos;
4572  const QPointF &otherPos = other->d_ptr->pos;
4573  if (!d_ptr->transformData && !other->d_ptr->transformData) {
4574  QPointF delta = itemPos - otherPos;
4575  if (ok)
4576  *ok = true;
4577  return QTransform::fromTranslate(delta.x(), delta.y());
4578  }
4579 
4580  QTransform itemToParent;
4581  d_ptr->combineTransformFromParent(&itemToParent);
4582  QTransform otherToParent;
4583  other->d_ptr->combineTransformFromParent(&otherToParent);
4584  return itemToParent * otherToParent.inverted(ok);
4585  }
4586 
4587  // Find the closest common ancestor. If the two items don't share an
4588  // ancestor, then the only way is to combine their scene transforms.
4589  const QGraphicsItem *commonAncestor = commonAncestorItem(other);
4590  if (!commonAncestor) {
4592  other->d_ptr->ensureSceneTransform();
4593  return d_ptr->sceneTransform * other->d_ptr->sceneTransform.inverted(ok);
4594  }
4595 
4596  // If the two items are cousins (in sibling branches), map both to the
4597  // common ancestor, and combine the two transforms.
4598  bool cousins = other != commonAncestor && this != commonAncestor;
4599  if (cousins) {
4600  bool good = false;
4601  QTransform thisToScene = itemTransform(commonAncestor, &good);
4602  QTransform otherToScene(Qt::Uninitialized);
4603  if (good)
4604  otherToScene = other->itemTransform(commonAncestor, &good);
4605  if (!good) {
4606  if (ok)
4607  *ok = false;
4608  return QTransform();
4609  }
4610  return thisToScene * otherToScene.inverted(ok);
4611  }
4612 
4613  // One is an ancestor of the other; walk the chain.
4614  bool parentOfOther = isAncestorOf(other);
4615  const QGraphicsItem *child = parentOfOther ? other : this;
4616  const QGraphicsItem *root = parentOfOther ? this : other;
4617 
4618  QTransform x;
4619  const QGraphicsItem *p = child;
4620  do {
4622  } while ((p = p->d_ptr->parent) && p != root);
4623  if (parentOfOther)
4624  return x.inverted(ok);
4625  if (ok)
4626  *ok = true;
4627  return x;
4628 }
QGraphicsItem * parent
QGraphicsItem * commonAncestorItem(const QGraphicsItem *other) const
Returns the closest common ancestor item of this item and other, or 0 if either other is 0...
QScopedPointer< QGraphicsItemPrivate > d_ptr
T * data() const
Returns the value of the pointer referenced by this object.
QTransform itemTransform(const QGraphicsItem *other, bool *ok=0) const
Returns a QTransform that maps coordinates from this item to other.
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
void combineTransformToParent(QTransform *x, const QTransform *viewTransform=0) const
Combines this item&#39;s position and transform onto transform.
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
Q_CORE_EXPORT void qWarning(const char *,...)
bool isAncestorOf(const QGraphicsItem *child) const
Returns true if this item is an ancestor of child (i.e., if this item is child&#39;s parent, or one of child&#39;s parent&#39;s ancestors).
qreal x() const
This convenience function is equivalent to calling pos().
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
void combineTransformFromParent(QTransform *x, const QTransform *viewTransform=0) const
Combines this item&#39;s position and transform onto transform.
TransformData * transformData
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis...
Definition: qtransform.cpp:462
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ 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, QDeclarativeTextEdit, QDeclarativeTextInput, QDeclarativeListView, QDeclarativeGridView, QDeclarativeItem, and QGraphicsProxyWidget.

Definition at line 7437 of file qgraphicsitem.cpp.

Referenced by sceneEvent().

7438 {
7439  event->ignore();
7440 }

◆ 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, QDeclarativeTextEdit, QDeclarativeItem, and QGraphicsProxyWidget.

Definition at line 7454 of file qgraphicsitem.cpp.

Referenced by sceneEvent().

7455 {
7456  event->ignore();
7457 }

◆ mapFromItem() [1/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 0, this function returns the same as mapFromScene().

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

Definition at line 6633 of file qgraphicsitem.cpp.

Referenced by QGraphicsItemGroup::addToGroup(), collidesWithItem(), and QGraphicsItemPrivate::remapItemPos().

6634 {
6635  if (item)
6636  return item->itemTransform(this).map(point);
6637  return mapFromScene(point);
6638 }
QTransform itemTransform(const QGraphicsItem *other, bool *ok=0) const
Returns a QTransform that maps coordinates from this item to other.
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
QPointF mapFromScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s scene&#39;s coordinate system, to this item&#39;s coordinate sy...

◆ mapFromItem() [2/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 0, this function returns the same as mapFromScene()

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

Definition at line 6711 of file qgraphicsitem.cpp.

6712 {
6713  if (item)
6714  return item->itemTransform(this).map(rect);
6715  return mapFromScene(rect);
6716 }
QTransform itemTransform(const QGraphicsItem *other, bool *ok=0) const
Returns a QTransform that maps coordinates from this item to other.
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
QPointF mapFromScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s scene&#39;s coordinate system, to this item&#39;s coordinate sy...

◆ 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 0, this function returns the same as mapFromScene().

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

Definition at line 6785 of file qgraphicsitem.cpp.

6786 {
6787  if (item)
6788  return item->itemTransform(this).map(polygon);
6789  return mapFromScene(polygon);
6790 }
QTransform itemTransform(const QGraphicsItem *other, bool *ok=0) const
Returns a QTransform that maps coordinates from this item to other.
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
QPointF mapFromScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s scene&#39;s coordinate system, to this item&#39;s coordinate sy...

◆ mapFromItem() [4/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 0, this function returns the same as mapFromScene().

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

Definition at line 6830 of file qgraphicsitem.cpp.

6831 {
6832  if (item)
6833  return item->itemTransform(this).map(path);
6834  return mapFromScene(path);
6835 }
QTransform itemTransform(const QGraphicsItem *other, bool *ok=0) const
Returns a QTransform that maps coordinates from this item to other.
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
QPointF mapFromScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s scene&#39;s coordinate system, to this item&#39;s coordinate sy...

◆ 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 515 of file qgraphicsitem.h.

516 { return mapFromItem(item, QPointF(ax, ay)); }
QPointF mapFromItem(const QGraphicsItem *item, const QPointF &point) const
Maps the point point, which is in item&#39;s coordinate system, to this item&#39;s coordinate system...
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214

◆ 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 533 of file qgraphicsitem.h.

534 { return mapFromItem(item, QRectF(ax, ay, w, h)); }
QPointF mapFromItem(const QGraphicsItem *item, const QPointF &point) const
Maps the point point, which is in item&#39;s coordinate system, to this item&#39;s coordinate system...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ mapFromParent() [1/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 6656 of file qgraphicsitem.cpp.

6657 {
6658  // COMBINE
6659  if (d_ptr->transformData)
6660  return d_ptr->transformToParent().inverted().map(point);
6661  return point - d_ptr->pos;
6662 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
TransformData * transformData
QTransform transformToParent() const

◆ mapFromParent() [2/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 6733 of file qgraphicsitem.cpp.

6734 {
6735  // COMBINE
6736  if (!d_ptr->transformData)
6737  return rect.translated(-d_ptr->pos);
6738  return d_ptr->transformToParent().inverted().map(rect);
6739 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
TransformData * transformData
QTransform transformToParent() const
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740

◆ 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 6799 of file qgraphicsitem.cpp.

6800 {
6801  // COMBINE
6802  if (!d_ptr->transformData)
6803  return polygon.translated(-d_ptr->pos);
6804  return d_ptr->transformToParent().inverted().map(polygon);
6805 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
QPolygonF translated(qreal dx, qreal dy) const
Returns a copy of the polygon that is translated by ({dx}, {dy}).
Definition: qpolygon.h:182
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
TransformData * transformData
QTransform transformToParent() const

◆ mapFromParent() [4/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 6844 of file qgraphicsitem.cpp.

6845 {
6846  // COMBINE
6847  if (!d_ptr->transformData)
6848  return path.translated(-d_ptr->pos);
6849  return d_ptr->transformToParent().inverted().map(path);
6850 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
TransformData * transformData
QTransform transformToParent() const
QPainterPath translated(qreal dx, qreal dy) const
Returns a copy of the path that is translated by ({dx}, {dy}).

◆ mapFromParent() [5/6]

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

This convenience function is equivalent to calling mapFromParent(QPointF(x, y)).

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

Definition at line 517 of file qgraphicsitem.h.

518 { return mapFromParent(QPointF(ax, ay)); }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPointF mapFromParent(const QPointF &point) const
Maps the point point, which is in this item&#39;s parent&#39;s coordinate system, to this item&#39;s coordinate s...

◆ mapFromParent() [6/6]

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

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

Since
4.3

Definition at line 535 of file qgraphicsitem.h.

536 { return mapFromParent(QRectF(ax, ay, w, h)); }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QPointF mapFromParent(const QPointF &point) const
Maps the point point, which is in this item&#39;s parent&#39;s coordinate system, to this item&#39;s coordinate s...

◆ mapFromScene() [1/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 6683 of file qgraphicsitem.cpp.

Referenced by QGraphicsProxyWidget::event(), QDeclarativeMouseArea::geometryChanged(), isUnderMouse(), mapFromItem(), QDeclarativeMouseArea::mouseMoveEvent(), mouseMoveEvent(), QmlJSDebugger::LiveSelectionRectangle::rect(), QDeclarativePathView::sendMouseEvent(), QDeclarativeMouseArea::sendMouseEvent(), QDeclarativeFlickable::sendMouseEvent(), QDeclarativePinchArea::sendMouseEvent(), QDeclarativePinchArea::updatePinch(), and QGraphicsScenePrivate::updateTouchPointsForItem().

6684 {
6686  return QPointF(point.x() - d_ptr->sceneTransform.dx(), point.y() - d_ptr->sceneTransform.dy());
6687  return d_ptr->sceneTransform.inverted().map(point);
6688 }
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
QScopedPointer< QGraphicsItemPrivate > d_ptr
bool hasTranslateOnlySceneTransform()
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ mapFromScene() [2/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 6759 of file qgraphicsitem.cpp.

6760 {
6762  return rect.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());
6763  return d_ptr->sceneTransform.inverted().map(rect);
6764 }
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
QScopedPointer< QGraphicsItemPrivate > d_ptr
bool hasTranslateOnlySceneTransform()
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740

◆ 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 6814 of file qgraphicsitem.cpp.

6815 {
6817  return polygon.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());
6818  return d_ptr->sceneTransform.inverted().map(polygon);
6819 }
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
QScopedPointer< QGraphicsItemPrivate > d_ptr
bool hasTranslateOnlySceneTransform()
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
QPolygonF translated(qreal dx, qreal dy) const
Returns a copy of the polygon that is translated by ({dx}, {dy}).
Definition: qpolygon.h:182
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273

◆ mapFromScene() [4/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 6859 of file qgraphicsitem.cpp.

6860 {
6862  return path.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());
6863  return d_ptr->sceneTransform.inverted().map(path);
6864 }
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
QScopedPointer< QGraphicsItemPrivate > d_ptr
bool hasTranslateOnlySceneTransform()
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
QPainterPath translated(qreal dx, qreal dy) const
Returns a copy of the path that is translated by ({dx}, {dy}).

◆ mapFromScene() [5/6]

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

This convenience function is equivalent to calling mapFromScene(QPointF(x, y)).

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

Definition at line 519 of file qgraphicsitem.h.

520 { return mapFromScene(QPointF(ax, ay)); }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPointF mapFromScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s scene&#39;s coordinate system, to this item&#39;s coordinate sy...

◆ mapFromScene() [6/6]

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

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

Since
4.3

Definition at line 537 of file qgraphicsitem.h.

538 { return mapFromScene(QRectF(ax, ay, w, h)); }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QPointF mapFromScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s scene&#39;s coordinate system, to this item&#39;s coordinate sy...

◆ mapRectFromItem() [1/2]

QRectF QGraphicsItem::mapRectFromItem ( 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 new rectangle (i.

Since
4.5

e., the bounding rectangle of the resulting polygon).

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

\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}

Definition at line 6454 of file qgraphicsitem.cpp.

6455 {
6456  if (item)
6457  return item->itemTransform(this).mapRect(rect);
6458  return mapRectFromScene(rect);
6459 }
QTransform itemTransform(const QGraphicsItem *other, bool *ok=0) const
Returns a QTransform that maps coordinates from this item to other.
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
QRectF mapRectFromScene(const QRectF &rect) const
Maps the rectangle rect, which is in scene coordinates, to this item&#39;s coordinate system...

◆ 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 539 of file qgraphicsitem.h.

540 { return mapRectFromItem(item, QRectF(ax, ay, w, h)); }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QRectF mapRectFromItem(const QGraphicsItem *item, const QRectF &rect) const
Maps the rectangle rect, which is in item&#39;s coordinate system, to this item&#39;s coordinate system...

◆ mapRectFromParent() [1/2]

QRectF QGraphicsItem::mapRectFromParent ( 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 new rectangle (i.

Since
4.5

e., the bounding rectangle of the resulting polygon).

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

Definition at line 6482 of file qgraphicsitem.cpp.

6483 {
6484  // COMBINE
6485  if (!d_ptr->transformData)
6486  return rect.translated(-d_ptr->pos);
6487  return d_ptr->transformToParent().inverted().mapRect(rect);
6488 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
TransformData * transformData
QTransform transformToParent() const
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740

◆ mapRectFromParent() [2/2]

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

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

Since
4.5

Definition at line 541 of file qgraphicsitem.h.

542 { return mapRectFromParent(QRectF(ax, ay, w, h)); }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QRectF mapRectFromParent(const QRectF &rect) const
Maps the rectangle rect, which is in this item&#39;s parent&#39;s coordinate system, to this item&#39;s coordinat...

◆ mapRectFromScene() [1/2]

QRectF QGraphicsItem::mapRectFromScene ( const QRectF rect) const

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.

Since
4.5

e., the bounding rectangle of the resulting polygon).

\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}

Definition at line 6513 of file qgraphicsitem.cpp.

Referenced by QmlJSDebugger::BoundingRectHighlighter::highlightAll(), mapRectFromItem(), and QmlJSDebugger::LiveSelectionIndicator::setItems().

6514 {
6516  return rect.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());
6517  return d_ptr->sceneTransform.inverted().mapRect(rect);
6518 }
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
QScopedPointer< QGraphicsItemPrivate > d_ptr
bool hasTranslateOnlySceneTransform()
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740

◆ mapRectFromScene() [2/2]

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

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

Since
4.5

Definition at line 543 of file qgraphicsitem.h.

544 { return mapRectFromScene(QRectF(ax, ay, w, h)); }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QRectF mapRectFromScene(const QRectF &rect) const
Maps the rectangle rect, which is in scene coordinates, to this item&#39;s coordinate system...

◆ mapRectToItem() [1/2]

QRectF QGraphicsItem::mapRectToItem ( 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 new rectangle (i.

Since
4.5

e., the bounding rectangle of the resulting polygon).

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

\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}

Definition at line 6364 of file qgraphicsitem.cpp.

Referenced by QGraphicsItemPrivate::effectiveBoundingRect().

6365 {
6366  if (item)
6367  return itemTransform(item).mapRect(rect);
6368  return mapRectToScene(rect);
6369 }
QTransform itemTransform(const QGraphicsItem *other, bool *ok=0) const
Returns a QTransform that maps coordinates from this item to other.
QRectF mapRectToScene(const QRectF &rect) const
Maps the rectangle rect, which is in this item&#39;s coordinate system, to the scene coordinate system...
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...

◆ 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 527 of file qgraphicsitem.h.

528 { return mapRectToItem(item, QRectF(ax, ay, w, h)); }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QRectF mapRectToItem(const QGraphicsItem *item, const QRectF &rect) const
Maps the rectangle rect, which is in this item&#39;s coordinate system, to item&#39;s coordinate system...

◆ mapRectToParent() [1/2]

QRectF QGraphicsItem::mapRectToParent ( 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 new rectangle (i.

Since
4.5

e., the bounding rectangle of the resulting polygon).

\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}

Definition at line 6391 of file qgraphicsitem.cpp.

6392 {
6393  // COMBINE
6394  if (!d_ptr->transformData)
6395  return rect.translated(d_ptr->pos);
6396  return d_ptr->transformToParent().mapRect(rect);
6397 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
TransformData * transformData
QTransform transformToParent() const
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740

◆ mapRectToParent() [2/2]

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

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

Since
4.5

Definition at line 529 of file qgraphicsitem.h.

530 { return mapRectToParent(QRectF(ax, ay, w, h)); }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QRectF mapRectToParent(const QRectF &rect) const
Maps the rectangle rect, which is in this item&#39;s coordinate system, to its parent&#39;s coordinate system...

◆ mapRectToScene() [1/2]

QRectF QGraphicsItem::mapRectToScene ( const QRectF rect) const

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.

Since
4.5

e., the bounding rectangle of the resulting polygon).

\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}

Definition at line 6422 of file qgraphicsitem.cpp.

Referenced by mapRectToItem(), QmlJSDebugger::SubcomponentMaskLayerItem::setCurrentItem(), and QmlJSDebugger::LiveSelectionIndicator::setItems().

6423 {
6425  return rect.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());
6426  return d_ptr->sceneTransform.mapRect(rect);
6427 }
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
QScopedPointer< QGraphicsItemPrivate > d_ptr
bool hasTranslateOnlySceneTransform()
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740

◆ mapRectToScene() [2/2]

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

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

Since
4.5

Definition at line 531 of file qgraphicsitem.h.

532 { return mapRectToScene(QRectF(ax, ay, w, h)); }
QRectF mapRectToScene(const QRectF &rect) const
Maps the rectangle rect, which is in this item&#39;s coordinate system, to the scene coordinate system...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ mapToItem() [1/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 0, this function returns the same as mapToScene().

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

Definition at line 6208 of file qgraphicsitem.cpp.

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

6209 {
6210  if (item)
6211  return itemTransform(item).map(point);
6212  return mapToScene(point);
6213 }
QTransform itemTransform(const QGraphicsItem *other, bool *ok=0) const
Returns a QTransform that maps coordinates from this item to other.
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
QPointF mapToScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to the scene&#39;s coordinate system...

◆ mapToItem() [2/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 0, this function returns the same as mapToScene().

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

Definition at line 6284 of file qgraphicsitem.cpp.

6285 {
6286  if (item)
6287  return itemTransform(item).map(rect);
6288  return mapToScene(rect);
6289 }
QTransform itemTransform(const QGraphicsItem *other, bool *ok=0) const
Returns a QTransform that maps coordinates from this item to other.
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
QPointF mapToScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to the scene&#39;s coordinate system...

◆ 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 0, this function returns the same as mapToScene().

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

Definition at line 6539 of file qgraphicsitem.cpp.

6540 {
6541  if (item)
6542  return itemTransform(item).map(polygon);
6543  return mapToScene(polygon);
6544 }
QTransform itemTransform(const QGraphicsItem *other, bool *ok=0) const
Returns a QTransform that maps coordinates from this item to other.
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
QPointF mapToScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to the scene&#39;s coordinate system...

◆ mapToItem() [4/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 0, this function returns the same as mapToScene().

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

Definition at line 6586 of file qgraphicsitem.cpp.

6587 {
6588  if (item)
6589  return itemTransform(item).map(path);
6590  return mapToScene(path);
6591 }
QTransform itemTransform(const QGraphicsItem *other, bool *ok=0) const
Returns a QTransform that maps coordinates from this item to other.
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
QPointF mapToScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to the scene&#39;s coordinate system...

◆ 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 509 of file qgraphicsitem.h.

510 { return mapToItem(item, QPointF(ax, ay)); }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPointF mapToItem(const QGraphicsItem *item, const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to item&#39;s coordinate system...

◆ 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 521 of file qgraphicsitem.h.

522 { return mapToItem(item, QRectF(ax, ay, w, h)); }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QPointF mapToItem(const QGraphicsItem *item, const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to item&#39;s coordinate system...

◆ mapToParent() [1/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 6231 of file qgraphicsitem.cpp.

Referenced by mouseMoveEvent().

6232 {
6233  // COMBINE
6234  if (!d_ptr->transformData)
6235  return point + d_ptr->pos;
6236  return d_ptr->transformToParent().map(point);
6237 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
TransformData * transformData
QTransform transformToParent() const

◆ mapToParent() [2/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 6307 of file qgraphicsitem.cpp.

6308 {
6309  // COMBINE
6310  if (!d_ptr->transformData)
6311  return rect.translated(d_ptr->pos);
6312  return d_ptr->transformToParent().map(rect);
6313 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
TransformData * transformData
QTransform transformToParent() const
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740

◆ 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 6555 of file qgraphicsitem.cpp.

6556 {
6557  // COMBINE
6558  if (!d_ptr->transformData)
6559  return polygon.translated(d_ptr->pos);
6560  return d_ptr->transformToParent().map(polygon);
6561 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QPolygonF translated(qreal dx, qreal dy) const
Returns a copy of the polygon that is translated by ({dx}, {dy}).
Definition: qpolygon.h:182
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
TransformData * transformData
QTransform transformToParent() const

◆ mapToParent() [4/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 6602 of file qgraphicsitem.cpp.

6603 {
6604  // COMBINE
6605  if (!d_ptr->transformData)
6606  return path.translated(d_ptr->pos);
6607  return d_ptr->transformToParent().map(path);
6608 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
TransformData * transformData
QTransform transformToParent() const
QPainterPath translated(qreal dx, qreal dy) const
Returns a copy of the path that is translated by ({dx}, {dy}).

◆ mapToParent() [5/6]

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

This convenience function is equivalent to calling mapToParent(QPointF(x, y)).

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

Definition at line 511 of file qgraphicsitem.h.

512 { return mapToParent(QPointF(ax, ay)); }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPointF mapToParent(const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to its parent&#39;s coordinate system...

◆ mapToParent() [6/6]

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

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

Since
4.3

Definition at line 523 of file qgraphicsitem.h.

524 { return mapToParent(QRectF(ax, ay, w, h)); }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QPointF mapToParent(const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to its parent&#39;s coordinate system...

◆ mapToScene() [1/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 6257 of file qgraphicsitem.cpp.

Referenced by QDeclarativeMouseArea::geometryChanged(), QmlJSDebugger::BoundingRectHighlighter::highlightAll(), isObscured(), mapToItem(), scenePos(), QDeclarativePathView::sendMouseEvent(), QDeclarativeMouseArea::sendMouseEvent(), QDeclarativeFlickable::sendMouseEvent(), and QDeclarativePinchArea::sendMouseEvent().

6258 {
6260  return QPointF(point.x() + d_ptr->sceneTransform.dx(), point.y() + d_ptr->sceneTransform.dy());
6261  return d_ptr->sceneTransform.map(point);
6262 }
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
QScopedPointer< QGraphicsItemPrivate > d_ptr
bool hasTranslateOnlySceneTransform()
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ mapToScene() [2/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 6332 of file qgraphicsitem.cpp.

6333 {
6335  return rect.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());
6336  return d_ptr->sceneTransform.map(rect);
6337 }
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
QScopedPointer< QGraphicsItemPrivate > d_ptr
bool hasTranslateOnlySceneTransform()
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740

◆ 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 6570 of file qgraphicsitem.cpp.

6571 {
6573  return polygon.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());
6574  return d_ptr->sceneTransform.map(polygon);
6575 }
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
QScopedPointer< QGraphicsItemPrivate > d_ptr
bool hasTranslateOnlySceneTransform()
QPolygonF translated(qreal dx, qreal dy) const
Returns a copy of the polygon that is translated by ({dx}, {dy}).
Definition: qpolygon.h:182
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273

◆ mapToScene() [4/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 6617 of file qgraphicsitem.cpp.

6618 {
6620  return path.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());
6621  return d_ptr->sceneTransform.map(path);
6622 }
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
QScopedPointer< QGraphicsItemPrivate > d_ptr
bool hasTranslateOnlySceneTransform()
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
QPainterPath translated(qreal dx, qreal dy) const
Returns a copy of the path that is translated by ({dx}, {dy}).

◆ mapToScene() [5/6]

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

This convenience function is equivalent to calling mapToScene(QPointF(x, y)).

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

Definition at line 513 of file qgraphicsitem.h.

514 { return mapToScene(QPointF(ax, ay)); }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPointF mapToScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to the scene&#39;s coordinate system...

◆ mapToScene() [6/6]

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

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

Since
4.3

Definition at line 525 of file qgraphicsitem.h.

526 { return mapToScene(QRectF(ax, ay, w, h)); }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QPointF mapToScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to the scene&#39;s coordinate system...

◆ matrix()

QMatrix QGraphicsItem::matrix ( ) const

Returns the item's affine transformation matrix.

This is a subset or the item's full transformation matrix, and might not represent the item's full transformation.

Use transform() instead.

See also
setTransform(), sceneTransform()

Definition at line 4050 of file qgraphicsitem.cpp.

Referenced by deviceTransform(), ShaderEffectItem::meshResolution(), ShaderEffectItem::renderEffect(), and QGraphicsItemAnimation::reset().

4051 {
4052  return transform().toAffine();
4053 }
QTransform transform() const
Returns this item&#39;s transformation matrix.
const QMatrix & toAffine() const
Returns the QTransform as an affine matrix.

◆ mouseDoubleClickEvent()

void QGraphicsItem::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent event)
protectedvirtual

This event handler, for event event, can be reimplemented to receive mouse doubleclick 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 doubleclick 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 QGraphicsItem::ItemIsSelectable{selectable} nor 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, QDeclarativeTextEdit, QDeclarativeTextInput, QDeclarativeMouseArea, and QGraphicsProxyWidget.

Definition at line 7721 of file qgraphicsitem.cpp.

Referenced by QDeclarativeMouseArea::mouseDoubleClickEvent(), QDeclarativeTextInput::mouseDoubleClickEvent(), QDeclarativeTextEdit::mouseDoubleClickEvent(), QGraphicsTextItem::mouseDoubleClickEvent(), and sceneEvent().

7722 {
7723  mousePressEvent(event);
7724 }
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse press events for this item...

◆ 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, QDeclarativeTextEdit, QDeclarativePinchArea, QDeclarativeTextInput, QDeclarativeMouseArea, QDeclarativeFlickable, QDeclarativePathView, and QGraphicsProxyWidget.

Definition at line 7556 of file qgraphicsitem.cpp.

Referenced by QDeclarativePathView::mouseMoveEvent(), QDeclarativeFlickable::mouseMoveEvent(), QDeclarativeMouseArea::mouseMoveEvent(), QDeclarativeTextInput::mouseMoveEvent(), QDeclarativePinchArea::mouseMoveEvent(), QDeclarativeTextEdit::mouseMoveEvent(), QGraphicsTextItem::mouseMoveEvent(), and sceneEvent().

7557 {
7558  if ((event->buttons() & Qt::LeftButton) && (flags() & ItemIsMovable)) {
7559  // Determine the list of items that need to be moved.
7560  QList<QGraphicsItem *> selectedItems;
7561  QMap<QGraphicsItem *, QPointF> initialPositions;
7562  if (d_ptr->scene) {
7563  selectedItems = d_ptr->scene->selectedItems();
7564  initialPositions = d_ptr->scene->d_func()->movingItemsInitialPositions;
7565  if (initialPositions.isEmpty()) {
7566  foreach (QGraphicsItem *item, selectedItems)
7567  initialPositions[item] = item->pos();
7568  initialPositions[this] = pos();
7569  }
7570  d_ptr->scene->d_func()->movingItemsInitialPositions = initialPositions;
7571  }
7572 
7573  // Find the active view.
7574  QGraphicsView *view = 0;
7575  if (event->widget())
7576  view = qobject_cast<QGraphicsView *>(event->widget()->parentWidget());
7577 
7578  // Move all selected items
7579  int i = 0;
7580  bool movedMe = false;
7581  while (i <= selectedItems.size()) {
7582  QGraphicsItem *item = 0;
7583  if (i < selectedItems.size())
7584  item = selectedItems.at(i);
7585  else
7586  item = this;
7587  if (item == this) {
7588  // Slightly clumsy-looking way to ensure that "this" is part
7589  // of the list of items to move, this is to avoid allocations
7590  // (appending this item to the list of selected items causes a
7591  // detach).
7592  if (movedMe)
7593  break;
7594  movedMe = true;
7595  }
7596 
7598  QPointF currentParentPos;
7599  QPointF buttonDownParentPos;
7601  // Items whose ancestors ignore transformations need to
7602  // map screen coordinates to local coordinates, then map
7603  // those to the parent.
7604  QTransform viewToItemTransform = (item->deviceTransform(view->viewportTransform())).inverted();
7605  currentParentPos = mapToParent(viewToItemTransform.map(QPointF(view->mapFromGlobal(event->screenPos()))));
7606  buttonDownParentPos = mapToParent(viewToItemTransform.map(QPointF(view->mapFromGlobal(event->buttonDownScreenPos(Qt::LeftButton)))));
7607  } else if (item->flags() & ItemIgnoresTransformations) {
7608  // Root items that ignore transformations need to
7609  // calculate their diff by mapping viewport coordinates
7610  // directly to parent coordinates.
7611  // COMBINE
7613  if (item->d_ptr->transformData)
7614  itemTransform = item->d_ptr->transformData->computedFullTransform();
7615  itemTransform.translate(item->d_ptr->pos.x(), item->d_ptr->pos.y());
7616  QTransform viewToParentTransform = itemTransform
7617  * (item->sceneTransform() * view->viewportTransform()).inverted();
7618  currentParentPos = viewToParentTransform.map(QPointF(view->mapFromGlobal(event->screenPos())));
7619  buttonDownParentPos = viewToParentTransform.map(QPointF(view->mapFromGlobal(event->buttonDownScreenPos(Qt::LeftButton))));
7620  } else {
7621  // All other items simply map from the scene.
7622  currentParentPos = item->mapToParent(item->mapFromScene(event->scenePos()));
7623  buttonDownParentPos = item->mapToParent(item->mapFromScene(event->buttonDownScenePos(Qt::LeftButton)));
7624  }
7625 
7626  item->setPos(initialPositions.value(item) + currentParentPos - buttonDownParentPos);
7627 
7628  if (item->flags() & ItemIsSelectable)
7629  item->setSelected(true);
7630  }
7631  ++i;
7632  }
7633 
7634  } else {
7635  event->ignore();
7636  }
7637 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
QTransform computedFullTransform(QTransform *postmultiplyTransform=0) const
QPoint screenPos() const
Returns the mouse cursor position in screen coordinates.
QScopedPointer< QGraphicsItemPrivate > d_ptr
void setSelected(bool selected)
If selected is true and this item is selectable, this item is selected; otherwise, it is unselected.
QTransform itemTransform(const QGraphicsItem *other, bool *ok=0) const
Returns a QTransform that maps coordinates from this item to other.
QTransform sceneTransform() const
Returns this item&#39;s scene transformation matrix.
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QGraphicsScene * scene
QWidget * widget() const
Returns the widget where the event originated, or 0 if the event originates from another application...
QPointF pos() const
Returns the position of the item in parent coordinates.
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
Definition: qtransform.cpp:417
void setPos(const QPointF &pos)
Sets the position of the item to pos, which is in parent coordinates.
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QTransform viewportTransform() const
Returns a matrix that maps viewport coordinates to scene coordinates.
QPointF buttonDownScenePos(Qt::MouseButton button) const
Returns the mouse cursor position in scene coordinates where the specified button was clicked...
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
static bool movableAncestorIsSelected(const QGraphicsItem *item)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
QList< QGraphicsItem * > selectedItems() const
Returns a list of all currently selected items.
QPointF mapFromScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s scene&#39;s coordinate system, to this item&#39;s coordinate sy...
QTransform deviceTransform(const QTransform &viewportTransform) const
Returns this item&#39;s device transformation matrix, using viewportTransform to map from scene to device...
QPointF scenePos() const
Returns the mouse cursor position in scene coordinates.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool isEmpty() const
Returns true if the map contains no items; otherwise returns false.
Definition: qmap.h:203
QPoint buttonDownScreenPos(Qt::MouseButton button) const
Returns the mouse cursor position in screen coordinates where the specified button was clicked...
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
TransformData * transformData
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...
QPointF mapToParent(const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to its parent&#39;s coordinate system...
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ 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 doubleclick 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 for items that are neither QGraphicsItem::ItemIsMovable "movable" nor QGraphicsItem::ItemIsSelectable "selectable". mouseMoveEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), sceneEvent()

Reimplemented in QGraphicsTextItem, QDeclarativeTextEdit, QDeclarativePinchArea, QDeclarativeTextInput, QDeclarativeText, QDeclarativeMouseArea, QDeclarativeFlickable, QDeclarativePathView, and QGraphicsProxyWidget.

Definition at line 7492 of file qgraphicsitem.cpp.

Referenced by mouseDoubleClickEvent(), QDeclarativePathView::mousePressEvent(), QDeclarativeFlickable::mousePressEvent(), QDeclarativeMouseArea::mousePressEvent(), QDeclarativeText::mousePressEvent(), QDeclarativePinchArea::mousePressEvent(), QDeclarativeTextEdit::mousePressEvent(), QGraphicsTextItem::mousePressEvent(), and sceneEvent().

7493 {
7494  if (event->button() == Qt::LeftButton && (flags() & ItemIsSelectable)) {
7495  bool multiSelect = (event->modifiers() & Qt::ControlModifier) != 0;
7496  if (!multiSelect) {
7497  if (!d_ptr->selected) {
7498  if (QGraphicsScene *scene = d_ptr->scene) {
7499  ++scene->d_func()->selectionChanging;
7500  scene->clearSelection();
7501  --scene->d_func()->selectionChanging;
7502  }
7503  setSelected(true);
7504  }
7505  }
7506  } else if (!(flags() & ItemIsMovable)) {
7507  event->ignore();
7508  }
7509  if (d_ptr->isWidget) {
7510  // Qt::Popup closes when you click outside.
7511  QGraphicsWidget *w = static_cast<QGraphicsWidget *>(this);
7512  if ((w->windowFlags() & Qt::Popup) == Qt::Popup) {
7513  event->accept();
7514  if (!w->rect().contains(event->pos()))
7515  w->close();
7516  }
7517  }
7518 }
Qt::WindowFlags windowFlags
the widget&#39;s window flags
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
QScopedPointer< QGraphicsItemPrivate > d_ptr
void setSelected(bool selected)
If selected is true and this item is selectable, this item is selected; otherwise, it is unselected.
QGraphicsScene * scene
Qt::MouseButton button() const
Returns the mouse button (if any) that caused the event.
QRectF rect() const
Returns the item&#39;s local rect as a QRectF.
bool close()
Call this function to close the widget.
bool contains(const QPointF &p) const
Returns true if the given point is inside or on the edge of the rectangle; otherwise returns false...
Definition: qrect.cpp:2349
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
void clearSelection()
Clears the current selection.
QPointF pos() const
Returns the mouse cursor position in item coordinates.
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ 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, QDeclarativeTextEdit, QDeclarativePinchArea, QDeclarativeTextInput, QDeclarativeText, QDeclarativeFlickable, QDeclarativeMouseArea, QDeclarativePathView, and QGraphicsProxyWidget.

Definition at line 7658 of file qgraphicsitem.cpp.

Referenced by QDeclarativePathView::mouseReleaseEvent(), QDeclarativeMouseArea::mouseReleaseEvent(), QDeclarativeFlickable::mouseReleaseEvent(), QDeclarativeText::mouseReleaseEvent(), QDeclarativeTextInput::mouseReleaseEvent(), QDeclarativePinchArea::mouseReleaseEvent(), QDeclarativeTextEdit::mouseReleaseEvent(), QGraphicsTextItem::mouseReleaseEvent(), and sceneEvent().

7659 {
7660  if (event->button() == Qt::LeftButton && (flags() & ItemIsSelectable)) {
7661  bool multiSelect = (event->modifiers() & Qt::ControlModifier) != 0;
7662  if (event->scenePos() == event->buttonDownScenePos(Qt::LeftButton)) {
7663  // The item didn't move
7664  if (multiSelect) {
7665  setSelected(!isSelected());
7666  } else {
7667  bool selectionChanged = false;
7668  if (QGraphicsScene *scene = d_ptr->scene) {
7669  ++scene->d_func()->selectionChanging;
7670  // Clear everything but this item. Bypass
7671  // QGraphicsScene::clearSelection()'s default behavior by
7672  // temporarily removing this item from the selection list.
7673  if (d_ptr->selected) {
7674  scene->d_func()->selectedItems.remove(this);
7675  foreach (QGraphicsItem *item, scene->d_func()->selectedItems) {
7676  if (item->isSelected()) {
7677  selectionChanged = true;
7678  break;
7679  }
7680  }
7681  }
7682  scene->clearSelection();
7683  if (d_ptr->selected)
7684  scene->d_func()->selectedItems.insert(this);
7685  --scene->d_func()->selectionChanging;
7686  if (selectionChanged)
7688  }
7689  setSelected(true);
7690  }
7691  }
7692  }
7693  if (d_ptr->scene && !event->buttons())
7694  d_ptr->scene->d_func()->movingItemsInitialPositions.clear();
7695 }
void clear()
Removes and deletes all items from the scene, but otherwise leaves the state of the scene unchanged...
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
QScopedPointer< QGraphicsItemPrivate > d_ptr
void setSelected(bool selected)
If selected is true and this item is selectable, this item is selected; otherwise, it is unselected.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QGraphicsScene * scene
Qt::MouseButton button() const
Returns the mouse button (if any) that caused the event.
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
bool isSelected() const
Returns true if this item is selected; otherwise, false is returned.
#define emit
Definition: qobjectdefs.h:76
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
QList< QGraphicsItem * > selectedItems() const
Returns a list of all currently selected items.
void selectionChanged()
This signal is emitted by QGraphicsScene whenever the selection changes.
QPointF scenePos() const
Returns the mouse cursor position in scene coordinates.
void clearSelection()
Clears the current selection.
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...

◆ 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 287 of file qgraphicsitem.h.

Referenced by QDeclarativeListView::itemsMoved().

287 { setPos(pos().x() + dx, pos().y() + dy); }
QPointF pos() const
Returns the position of the item in parent coordinates.
void setPos(const QPointF &pos)
Sets the position of the item to pos, which is in parent coordinates.
qreal y() const
This convenience function is equivalent to calling pos().
qreal x() const
This convenience function is equivalent to calling pos().

◆ opacity()

qreal QGraphicsItem::opacity ( ) const

Returns this item's local opacity, which is between 0.

Since
4.5

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.

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 2800 of file qgraphicsitem.cpp.

2801 {
2802  return d_ptr->opacity;
2803 }
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ 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 QGraphicsItemGroup, QGraphicsSimpleTextItem, QGraphicsTextItem, QGraphicsPixmapItem, QGraphicsLineItem, QGraphicsPolygonItem, QGraphicsEllipseItem, QGraphicsRectItem, QGraphicsPathItem, and QAbstractGraphicsShapeItem.

Definition at line 5514 of file qgraphicsitem.cpp.

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

5515 {
5516  return QPainterPath();
5517 }
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67

◆ paint()

void QGraphicsItem::paint ( QPainter painter,
const QStyleOptionGraphicsItem option,
QWidget widget = 0 
)
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,
const QStyleOptionGraphicsItem *option,
{
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.

See also
setCacheMode(), QPen::width(), {Item Coordinates}, ItemUsesExtendedStyleOption

Implemented in QGraphicsItemGroup, QGraphicsSimpleTextItem, QGraphicsTextItem, QGraphicsPixmapItem, QGraphicsLineItem, QGraphicsPolygonItem, QGraphicsEllipseItem, QGraphicsRectItem, QGraphicsPathItem, QDeclarativeParticlesPainter, QDeclarativeParticles, QGraphicsWidget, QDeclarativeText, QDeclarativeRectangle, QDeclarativeItem, QDeclarativePaintedItem, QGraphicsSvgItem, QDeclarativeBorderImage, QDeclarativeImage, QGraphicsProxyWidget, ShaderEffectItem, and QmlJSDebugger::LiveLayerItem.

Referenced by _q_paintItem(), boundingRegion(), QGraphicsScenePrivate::draw(), and QGraphicsLineItem::setLine().

◆ panel()

QGraphicsItem * QGraphicsItem::panel ( ) const

Returns the item's panel, or 0 if this item does not have a panel.

Since
4.6

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 1737 of file qgraphicsitem.cpp.

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

1738 {
1739  if (d_ptr->flags & ItemIsPanel)
1740  return const_cast<QGraphicsItem *>(this);
1741  return d_ptr->parent ? d_ptr->parent->panel() : 0;
1742 }
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QGraphicsItem * panel() const
Returns the item&#39;s panel, or 0 if this item does not have a panel.

◆ panelModality()

QGraphicsItem::PanelModality QGraphicsItem::panelModality ( ) const

Returns the modality for this item.

Since
4.6

Definition at line 2132 of file qgraphicsitem.cpp.

Referenced by QGraphicsScene::addItem(), isBlockedByModalPanel(), QGraphicsScenePrivate::mousePressEventHandler(), QGraphicsScenePrivate::removeItemHelper(), setPanelModality(), and QGraphicsItemPrivate::setVisibleHelper().

2133 {
2134  return d_ptr->panelModality;
2135 }
QGraphicsItem::PanelModality panelModality
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ parentItem()

QGraphicsItem * QGraphicsItem::parentItem ( ) const

Returns a pointer to this item's parent item.

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

See also
setParentItem(), childItems()

Definition at line 1631 of file qgraphicsitem.cpp.

Referenced by _qt_movableAncestorIsSelected(), QGraphicsLayoutPrivate::addChildLayoutItem(), QDeclarativeAnchorsPrivate::calcStretch(), QDeclarativeAnchorsPrivate::centerInChanged(), QDeclarativeAnchorsPrivate::checkHAnchorValid(), QDeclarativeAnchorsPrivate::checkVAnchorValid(), collidesWithItem(), QGraphicsScene::createItemGroup(), deviceTransform(), QGraphicsScenePrivate::dispatchHoverEvent(), QGraphicsScene::event(), QDeclarativeAnchorsPrivate::fillChanged(), QGraphicsScenePrivate::filterDescendantEvent(), QDeclarativeItem::forceActiveFocus(), QGraphicsScenePrivate::gestureEventHandler(), QDeclarativeItem::hasFocus(), QGraphicsScene::keyPressEvent(), QGraphicsScene::keyReleaseEvent(), QDeclarativeMouseArea::mouseMoveEvent(), operator<<(), QDeclarativeItem::parentItem(), parentWidget(), QGraphicsScenePrivate::removeItemHelper(), QGraphicsLayoutPrivate::reparentChildItems(), sceneBoundingRect(), QGraphicsItemPrivate::sceneEffectiveBoundingRect(), QmlJSDebugger::LiveRubberBandSelectionManipulator::select(), QGraphicsScenePrivate::setActivePanelHelper(), QGraphicsScene::setActiveWindow(), QDeclarativeAnchors::setCenterIn(), QDeclarativeAnchors::setFill(), stackBefore(), topLevelItem(), QGraphicsScenePrivate::updateFont(), QGraphicsWidget::updateGeometry(), QDeclarativeAnchorsPrivate::updateHorizontalAnchors(), QGraphicsScenePrivate::updatePalette(), QDeclarativeAnchorsPrivate::updateVerticalAnchors(), and QDeclarativeItem::~QDeclarativeItem().

1632 {
1633  return d_ptr->parent;
1634 }
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ parentObject()

QGraphicsObject * QGraphicsItem::parentObject ( ) const

Returns a pointer to the item's parent, cast to a QGraphicsObject.

Since
4.6

returns 0 if the parent item is not a QGraphicsObject.

See also
parentItem(), childItems()

Definition at line 1662 of file qgraphicsitem.cpp.

Referenced by QGestureManager::filterEvent().

1663 {
1664  QGraphicsItem *p = d_ptr->parent;
1665  return (p && p->d_ptr->isObject) ? static_cast<QGraphicsObject *>(p) : 0;
1666 }
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
The QGraphicsObject class provides a base class for all graphics items that require signals...

◆ parentWidget()

QGraphicsWidget * QGraphicsItem::parentWidget ( ) const

Returns a pointer to the item's parent widget.

Since
4.4

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

See also
parentItem(), childItems()

Definition at line 1679 of file qgraphicsitem.cpp.

Referenced by QGraphicsScene::addItem(), QShortcutMap::correctGraphicsWidgetContext(), QGraphicsWidget::focusNextPrevChild(), QGraphicsWidgetPrivate::naturalWidgetFont(), QGraphicsWidgetPrivate::naturalWidgetPalette(), QGraphicsWidgetPrivate::resolveFont(), QGraphicsItemPrivate::setEnabledHelper(), QGraphicsWidgetPrivate::setLayoutDirection_helper(), QGraphicsItemPrivate::setVisibleHelper(), topLevelWidget(), and QGraphicsWidget::updateGeometry().

1680 {
1681  QGraphicsItem *p = parentItem();
1682  while (p && !p->isWidget())
1683  p = p->parentItem();
1684  return (p && p->isWidget()) ? static_cast<QGraphicsWidget *>(p) : 0;
1685 }
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
bool isWidget() const
Returns true if this item is a widget (i.

◆ 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 3813 of file qgraphicsitem.cpp.

Referenced by QGraphicsItemGroup::addToGroup(), QGraphicsProxyWidget::contextMenuEvent(), deviceTransform(), QGraphicsProxyWidget::event(), QGraphicsWidget::insertAction(), QDeclarativeListView::itemsInserted(), ShaderEffectItem::lookThroughShaderCode(), mouseMoveEvent(), QDeclarativeTextEdit::moveCursorSelection(), operator<<(), QDeclarativeTextInput::positionAt(), QDeclarativeGridViewPrivate::positionViewAtIndex(), QDeclarativeListViewPrivate::positionViewAtIndex(), QDeclarativePathView::refill(), QGraphicsItemGroup::removeFromGroup(), QGraphicsItemAnimation::reset(), QGraphicsWidget::resize(), QDeclarativeFlickable::resizeContent(), QDeclarativeTextEdit::setCursorPosition(), QGraphicsWidget::setGeometry(), QGraphicsItemAnimation::setItem(), QGraphicsItemPrivate::setPosHelper(), QDeclarativeGridView::trackedPositionChanged(), QDeclarativeListView::trackedPositionChanged(), QDeclarativePinchArea::updatePinch(), QDeclarativeGridView::viewportMoved(), QDeclarativeListView::viewportMoved(), and QGraphicsProxyWidget::wheelEvent().

3814 {
3815  return d_ptr->pos;
3816 }
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ 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) {
radius = newRadius;
}
}
See also
boundingRect()

Definition at line 7979 of file qgraphicsitem.cpp.

Referenced by QGraphicsItemGroup::addToGroup(), QGraphicsItemGroup::removeFromGroup(), QDeclarativePaintedItem::setContentsSize(), QGraphicsWidget::setGeometry(), setGraphicsEffect(), QDeclarativeItem::setImplicitHeight(), QDeclarativeItem::setImplicitWidth(), QGraphicsTransformPrivate::setItem(), QGraphicsLineItem::setLine(), QGraphicsPixmapItem::setOffset(), QGraphicsPathItem::setPath(), QAbstractGraphicsShapeItem::setPen(), QGraphicsLineItem::setPen(), QGraphicsPixmapItem::setPixmap(), QGraphicsPolygonItem::setPolygon(), QGraphicsRectItem::setRect(), QGraphicsEllipseItem::setRect(), setRotation(), setScale(), QDeclarativeItem::setSize(), QGraphicsEllipseItem::setSpanAngle(), QGraphicsEllipseItem::setStartAngle(), QDeclarativeText::setStyle(), setTransformations(), setTransformOriginPoint(), QDeclarativeText::setVAlign(), QGraphicsWidget::setWindowFrameMargins(), QGraphicsTransformPrivate::updateItem(), and QDeclarativeTextEdit::updateSize().

7980 {
7981  if (d_ptr->inDestructor)
7982  return;
7983  if (d_ptr->scene) {
7984  d_ptr->scene->d_func()->dirtyGrowingItemsBoundingRect = true;
7985  d_ptr->geometryChanged = 1;
7988 
7989  QGraphicsScenePrivate *scenePrivate = d_ptr->scene->d_func();
7990  scenePrivate->index->prepareBoundingRectChange(this);
7991  scenePrivate->markDirty(this, QRectF(), /*invalidateChildren=*/true, /*force=*/false,
7992  /*ignoreOpacity=*/ false, /*removingItemFromScene=*/ false,
7993  /*updateBoundingRect=*/true);
7994 
7995  // For compatibility reasons, we have to update the item's old geometry
7996  // if someone is connected to the changed signal or the scene has no views.
7997  // Note that this has to be done *after* markDirty to ensure that
7998  // _q_processDirtyItems is called before _q_emitUpdated.
7999  if (scenePrivate->isSignalConnected(scenePrivate->changedSignalIndex)
8000  || scenePrivate->views.isEmpty()) {
8002  d_ptr->scene->update(boundingRect().translated(d_ptr->sceneTransform.dx(),
8003  d_ptr->sceneTransform.dy()));
8004  } else {
8006  }
8007  }
8008  }
8009 
8010  d_ptr->markParentDirty(/*updateBoundingRect=*/true);
8011 }
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
QScopedPointer< QGraphicsItemPrivate > d_ptr
bool hasTranslateOnlySceneTransform()
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
QGraphicsScene * scene
QGraphicsSceneIndex * index
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QList< QGraphicsView * > views
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void markDirty(QGraphicsItem *item, const QRectF &rect=QRectF(), bool invalidateChildren=false, bool force=false, bool ignoreOpacity=false, bool removingItemFromScene=false, bool updateBoundingRect=false)
quint32 paintedViewBoundingRectsNeedRepaint
virtual void prepareBoundingRectChange(const QGraphicsItem *item)
Notify the index for a geometry change of an item.
void update(qreal x, qreal y, qreal w, qreal h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isSignalConnected(uint signalIdx) const
Returns true if the signal with index signal_index from object sender is connected.
Definition: qobject_p.h:237
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
void markParentDirty(bool updateBoundingRect=false)

◆ removeFromIndex()

void QGraphicsItem::removeFromIndex ( )
protected

Removes this item from the scene's index.

Warning
This function is not part of the public interface.

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

Definition at line 7956 of file qgraphicsitem.cpp.

7957 {
7959  // ### remove from child index only if applicable
7960  return;
7961  }
7962  if (d_ptr->scene)
7963  d_ptr->scene->d_func()->index->removeItem(this);
7964 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsScene * scene
void removeItem(QGraphicsItem *item)
Removes the item item and all its children from the scene.

◆ removeSceneEventFilter()

void QGraphicsItem::removeSceneEventFilter ( QGraphicsItem filterItem)

Removes an event filter on this item from filterItem.

See also
installSceneEventFilter()

Definition at line 7057 of file qgraphicsitem.cpp.

7058 {
7059  if (!d_ptr->scene || d_ptr->scene != filterItem->scene())
7060  return;
7061  d_ptr->scene->d_func()->removeSceneEventFilter(this, filterItem);
7062 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsScene * scene
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.

◆ resetMatrix()

void QGraphicsItem::resetMatrix ( )

Use resetTransform() instead.

Definition at line 4736 of file qgraphicsitem.cpp.

4737 {
4738  resetTransform();
4739 }
void resetTransform()
Resets this item&#39;s transformation matrix to the identity matrix or all the transformation properties ...

◆ resetTransform()

void QGraphicsItem::resetTransform ( )

Resets this item's transformation matrix to the identity matrix or all the transformation properties to their default values.

Since
4.3

This is equivalent to calling setTransform(QTransform()).

See also
setTransform(), transform()

Definition at line 4753 of file qgraphicsitem.cpp.

Referenced by resetMatrix().

4754 {
4755  setTransform(QTransform(), false);
4756 }
void setTransform(const QTransform &matrix, bool combine=false)
Sets the item&#39;s current transformation matrix to matrix.
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ rotate()

void QGraphicsItem::rotate ( qreal  angle)

Use.

instead.

Rotates the current item transformation angle degrees clockwise around its origin. To translate around an arbitrary point (x, y), you need to combine translation and rotation with setTransform().

Example:

// Rotate an item 45 degrees around (0, 0).
item->rotate(45);
// Rotate an item 45 degrees around (x, y).
item->setTransform(QTransform().translate(x, y).rotate(45).translate(-x, -y));
See also
setTransform(), transform(), scale(), shear(), translate()

Definition at line 4782 of file qgraphicsitem.cpp.

4783 {
4784  setTransform(QTransform().rotate(angle), true);
4785 }
void setTransform(const QTransform &matrix, bool combine=false)
Sets the item&#39;s current transformation matrix to matrix.
void rotate(qreal angle)
Use.
qreal angle(const QPointF &p1, const QPointF &p2)
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ rotation()

qreal QGraphicsItem::rotation ( ) const

Returns the clockwise rotation, in degrees, around the Z axis.

Since
4.6

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 4091 of file qgraphicsitem.cpp.

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

4092 {
4093  if (!d_ptr->transformData)
4094  return 0;
4095  return d_ptr->transformData->rotation;
4096 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
TransformData * transformData

◆ scale() [1/2]

void QGraphicsItem::scale ( qreal  sx,
qreal  sy 
)

Use.

instead.

Scales the current item transformation by (sx, sy) around its origin. To scale from an arbitrary point (x, y), you need to combine translation and scaling with setTransform().

Example:

// Scale an item by 3x2 from its origin
item->scale(3, 2);
// Scale an item by 3x2 from (x, y)
item->setTransform(QTransform().translate(x, y).scale(3, 2).translate(-x, -y));
See also
setTransform(), transform()

Definition at line 4811 of file qgraphicsitem.cpp.

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

4812 {
4813  setTransform(QTransform::fromScale(sx, sy), true);
4814 }
void setTransform(const QTransform &matrix, bool combine=false)
Sets the item&#39;s current transformation matrix to matrix.
static QTransform fromScale(qreal dx, qreal dy)
Creates a matrix which corresponds to a scaling of sx horizontally and sy vertically.
Definition: qtransform.cpp:528

◆ scale() [2/2]

qreal QGraphicsItem::scale ( ) const

Returns the scale factor of the item.

Since
4.6

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 4165 of file qgraphicsitem.cpp.

Referenced by QDeclarativeBorderImage::paint(), QDeclarativePaintedItem::setContentsScale(), and QDeclarativePinchArea::updatePinch().

4166 {
4167  if (!d_ptr->transformData)
4168  return 1.;
4169  return d_ptr->transformData->scale;
4170 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
TransformData * transformData

◆ scene()

QGraphicsScene * QGraphicsItem::scene ( ) const

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

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

Definition at line 1583 of file qgraphicsitem.cpp.

Referenced by QGraphicsScene::addItem(), ShaderEffectItem::checkViewportUpdateMode(), QmlJSDebugger::LiveSelectionIndicator::clear(), QDeclarativeLoaderPrivate::clear(), QGraphicsItemPrivate::clearFocusHelper(), QDeclarativeTextEdit::closeSoftwareInputPanel(), QDeclarativeTextInput::closeSoftwareInputPanel(), QShortcutMap::correctGraphicsWidgetContext(), QDeclarativeFlickablePrivate::data_clear(), QGraphicsItemPrivate::discardUpdateRequest(), QGraphicsItemPrivate::effectiveBoundingRect(), QMotifStyle::event(), QMacStyle::event(), QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(), QDeclarativeTextEditPrivate::focusChanged(), QDeclarativeTextInputPrivate::focusChanged(), QGraphicsObject::grabGesture(), QDeclarativeItem::hasActiveFocus(), installSceneEventFilter(), mousePressEvent(), QDeclarativeMouseArea::mouseReleaseEvent(), QDeclarativeTextInput::mouseReleaseEvent(), QDeclarativePinchArea::mouseReleaseEvent(), QDeclarativeTextEdit::mouseReleaseEvent(), mouseReleaseEvent(), QDeclarativeTextEdit::openSoftwareInputPanel(), QDeclarativeTextInput::openSoftwareInputPanel(), QGraphicsItem(), QDeclarativeVisualItemModel::release(), QDeclarativeVisualDataModel::release(), QGraphicsScene::removeItem(), QGraphicsScenePrivate::removeItemHelper(), removeSceneEventFilter(), QWidgetPrivate::screenGeometry(), QGraphicsScene::sendEvent(), QDeclarativePathView::sendMouseEvent(), QDeclarativeMouseArea::sendMouseEvent(), QDeclarativeFlickable::sendMouseEvent(), QDeclarativePinchArea::sendMouseEvent(), QGraphicsItemPrivate::sendScenePosChange(), QGraphicsScenePrivate::setActivePanelHelper(), QGraphicsScene::setActiveWindow(), QGraphicsItemPrivate::setEnabledHelper(), QGraphicsItemPrivate::setFocusHelper(), QGraphicsScenePrivate::setFocusItemHelper(), QDeclarativeGridView::setFooter(), QDeclarativeListView::setFooter(), QDeclarativeGridView::setHeader(), QDeclarativeListView::setHeader(), setInputMethodHints(), QGraphicsItemPrivate::setPosHelper(), QGraphicsItemPrivate::setSubFocus(), QGraphicsWidget::setTabOrder(), QGraphicsItemPrivate::setVisibleHelper(), QGraphicsWidget::style(), QDeclarativeFlickable::timerEvent(), QGraphicsObject::ungrabGesture(), updateMicroFocus(), QGraphicsItemPrivate::updatePaintedViewBoundingRects(), QDeclarativePinchArea::updatePinch(), QmlJSDebugger::LiveSelectionRectangle::~LiveSelectionRectangle(), and QGraphicsWidget::~QGraphicsWidget().

1584 {
1585  return d_ptr->scene;
1586 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsScene * scene

◆ 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 5121 of file qgraphicsitem.cpp.

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

5122 {
5123  // Find translate-only offset
5124  // COMBINE
5125  QPointF offset;
5126  const QGraphicsItem *parentItem = this;
5127  const QGraphicsItemPrivate *itemd;
5128  do {
5129  itemd = parentItem->d_ptr.data();
5130  if (itemd->transformData)
5131  break;
5132  offset += itemd->pos;
5133  } while ((parentItem = itemd->parent));
5134 
5135  QRectF br = boundingRect();
5136  br.translate(offset);
5137  if (!parentItem)
5138  return br;
5139  if (parentItem->d_ptr->hasTranslateOnlySceneTransform()) {
5140  br.translate(parentItem->d_ptr->sceneTransform.dx(), parentItem->d_ptr->sceneTransform.dy());
5141  return br;
5142  }
5143  return parentItem->d_ptr->sceneTransform.mapRect(br);
5144 }
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr
T * data() const
Returns the value of the pointer referenced by this object.
bool hasTranslateOnlySceneTransform()
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void translate(qreal dx, qreal dy)
Moves the rectangle dx along the x-axis and dy along the y-axis, relative to the current position...
Definition: qrect.h:716
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
TransformData * transformData

◆ 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, QDeclarativePinchArea, QDeclarativeTextInput, QDeclarativeFlickable, QGraphicsWidget, QDeclarativeMouseArea, QDeclarativeItem, QDeclarativeGestureArea, and QDeclarativeFocusPanel.

Definition at line 7101 of file qgraphicsitem.cpp.

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

7102 {
7104  if (event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverLeave
7105  || event->type() == QEvent::DragEnter || event->type() == QEvent::DragLeave) {
7106  // Hover enter and hover leave events for children are ignored;
7107  // hover move events are forwarded.
7108  return true;
7109  }
7110 
7111  QGraphicsItem *handler = this;
7112  do {
7113  handler = handler->d_ptr->parent;
7114  Q_ASSERT(handler);
7116  // Forward the event to the closest parent that handles child
7117  // events, mapping existing item-local coordinates to its
7118  // coordinate system.
7119  d_ptr->remapItemPos(event, handler);
7120  handler->sceneEvent(event);
7121  return true;
7122  }
7123 
7124  if (event->type() == QEvent::FocusOut) {
7125  focusOutEvent(static_cast<QFocusEvent *>(event));
7126  return true;
7127  }
7128 
7129  if (!d_ptr->visible) {
7130  // Eaten
7131  return true;
7132  }
7133 
7134  switch (event->type()) {
7135  case QEvent::FocusIn:
7136  focusInEvent(static_cast<QFocusEvent *>(event));
7137  break;
7139  contextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent *>(event));
7140  break;
7142  dragEnterEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));
7143  break;
7145  dragMoveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));
7146  break;
7148  dragLeaveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));
7149  break;
7151  dropEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));
7152  break;
7154  hoverEnterEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
7155  break;
7157  hoverMoveEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
7158  break;
7160  hoverLeaveEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
7161  break;
7163  mouseMoveEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
7164  break;
7166  mousePressEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
7167  break;
7169  mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
7170  break;
7172  mouseDoubleClickEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
7173  break;
7175  wheelEvent(static_cast<QGraphicsSceneWheelEvent *>(event));
7176  break;
7177  case QEvent::KeyPress: {
7178  QKeyEvent *k = static_cast<QKeyEvent *>(event);
7179  if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) {
7180  if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier?
7181  bool res = false;
7182  if (k->key() == Qt::Key_Backtab
7183  || (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier))) {
7184  if (d_ptr->isWidget) {
7185  res = static_cast<QGraphicsWidget *>(this)->focusNextPrevChild(false);
7186  } else if (d_ptr->scene) {
7187  res = d_ptr->scene->focusNextPrevChild(false);
7188  }
7189  } else if (k->key() == Qt::Key_Tab) {
7190  if (d_ptr->isWidget) {
7191  res = static_cast<QGraphicsWidget *>(this)->focusNextPrevChild(true);
7192  } else if (d_ptr->scene) {
7193  res = d_ptr->scene->focusNextPrevChild(true);
7194  }
7195  }
7196  if (!res)
7197  event->ignore();
7198  return true;
7199  }
7200  }
7201  keyPressEvent(static_cast<QKeyEvent *>(event));
7202  break;
7203  }
7204  case QEvent::KeyRelease:
7205  keyReleaseEvent(static_cast<QKeyEvent *>(event));
7206  break;
7207  case QEvent::InputMethod:
7208  inputMethodEvent(static_cast<QInputMethodEvent *>(event));
7209  break;
7212  // Propagate panel activation.
7213  if (d_ptr->scene) {
7214  for (int i = 0; i < d_ptr->children.size(); ++i) {
7215  QGraphicsItem *child = d_ptr->children.at(i);
7216  if (child->isVisible() && !child->isPanel()) {
7218  d_ptr->scene->sendEvent(child, event);
7219  }
7220  }
7221  }
7222  break;
7223  default:
7224  return false;
7225  }
7226 
7227  return true;
7228 }
QGraphicsItem * parent
The QKeyEvent class describes a key event.
Definition: qevent.h:224
virtual bool sceneEvent(QEvent *event)
This virtual function receives events to this item.
EventRef event
QScopedPointer< QGraphicsItemPrivate > d_ptr
void remapItemPos(QEvent *event, QGraphicsItem *item)
Maps any item pos properties of event to item&#39;s coordinate system.
virtual void inputMethodEvent(QInputMethodEvent *event)
This event handler, for event event, can be reimplemented to receive input method events for this ite...
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
QGraphicsScene * scene
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse doubleclick events for thi...
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse press events for this item...
virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
This event handler, for event event, can be reimplemented to receive drag enter 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...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool focusNextPrevChild(bool next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it cannot.
virtual void keyPressEvent(QKeyEvent *event)
This event handler, for event event, can be reimplemented to receive key press events for this item...
bool sendEvent(QGraphicsItem *item, QEvent *event)
Sends event event to item item through possible event filters.
virtual void focusInEvent(QFocusEvent *event)
This event handler, for event event, can be reimplemented to receive focus in 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...
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse move events for this item...
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
This event handler, for event event, can be reimplemented to receive hover move 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 contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
This event handler can be reimplemented in a subclass to process context menu events.
virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event)
This event handler, for event event, can be reimplemented to receive drag move 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...
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
virtual void dropEvent(QGraphicsSceneDragDropEvent *event)
This event handler, for event event, can be reimplemented to receive drop events for this item...
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
virtual void keyReleaseEvent(QKeyEvent *event)
This event handler, for event event, can be reimplemented to receive key release events for this item...
QList< QGraphicsItem * > children
QImageIOHandler * handler
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
virtual void focusOutEvent(QFocusEvent *event)
This event handler, for event event, can be reimplemented to receive focus out 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 it...
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ 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 send 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()

Reimplemented in QDeclarativePinchArea, QDeclarativeMouseArea, QDeclarativeFlickable, and QDeclarativePathView.

Definition at line 7080 of file qgraphicsitem.cpp.

Referenced by QGraphicsScenePrivate::filterDescendantEvent(), QDeclarativePathView::sceneEventFilter(), QDeclarativeFlickable::sceneEventFilter(), QDeclarativeMouseArea::sceneEventFilter(), and QDeclarativePinchArea::sceneEventFilter().

7081 {
7082  Q_UNUSED(watched);
7083  Q_UNUSED(event);
7084  return false;
7085 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ sceneMatrix()

QMatrix QGraphicsItem::sceneMatrix ( ) const

Use sceneTransform() instead.

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

Definition at line 4404 of file qgraphicsitem.cpp.

4405 {
4407  return d_ptr->sceneTransform.toAffine();
4408 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
const QMatrix & toAffine() const
Returns the QTransform as an affine matrix.

◆ 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 3890 of file qgraphicsitem.cpp.

Referenced by QGraphicsItemPrivate::sendScenePosChange().

3891 {
3892  return mapToScene(0, 0);
3893 }
QPointF mapToScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to the scene&#39;s coordinate system...

◆ sceneTransform()

QTransform QGraphicsItem::sceneTransform ( ) const

Returns this item's scene transformation matrix.

Since
4.3

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);
rect.sceneTransform().map(QPointF(0, 0));
// returns QPointF(100, 100);
rect.sceneTransform().inverted().map(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 transfomation properties.

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

Definition at line 4431 of file qgraphicsitem.cpp.

Referenced by deviceTransform(), ensureVisible(), QGraphicsViewPrivate::mapToViewRect(), mouseMoveEvent(), QGraphicsView::paintEvent(), QGraphicsItemEffectSourcePrivate::pixmap(), QGraphicsItemGroup::removeFromGroup(), QGraphicsItemPrivate::sceneEffectiveBoundingRect(), and QDeclarativeFlipablePrivate::updateSceneTransformFromParent().

4432 {
4434  return d_ptr->sceneTransform;
4435 }
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ scroll()

void QGraphicsItem::scroll ( qreal  dx,
qreal  dy,
const QRectF rect = QRectF() 
)

Scrolls the contents of rect by dx, dy.

Since
4.4 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);
See also
boundingRect()

Definition at line 6114 of file qgraphicsitem.cpp.

6115 {
6116  Q_D(QGraphicsItem);
6117  if (dx == 0.0 && dy == 0.0)
6118  return;
6119  if (!d->scene)
6120  return;
6121 
6122  // Accelerated scrolling means moving pixels from one location to another
6123  // and only redraw the newly exposed area. The following requirements must
6124  // be fulfilled in order to do that:
6125  //
6126  // 1) Item is opaque.
6127  // 2) Item is not overlapped by other items.
6128  //
6129  // There's (yet) no way to detect whether an item is opaque or not, which means
6130  // we cannot do accelerated scrolling unless the cache is enabled. In case of using
6131  // DeviceCoordinate cache we also have to take the device transform into account in
6132  // order to determine whether we can do accelerated scrolling or not. That's left out
6133  // for simplicity here, but it is definitely something we can consider in the future
6134  // as a performance improvement.
6135  if (d->cacheMode != QGraphicsItem::ItemCoordinateCache
6136  || !qFuzzyIsNull(dx - int(dx)) || !qFuzzyIsNull(dy - int(dy))) {
6137  update(rect);
6138  return;
6139  }
6140 
6141  QGraphicsItemCache *cache = d->extraItemCache();
6142  if (cache->allExposed || cache->fixedSize.isValid()) {
6143  // Cache is either invalidated or item is scaled (see QGraphicsItem::setCacheMode).
6144  update(rect);
6145  return;
6146  }
6147 
6148  // Find pixmap in cache.
6149  QPixmap cachedPixmap;
6150  if (!QPixmapCache::find(cache->key, &cachedPixmap)) {
6151  update(rect);
6152  return;
6153  }
6154 
6155  QRect scrollRect = (rect.isNull() ? boundingRect() : rect).toAlignedRect();
6156  if (!scrollRect.intersects(cache->boundingRect))
6157  return; // Nothing to scroll.
6158 
6159  // Remove from cache to avoid deep copy when modifying.
6160  QPixmapCache::remove(cache->key);
6161 
6162  QRegion exposed;
6163  cachedPixmap.scroll(dx, dy, scrollRect.translated(-cache->boundingRect.topLeft()), &exposed);
6164 
6165  // Reinsert into cache.
6166  cache->key = QPixmapCache::insert(cachedPixmap);
6167 
6168  // Translate the existing expose.
6169  for (int i = 0; i < cache->exposed.size(); ++i) {
6170  QRectF &e = cache->exposed[i];
6171  if (!rect.isNull() && !e.intersects(rect))
6172  continue;
6173  e.translate(dx, dy);
6174  }
6175 
6176  // Append newly exposed areas. Note that the exposed region is currently
6177  // in pixmap coordinates, so we have to translate it to item coordinates.
6178  exposed.translate(cache->boundingRect.topLeft());
6179  const QVector<QRect> exposedRects = exposed.rects();
6180  for (int i = 0; i < exposedRects.size(); ++i)
6181  cache->exposed += exposedRects.at(i);
6182 
6183  // Trigger update. This will redraw the newly exposed area and make sure
6184  // the pixmap is re-blitted in case there are overlapping items.
6185  d->scene->d_func()->markDirty(this, rect);
6186 }
double d
Definition: qnumeric_p.h:62
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
bool intersects(const QRectF &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:2744
void update(const QRectF &rect=QRectF())
Schedules a redraw of the area covered by rect in this item.
#define Q_D(Class)
Definition: qglobal.h:2482
static QPixmap * find(const QString &key)
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed=0)
Definition: qpixmap.h:307
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
void translate(qreal dx, qreal dy)
Moves the rectangle dx along the x-axis and dy along the y-axis, relative to the current position...
Definition: qrect.h:716
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QPixmapCache::Key key
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
QVector< QRectF > exposed
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
void translate(int dx, int dy)
Translates (moves) the region dx along the X axis and dy along the Y axis.
Definition: qregion.cpp:4116
static void remove(const QString &key)
Removes the pixmap associated with key from the cache.
bool intersects(const QRect &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:1429
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288

◆ 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 3076 of file qgraphicsitem.cpp.

Referenced by QGraphicsTextItem::QGraphicsTextItem().

3077 {
3078  d_ptr->acceptDrops = on;
3079 }
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ 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(0).

See also
acceptedMouseButtons(), mousePressEvent()

Definition at line 3112 of file qgraphicsitem.cpp.

Referenced by QDeclarativeGestureArea::QDeclarativeGestureArea(), and QDeclarativeMouseArea::setAcceptedButtons().

3113 {
3114  if (Qt::MouseButtons(d_ptr->acceptedMouseButtons) != buttons) {
3115  if (buttons == 0 && d_ptr->scene && d_ptr->scene->mouseGrabberItem() == this
3116  && d_ptr->scene->d_func()->lastMouseGrabberItemHasImplicitMouseGrab) {
3117  ungrabMouse();
3118  }
3120  }
3121 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
static Qt::MouseButtons buttons
QGraphicsScene * scene
QGraphicsItem * mouseGrabberItem() const
Returns the current mouse grabber item, or 0 if no item is currently grabbing the mouse...
unsigned int quint32
Definition: qglobal.h:938
void ungrabMouse()
Releases the mouse grab.

◆ setAcceptHoverEvents()

void QGraphicsItem::setAcceptHoverEvents ( bool  enabled)

If enabled is true, this item will accept hover events; otherwise, it will ignore them.

Since
4.4

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 3187 of file qgraphicsitem.cpp.

Referenced by QGraphicsTextItem::QGraphicsTextItem(), setAcceptsHoverEvents(), and QDeclarativeMouseArea::setHoverEnabled().

3188 {
3189  if (d_ptr->acceptsHover == quint32(enabled))
3190  return;
3192  if (d_ptr->acceptsHover && d_ptr->scene && d_ptr->scene->d_func()->allItemsIgnoreHoverEvents) {
3193  d_ptr->scene->d_func()->allItemsIgnoreHoverEvents = false;
3194  d_ptr->scene->d_func()->enableMouseTrackingOnViews();
3195  }
3196 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsScene * scene
unsigned int quint32
Definition: qglobal.h:938
#define enabled

◆ setAcceptsHoverEvents()

void QGraphicsItem::setAcceptsHoverEvents ( bool  enabled)

Use setAcceptHoverEvents(enabled) instead.

Definition at line 3206 of file qgraphicsitem.cpp.

3207 {
3209 }
void setAcceptHoverEvents(bool enabled)
If enabled is true, this item will accept hover events; otherwise, it will ignore them...
#define enabled

◆ setAcceptTouchEvents()

void QGraphicsItem::setAcceptTouchEvents ( bool  enabled)

If enabled is true, this item will accept touch events; otherwise, it will ignore them.

Since
4.6

By default, items do not accept touch events.

Definition at line 3236 of file qgraphicsitem.cpp.

Referenced by QDeclarativeGestureArea::QDeclarativeGestureArea().

3237 {
3239  return;
3241  if (d_ptr->acceptTouchEvents && d_ptr->scene && d_ptr->scene->d_func()->allItemsIgnoreTouchEvents) {
3242  d_ptr->scene->d_func()->allItemsIgnoreTouchEvents = false;
3243  d_ptr->scene->d_func()->enableTouchEventsOnViews();
3244  }
3245 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsScene * scene
unsigned int quint32
Definition: qglobal.h:938
#define enabled

◆ setActive()

void QGraphicsItem::setActive ( bool  active)

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

Since
4.6

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 3387 of file qgraphicsitem.cpp.

3388 {
3389  d_ptr->explicitActivate = 1;
3390  d_ptr->wantsActive = active;
3391  if (d_ptr->scene) {
3392  if (active) {
3393  // Activate this item.
3394  d_ptr->scene->setActivePanel(this);
3395  } else {
3396  // Deactivate this item, and reactivate the last active item
3397  // (if any).
3398  QGraphicsItem *lastActive = d_ptr->scene->d_func()->lastActivePanel;
3399  d_ptr->scene->setActivePanel(lastActive != this ? lastActive : 0);
3400  }
3401  }
3402 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QGraphicsScene * scene
void setActivePanel(QGraphicsItem *item)
Activates item, which must be an item in this scene.

◆ setBoundingRegionGranularity()

void QGraphicsItem::setBoundingRegionGranularity ( qreal  granularity)

Sets the bounding region granularity to granularity; a value between and including 0 and 1.

Since
4.4 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 5640 of file qgraphicsitem.cpp.

5641 {
5642  if (granularity < 0.0 || granularity > 1.0) {
5643  qWarning("QGraphicsItem::setBoundingRegionGranularity: invalid granularity %g", granularity);
5644  return;
5645  }
5646  if (granularity == 0.0) {
5649  return;
5650  }
5653  QVariant::fromValue<qreal>(granularity));
5654 }
void unsetExtra(Extra type)
QScopedPointer< QGraphicsItemPrivate > d_ptr
quint32 hasBoundingRegionGranularity
Q_CORE_EXPORT void qWarning(const char *,...)
void setExtra(Extra type, const QVariant &value)

◆ setCacheMode()

void QGraphicsItem::setCacheMode ( CacheMode  mode,
const QSize logicalCacheSize = QSize() 
)

Sets the item's cache mode to mode.

Since
4.4

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 enabled, the item's paint() function will be called only once for each call to update(); 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.

See also
CacheMode, QPixmapCache::setCacheLimit()

Definition at line 2098 of file qgraphicsitem.cpp.

Referenced by QGraphicsSvgItem::setCachingEnabled().

2099 {
2100  CacheMode lastMode = CacheMode(d_ptr->cacheMode);
2101  d_ptr->cacheMode = mode;
2102  bool noVisualChange = (mode == NoCache && lastMode == NoCache)
2103  || (mode == NoCache && lastMode == DeviceCoordinateCache)
2104  || (mode == DeviceCoordinateCache && lastMode == NoCache)
2105  || (mode == DeviceCoordinateCache && lastMode == DeviceCoordinateCache);
2106  if (mode == NoCache) {
2108  } else {
2110 
2111  // Reset old cache
2112  cache->purge();
2113 
2114  if (mode == ItemCoordinateCache) {
2115  if (lastMode == mode && cache->fixedSize == logicalCacheSize)
2116  noVisualChange = true;
2117  cache->fixedSize = logicalCacheSize;
2118  }
2119  }
2120  if (!noVisualChange)
2121  update();
2122 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
void update(const QRectF &rect=QRectF())
Schedules a redraw of the area covered by rect in this item.
void purge()
Empty all cached pixmaps from the pixmap cache.
CacheMode
This enum describes QGraphicsItem&#39;s cache modes.
QGraphicsItemCache * extraItemCache() const

◆ 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 list of predefined cursor objects for a range of useful shapes.

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

item->setCursor(Qt::IBeamCursor);

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

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

Definition at line 2276 of file qgraphicsitem.cpp.

Referenced by QApplicationPrivate::dispatchEnterLeave().

2277 {
2278  const QVariant cursorVariant(itemChange(ItemCursorChange, QVariant::fromValue<QCursor>(cursor)));
2279  d_ptr->setExtra(QGraphicsItemPrivate::ExtraCursor, qvariant_cast<QCursor>(cursorVariant));
2280  d_ptr->hasCursor = 1;
2281  if (d_ptr->scene) {
2282  d_ptr->scene->d_func()->allItemsUseDefaultCursor = false;
2283  foreach (QGraphicsView *view, d_ptr->scene->views()) {
2284  view->viewport()->setMouseTracking(true);
2285  // Note: Some of this logic is duplicated in QGraphicsView's mouse events.
2286  if (view->underMouse()) {
2287  foreach (QGraphicsItem *itemUnderCursor, view->items(view->mapFromGlobal(QCursor::pos()))) {
2288  if (itemUnderCursor->hasCursor()) {
2289  QMetaObject::invokeMethod(view, "_q_setViewportCursor",
2290  Q_ARG(QCursor, itemUnderCursor->cursor()));
2291  break;
2292  }
2293  }
2294  break;
2295  }
2296  }
2297  }
2298  itemChange(ItemCursorHasChanged, cursorVariant);
2299 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition: qcursor.h:89
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
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&#39;s ...
QGraphicsScene * scene
#define Q_ARG(type, data)
Definition: qobjectdefs.h:246
bool underMouse() const
Returns true if the widget is under the mouse cursor; otherwise returns false.
Definition: qwidget.h:996
QCursor cursor() const
Returns the current cursor shape for the item.
QWidget * viewport() const
Returns the viewport widget.
QList< QGraphicsView * > views() const
Returns a list of all the views that display this scene.
void setMouseTracking(bool enable)
Definition: qwidget.h:990
bool hasCursor() const
Returns true if this item has a cursor set; otherwise, false is returned.
void setExtra(Extra type, const QVariant &value)
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
QList< QGraphicsItem * > items() const
Returns a list of all the items in the associated scene, in descending stacking order (i...
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310

◆ 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 6976 of file qgraphicsitem.cpp.

Referenced by QmlJSDebugger::LiveSelectionIndicator::setItems(), and QmlJSDebugger::SubcomponentMaskLayerItem::SubcomponentMaskLayerItem().

6977 {
6978  qt_dataStore()->data[this][key] = value;
6979 }
int key

◆ 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 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 reenabled 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 2700 of file qgraphicsitem.cpp.

Referenced by QGraphicsProxyWidget::eventFilter().

2701 {
2702  d_ptr->setEnabledHelper(enabled, /* explicitly = */ true);
2703 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
void setEnabledHelper(bool newEnabled, bool explicitly, bool update=true)
Sets this item&#39;s visibility to newEnabled.
#define enabled

◆ 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.

Warning
This function is not part of the public interface.

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

Definition at line 7905 of file qgraphicsitem.cpp.

7906 {
7908  Q_UNUSED(variant);
7909 }
virtual QVariant extension(const QVariant &variant) const
Note: This is provided as a hook to avoid future problems related to adding virtual functions...
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ setFiltersChildEvents()

void QGraphicsItem::setFiltersChildEvents ( bool  enabled)

If enabled is true, this item is set to filter all events for all its children (i.

Since
4.6

e., all events intented 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 3280 of file qgraphicsitem.cpp.

3281 {
3283  return;
3284 
3287 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
void updateAncestorFlag(QGraphicsItem::GraphicsItemFlag childFlag, AncestorFlag flag=NoFlag, bool enabled=false, bool root=true)
Propagates the ancestor flag flag with value enabled to all this item&#39;s children. ...
GraphicsItemFlag
This enum describes different flags that you can set on an item to toggle different features in the i...
Definition: qgraphicsitem.h:92
#define enabled

◆ 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 1901 of file qgraphicsitem.cpp.

Referenced by _q_qgraphicsItemSetFlag(), QmlJSDebugger::BoundingBox::BoundingBox(), QmlJSDebugger::LiveLayerItem::LiveLayerItem(), QGraphicsTextItem::QGraphicsTextItem(), QDeclarativeItem::setClip(), QGraphicsWidget::setFocusPolicy(), QmlJSDebugger::LiveSelectionIndicator::setItems(), QDeclarativeTextInput::setReadOnly(), QDeclarativeTextEdit::setReadOnly(), QGraphicsWidget::setWindowFlags(), setZValue(), and ShaderEffectItem::ShaderEffectItem().

1902 {
1903  if (enabled)
1904  setFlags(GraphicsItemFlags(d_ptr->flags) | flag);
1905  else
1906  setFlags(GraphicsItemFlags(d_ptr->flags) & ~flag);
1907 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
void setFlags(GraphicsItemFlags flags)
Sets the item flags to flags.
#define enabled

◆ 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 1945 of file qgraphicsitem.cpp.

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

1946 {
1947  // Notify change and check for adjustment.
1948  if (quint32(d_ptr->flags) == quint32(flags))
1949  return;
1950  flags = GraphicsItemFlags(itemChange(ItemFlagsChange, quint32(flags)).toUInt());
1951  if (quint32(d_ptr->flags) == quint32(flags))
1952  return;
1953  if (d_ptr->scene && d_ptr->scene->d_func()->indexMethod != QGraphicsScene::NoIndex)
1954  d_ptr->scene->d_func()->index->itemChange(this, ItemFlagsChange, &flags);
1955 
1956  // Flags that alter the geometry of the item (or its children).
1958  bool fullUpdate = (quint32(flags) & geomChangeFlagsMask) != (d_ptr->flags & geomChangeFlagsMask);
1959  if (fullUpdate)
1960  d_ptr->updatePaintedViewBoundingRects(/*children=*/true);
1961 
1962  // Keep the old flags to compare the diff.
1963  GraphicsItemFlags oldFlags = GraphicsItemFlags(d_ptr->flags);
1964 
1965  // Update flags.
1966  d_ptr->flags = flags;
1967 
1968  if (!(d_ptr->flags & ItemIsFocusable) && hasFocus()) {
1969  // Clear focus on the item if it has focus when the focusable flag
1970  // is unset.
1971  clearFocus();
1972  }
1973 
1974  if (!(d_ptr->flags & ItemIsSelectable) && isSelected()) {
1975  // Unselect the item if it is selected when the selectable flag is
1976  // unset.
1977  setSelected(false);
1978  }
1979 
1980  if ((flags & ItemClipsChildrenToShape) != (oldFlags & ItemClipsChildrenToShape)) {
1981  // Item children clipping changes. Propagate the ancestor flag to
1982  // all children.
1983  d_ptr->updateAncestorFlag(ItemClipsChildrenToShape);
1984  // The childrenBoundingRect is clipped to the boundingRect in case of ItemClipsChildrenToShape,
1985  // which means we have to invalidate the cached childrenBoundingRect whenever this flag changes.
1987  d_ptr->markParentDirty(true);
1988  }
1989 
1990  if ((flags & ItemIgnoresTransformations) != (oldFlags & ItemIgnoresTransformations)) {
1991  // Item children clipping changes. Propagate the ancestor flag to
1992  // all children.
1993  d_ptr->updateAncestorFlag(ItemIgnoresTransformations);
1994  }
1995 
1996  if ((flags & ItemNegativeZStacksBehindParent) != (oldFlags & ItemNegativeZStacksBehindParent)) {
1997  // NB! We change the flags directly here, so we must also update d_ptr->flags.
1998  // Note that this has do be done before the ItemStacksBehindParent check
1999  // below; otherwise we will loose the change.
2000 
2001  // Update stack-behind.
2002  if (d_ptr->z < qreal(0.0))
2004  else
2006  d_ptr->flags = flags;
2007  }
2008 
2009  if ((flags & ItemStacksBehindParent) != (oldFlags & ItemStacksBehindParent)) {
2010  // NB! This check has to come after the ItemNegativeZStacksBehindParent
2011  // check above. Be careful.
2012 
2013  // Ensure child item sorting is up to date when toggling this flag.
2014  if (d_ptr->parent)
2016  else if (d_ptr->scene)
2017  d_ptr->scene->d_func()->needSortTopLevelItems = 1;
2018  }
2019 
2020  if ((flags & ItemAcceptsInputMethod) != (oldFlags & ItemAcceptsInputMethod)) {
2021  // Update input method sensitivity in any views.
2022  if (d_ptr->scene)
2023  d_ptr->scene->d_func()->updateInputMethodSensitivityInViews();
2024  }
2025 
2026 
2027  if ((d_ptr->panelModality != NonModal)
2028  && d_ptr->scene
2029  && (flags & ItemIsPanel) != (oldFlags & ItemIsPanel)) {
2030  // update the panel's modal state
2031  if (flags & ItemIsPanel)
2032  d_ptr->scene->d_func()->enterModal(this);
2033  else
2034  d_ptr->scene->d_func()->leaveModal(this);
2035  }
2036 
2037  if (d_ptr->scene) {
2038  if ((flags & ItemSendsScenePositionChanges) != (oldFlags & ItemSendsScenePositionChanges)) {
2039  if (flags & ItemSendsScenePositionChanges)
2040  d_ptr->scene->d_func()->registerScenePosItem(this);
2041  else
2042  d_ptr->scene->d_func()->unregisterScenePosItem(this);
2043  }
2044  d_ptr->scene->d_func()->markDirty(this, QRectF(), /*invalidateChildren=*/true);
2045  }
2046 
2047  // Notify change.
2049 }
bool hasFocus() const
Returns true if this item is active, and it or its focus proxy has keyboard input focus; otherwise...
QGraphicsItem * parent
double qreal
Definition: qglobal.h:1193
QGraphicsItem::PanelModality panelModality
QScopedPointer< QGraphicsItemPrivate > d_ptr
void setSelected(bool selected)
If selected is true and this item is selectable, this item is selected; otherwise, it is unselected.
void clearFocus()
Takes keyboard input focus from the 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&#39;s ...
QGraphicsScene * scene
void updateAncestorFlag(QGraphicsItem::GraphicsItemFlag childFlag, AncestorFlag flag=NoFlag, bool enabled=false, bool root=true)
Propagates the ancestor flag flag with value enabled to all this item&#39;s children. ...
bool isSelected() const
Returns true if this item is selected; otherwise, false is returned.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
unsigned int quint32
Definition: qglobal.h:938
void markParentDirty(bool updateBoundingRect=false)
void updatePaintedViewBoundingRects(bool updateChildren)

◆ setFocus()

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

Gives keyboard input focus to this item.

The focusReason argument will be passed into any 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 focus in event with focusReason. If another item already has focus, that item will first receive a focus out event indicating that it has lost input focus.

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

Definition at line 3442 of file qgraphicsitem.cpp.

Referenced by QGraphicsScene::addItem(), QGraphicsWidget::focusNextPrevChild(), QDeclarativeItem::forceActiveFocus(), QGraphicsScenePrivate::setActivePanelHelper(), QDeclarativeItem::setFocus(), QGraphicsScene::setFocusItem(), and QGraphicsScenePrivate::setFocusItemHelper().

3443 {
3444  d_ptr->setFocusHelper(focusReason, /* climb = */ true, /* focusFromHide = */ false);
3445 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
void setFocusHelper(Qt::FocusReason focusReason, bool climb, bool focusFromHide)

◆ setFocusProxy()

void QGraphicsItem::setFocusProxy ( QGraphicsItem item)

Sets the item's focus proxy to item.

Since
4.6

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 3605 of file qgraphicsitem.cpp.

3606 {
3607  if (item == d_ptr->focusProxy)
3608  return;
3609  if (item == this) {
3610  qWarning("QGraphicsItem::setFocusProxy: cannot assign self as focus proxy");
3611  return;
3612  }
3613  if (item) {
3614  if (item->d_ptr->scene != d_ptr->scene) {
3615  qWarning("QGraphicsItem::setFocusProxy: focus proxy must be in same scene");
3616  return;
3617  }
3618  for (QGraphicsItem *f = item->focusProxy(); f != 0; f = f->focusProxy()) {
3619  if (f == this) {
3620  qWarning("QGraphicsItem::setFocusProxy: %p is already in the focus proxy chain", item);
3621  return;
3622  }
3623  }
3624  }
3625 
3626  QGraphicsItem *lastFocusProxy = d_ptr->focusProxy;
3627  if (lastFocusProxy)
3628  lastFocusProxy->d_ptr->focusProxyRefs.removeOne(&d_ptr->focusProxy);
3629  d_ptr->focusProxy = item;
3630  if (item)
3631  item->d_ptr->focusProxyRefs << &d_ptr->focusProxy;
3632 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QList< QGraphicsItem ** > focusProxyRefs
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QGraphicsScene * scene
QGraphicsItem * focusProxy() const
Returns this item&#39;s focus proxy, or 0 if this item has no focus proxy.
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
Definition: qlist.h:796
Q_CORE_EXPORT void qWarning(const char *,...)
QGraphicsItem * focusProxy

◆ setGraphicsEffect()

void QGraphicsItem::setGraphicsEffect ( QGraphicsEffect effect)

Sets effect as the item's effect.

If there already is an effect installed on this item, QGraphicsItem will delete the existing effect before installing the new effect.

If effect is the installed on a different item, setGraphicsEffect() will remove the effect from the item and install it on this item.

QGraphicsItem takes ownership of effect.

Note
This function will apply the effect on itself and all its children.
Since
4.6

Definition at line 2911 of file qgraphicsitem.cpp.

Referenced by ShaderEffectSource::attachSourceItem().

2912 {
2913  if (d_ptr->graphicsEffect == effect)
2914  return;
2915 
2916  if (d_ptr->graphicsEffect) {
2917  delete d_ptr->graphicsEffect;
2918  d_ptr->graphicsEffect = 0;
2919  } else if (d_ptr->parent) {
2921  }
2922 
2923  if (effect) {
2924  // Set new effect.
2926  QGraphicsEffectSource *source = new QGraphicsEffectSource(*sourced);
2927  d_ptr->graphicsEffect = effect;
2928  effect->d_func()->setGraphicsEffectSource(source);
2930  }
2931 }
friend class QGraphicsItemEffectSourcePrivate
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsEffectSource class represents the source on which a QGraphicsEffect is installed on...
QGraphicsEffect * graphicsEffect
void prepareGeometryChange()
Prepares the item for a geometry change.
void updateChildWithGraphicsEffectFlagRecursively()

◆ setGroup()

void QGraphicsItem::setGroup ( QGraphicsItemGroup group)

Adds this item to the item group group.

If group is 0, 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 1615 of file qgraphicsitem.cpp.

1616 {
1617  if (!group) {
1618  if (QGraphicsItemGroup *group = this->group())
1619  group->removeFromGroup(this);
1620  } else {
1621  group->addToGroup(this);
1622  }
1623 }
void removeFromGroup(QGraphicsItem *item)
Removes the specified item from this group.
QGraphicsItemGroup * group() const
Returns a pointer to this item&#39;s item group, or 0 if this item is not member of a group...
void addToGroup(QGraphicsItem *item)
Adds the given item and item&#39;s child items to this item group.
The QGraphicsItemGroup class provides a container that treats a group of items as a single item...

◆ setHandlesChildEvents()

void QGraphicsItem::setHandlesChildEvents ( bool  enabled)

If enabled is true, this item is set to handle all events for all its children (i.

e., all events intented 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 3337 of file qgraphicsitem.cpp.

Referenced by QGraphicsItemGroup::QGraphicsItemGroup().

3338 {
3340  return;
3341 
3344 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
void updateAncestorFlag(QGraphicsItem::GraphicsItemFlag childFlag, AncestorFlag flag=NoFlag, bool enabled=false, bool root=true)
Propagates the ancestor flag flag with value enabled to all this item&#39;s children. ...
GraphicsItemFlag
This enum describes different flags that you can set on an item to toggle different features in the i...
Definition: qgraphicsitem.h:92
#define enabled

◆ 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(), QInputContext

Definition at line 7806 of file qgraphicsitem.cpp.

Referenced by QGraphicsViewPrivate::updateInputMethodSensitivity().

7807 {
7808  Q_D(QGraphicsItem);
7809  d->imHints = hints;
7810  if (!hasFocus())
7811  return;
7812  d->scene->d_func()->updateInputMethodSensitivityInViews();
7813 #if !defined(QT_NO_IM) && (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN))
7815  if (!fw)
7816  return;
7817  for (int i = 0 ; i < scene()->views().count() ; ++i)
7818  if (scene()->views().at(i) == fw)
7819  if (QInputContext *inputContext = fw->inputContext())
7820  inputContext->update();
7821 #endif
7822 }
double d
Definition: qnumeric_p.h:62
bool hasFocus() const
Returns true if this item is active, and it or its focus proxy has keyboard input focus; otherwise...
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_D(Class)
Definition: qglobal.h:2482
QList< QGraphicsView * > views() const
Returns a list of all the views that display this scene.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QInputContext * inputContext()
This function returns the QInputContext for this widget.
Definition: qwidget.cpp:474
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
The QInputContext class abstracts the input method dependent data and composing state.
Definition: qinputcontext.h:83
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or 0 if no widget in this applicati...

◆ setMatrix()

void QGraphicsItem::setMatrix ( const QMatrix matrix,
bool  combine = false 
)

Sets the item's affine transformation matrix.

This is a subset or the item's full transformation matrix, and might not represent the item's full transformation.

Use setTransform() instead.

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

Definition at line 4644 of file qgraphicsitem.cpp.

Referenced by QGraphicsItemAnimation::setStep().

4645 {
4646  if (!d_ptr->transformData)
4648 
4649  QTransform newTransform(combine ? QTransform(matrix) * d_ptr->transformData->transform : QTransform(matrix));
4650  if (d_ptr->transformData->transform == newTransform)
4651  return;
4652 
4653  // Update and set the new transformation.
4654  if (!(d_ptr->flags & ItemSendsGeometryChanges)) {
4655  d_ptr->setTransformHelper(newTransform);
4656  return;
4657  }
4658 
4659  // Notify the item that the transformation matrix is changing.
4660  const QVariant newMatrixVariant = QVariant::fromValue<QMatrix>(newTransform.toAffine());
4661  newTransform = QTransform(qvariant_cast<QMatrix>(itemChange(ItemMatrixChange, newMatrixVariant)));
4662  if (d_ptr->transformData->transform == newTransform)
4663  return;
4664 
4665  // Update and set the new transformation.
4666  d_ptr->setTransformHelper(newTransform);
4667 
4668  // Send post-notification.
4669  itemChange(ItemTransformHasChanged, QVariant::fromValue<QTransform>(newTransform));
4670 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QScopedPointer< QGraphicsItemPrivate > d_ptr
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&#39;s ...
void setTransformHelper(const QTransform &transform)
Sets the transform transform.
TransformData * transformData
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ setOpacity()

void QGraphicsItem::setOpacity ( qreal  opacity)

Sets this item's local opacity, between 0.

Since
4.5

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.

See also
opacity(), effectiveOpacity()

Definition at line 2849 of file qgraphicsitem.cpp.

Referenced by QDeclarativeFlipablePrivate::updateSceneTransformFromParent().

2850 {
2851  // Notify change.
2852  const QVariant newOpacityVariant(itemChange(ItemOpacityChange, opacity));
2853 
2854  // Normalized opacity
2855  qreal newOpacity = qBound(qreal(0), newOpacityVariant.toReal(), qreal(1));
2856 
2857  // No change? Done.
2858  if (newOpacity == d_ptr->opacity)
2859  return;
2860 
2861  bool wasFullyTransparent = d_ptr->isOpacityNull();
2862  d_ptr->opacity = newOpacity;
2863 
2864  // Notify change.
2865  itemChange(ItemOpacityHasChanged, newOpacityVariant);
2866 
2867  // Update.
2868  if (d_ptr->scene) {
2869 #ifndef QT_NO_GRAPHICSEFFECT
2873 #endif //QT_NO_GRAPHICSEFFECT
2874  d_ptr->scene->d_func()->markDirty(this, QRectF(),
2875  /*invalidateChildren=*/true,
2876  /*force=*/false,
2877  /*ignoreOpacity=*/d_ptr->isOpacityNull());
2878  if (wasFullyTransparent)
2880  }
2881 
2882  if (d_ptr->isObject)
2883  emit static_cast<QGraphicsObject *>(this)->opacityChanged();
2884 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void invalidateParentGraphicsEffectsRecursively()
double qreal
Definition: qglobal.h:1193
QScopedPointer< QGraphicsItemPrivate > d_ptr
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&#39;s ...
QGraphicsScene * scene
bool isOpacityNull() const
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
quint32 paintedViewBoundingRectsNeedRepaint
#define emit
Definition: qobjectdefs.h:76
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
qreal opacity() const
Returns this item&#39;s local opacity, which is between 0.
The QGraphicsObject class provides a base class for all graphics items that require signals...
void invalidateChildGraphicsEffectsRecursively(InvalidateReason reason)

◆ setPanelModality()

void QGraphicsItem::setPanelModality ( PanelModality  panelModality)

Sets the modality for this item to panelModality.

Since
4.6

Changing the modality of a visible item takes effect immediately.

Definition at line 2147 of file qgraphicsitem.cpp.

2148 {
2150  return;
2151 
2152  PanelModality previousModality = d_ptr->panelModality;
2153  bool enterLeaveModal = (isPanel() && d_ptr->scene && isVisible());
2154  if (enterLeaveModal && panelModality == NonModal)
2155  d_ptr->scene->d_func()->leaveModal(this);
2157  if (enterLeaveModal && d_ptr->panelModality != NonModal)
2158  d_ptr->scene->d_func()->enterModal(this, previousModality);
2159 }
QGraphicsItem::PanelModality panelModality
QScopedPointer< QGraphicsItemPrivate > d_ptr
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
QGraphicsScene * scene
PanelModality panelModality() const
Returns the modality for this item.
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
PanelModality
This enum specifies the behavior of a modal panel.

◆ 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 add the item to the scene yourself.

Calling this function on an item that is an ancestor of newParent have undefined behaviour.

See also
parentItem(), childItems()

Definition at line 1786 of file qgraphicsitem.cpp.

Referenced by QDeclarativeLoaderPrivate::_q_sourceLoaded(), QGraphicsScene::addItem(), QGraphicsItemGroup::addToGroup(), QGraphicsItemPrivate::children_append(), QGraphicsItemPrivate::children_clear(), children_clear_helper(), QDeclarativeLoaderPrivate::clear(), QDeclarativeItemPrivate::data_append(), QDeclarativeFlickablePrivate::data_append(), QGraphicsItem(), qgraphicsobject_autoParent(), QGraphicsItemGroup::removeFromGroup(), QGraphicsScenePrivate::removeItemHelper(), QDeclarativeItem::setParentItem(), and ~QGraphicsItem().

1787 {
1788  if (newParent == this) {
1789  qWarning("QGraphicsItem::setParentItem: cannot assign %p as a parent of itself", this);
1790  return;
1791  }
1792  if (newParent == d_ptr->parent)
1793  return;
1794 
1795  const QVariant newParentVariant(itemChange(QGraphicsItem::ItemParentChange,
1796  QVariant::fromValue<QGraphicsItem *>(newParent)));
1797  newParent = qvariant_cast<QGraphicsItem *>(newParentVariant);
1798  if (newParent == d_ptr->parent)
1799  return;
1800 
1801  const QVariant thisPointerVariant(QVariant::fromValue<QGraphicsItem *>(this));
1802  d_ptr->setParentItemHelper(newParent, &newParentVariant, &thisPointerVariant);
1803 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void setParentItemHelper(QGraphicsItem *parent, const QVariant *newParentVariant, const QVariant *thisPointerVariant)
Make sure not to trigger any pure virtual function calls (e.
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
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&#39;s ...
Q_CORE_EXPORT void qWarning(const char *,...)
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ 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 3947 of file qgraphicsitem.cpp.

Referenced by QGraphicsItemGroup::addToGroup(), QDeclarativeGridView::createdItem(), mouseMoveEvent(), QGraphicsItemGroup::removeFromGroup(), QGraphicsWidget::setGeometry(), FxGridItem::setPosition(), QGraphicsItemAnimation::setStep(), setX(), setY(), and QDeclarativeGridViewPrivate::updateUnrequestedPositions().

3948 {
3949  if (d_ptr->pos == pos)
3950  return;
3951 
3952  if (d_ptr->inDestructor)
3953  return;
3954 
3955  // Update and repositition.
3957  d_ptr->setPosHelper(pos);
3958  if (d_ptr->isWidget)
3959  static_cast<QGraphicsWidget *>(this)->d_func()->setGeometryFromSetPos();
3962  return;
3963  }
3964 
3965  // Notify the item that the position is changing.
3966  const QVariant newPosVariant(itemChange(ItemPositionChange, QVariant::fromValue<QPointF>(pos)));
3967  QPointF newPos = newPosVariant.toPointF();
3968  if (newPos == d_ptr->pos)
3969  return;
3970 
3971  // Update and repositition.
3972  d_ptr->setPosHelper(newPos);
3973 
3974  // Send post-notification.
3977 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
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&#39;s ...
virtual void setPosHelper(const QPointF &pos)
Sets the position pos.
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ setPos() [2/2]

void QGraphicsItem::setPos ( qreal  x,
qreal  y 
)
inline

This convenience function is equivalent to calling setPos(QPointF(x, y)).

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

Definition at line 501 of file qgraphicsitem.h.

502 { setPos(QPointF(ax, ay)); }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void setPos(const QPointF &pos)
Sets the position of the item to pos, which is in parent coordinates.

◆ setRotation()

void QGraphicsItem::setRotation ( qreal  angle)

Sets the clockwise rotation angle, in degrees, around the Z axis.

Since
4.6

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 4120 of file qgraphicsitem.cpp.

Referenced by QDeclarativeParentChangePrivate::doChange(), and QDeclarativePinchArea::updatePinch().

4121 {
4123  qreal newRotation = angle;
4124 
4126  // Notify the item that the rotation is changing.
4127  const QVariant newRotationVariant(itemChange(ItemRotationChange, angle));
4128  newRotation = newRotationVariant.toReal();
4129  }
4130 
4131  if (!d_ptr->transformData)
4133 
4134  if (d_ptr->transformData->rotation == newRotation)
4135  return;
4136 
4137  d_ptr->transformData->rotation = newRotation;
4138  d_ptr->transformData->onlyTransform = false;
4140 
4141  // Send post-notification.
4143  itemChange(ItemRotationHasChanged, newRotation);
4144 
4145  if (d_ptr->isObject)
4146  emit static_cast<QGraphicsObject *>(this)->rotationChanged();
4147 
4149 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double qreal
Definition: qglobal.h:1193
QScopedPointer< QGraphicsItemPrivate > d_ptr
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&#39;s ...
#define emit
Definition: qobjectdefs.h:76
qreal angle(const QPointF &p1, const QPointF &p2)
void prepareGeometryChange()
Prepares the item for a geometry change.
virtual void transformChanged()
TransformData * transformData
The QGraphicsObject class provides a base class for all graphics items that require signals...

◆ setScale()

void QGraphicsItem::setScale ( qreal  factor)

Sets the scale factor of the item.

Since
4.6

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 4192 of file qgraphicsitem.cpp.

Referenced by QDeclarativeParentChangePrivate::doChange(), and QDeclarativePinchArea::updatePinch().

4193 {
4195  qreal newScale = factor;
4196 
4198  // Notify the item that the scale is changing.
4199  const QVariant newScaleVariant(itemChange(ItemScaleChange, factor));
4200  newScale = newScaleVariant.toReal();
4201  }
4202 
4203  if (!d_ptr->transformData)
4205 
4206  if (d_ptr->transformData->scale == newScale)
4207  return;
4208 
4209  d_ptr->transformData->scale = newScale;
4210  d_ptr->transformData->onlyTransform = false;
4212 
4213  // Send post-notification.
4215  itemChange(ItemScaleHasChanged, newScale);
4216 
4217  if (d_ptr->isObject)
4218  emit static_cast<QGraphicsObject *>(this)->scaleChanged();
4219 
4221 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double qreal
Definition: qglobal.h:1193
QScopedPointer< QGraphicsItemPrivate > d_ptr
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&#39;s ...
#define emit
Definition: qobjectdefs.h:76
void prepareGeometryChange()
Prepares the item for a geometry change.
virtual void transformChanged()
TransformData * transformData
The QGraphicsObject class provides a base class for all graphics items that require signals...

◆ 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 2745 of file qgraphicsitem.cpp.

Referenced by QGraphicsScene::clearSelection(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), setFlags(), setSelected(), QGraphicsScene::setSelectionArea(), and QGraphicsItemPrivate::setVisibleHelper().

2746 {
2747  if (QGraphicsItemGroup *group = this->group()) {
2748  group->setSelected(selected);
2749  return;
2750  }
2751 
2752  if (!(d_ptr->flags & ItemIsSelectable) || !d_ptr->enabled || !d_ptr->visible)
2753  selected = false;
2754  if (d_ptr->selected == selected)
2755  return;
2756  const QVariant newSelectedVariant(itemChange(ItemSelectedChange, quint32(selected)));
2757  bool newSelected = newSelectedVariant.toBool();
2758  if (d_ptr->selected == newSelected)
2759  return;
2760  d_ptr->selected = newSelected;
2761 
2762  update();
2763  if (d_ptr->scene) {
2764  QGraphicsScenePrivate *sceneD = d_ptr->scene->d_func();
2765  if (selected) {
2766  sceneD->selectedItems << this;
2767  } else {
2768  // QGraphicsScene::selectedItems() lazily pulls out all items that are
2769  // no longer selected.
2770  }
2771  if (!sceneD->selectionChanging)
2773  }
2774 
2775  // Deliver post-change notification.
2777 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QScopedPointer< QGraphicsItemPrivate > d_ptr
void setSelected(bool selected)
If selected is true and this item is selectable, this item is selected; otherwise, it is unselected.
QGraphicsItemGroup * group() const
Returns a pointer to this item&#39;s item group, or 0 if this item is not member of a group...
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&#39;s ...
QGraphicsScene * scene
void update(const QRectF &rect=QRectF())
Schedules a redraw of the area covered by rect in this item.
QSet< QGraphicsItem * > selectedItems
#define emit
Definition: qobjectdefs.h:76
void selectionChanged()
This signal is emitted by QGraphicsScene whenever the selection changes.
unsigned int quint32
Definition: qglobal.h:938
The QGraphicsItemGroup class provides a container that treats a group of items as a single item...

◆ setToolTip()

void QGraphicsItem::setToolTip ( const QString toolTip)

Sets the item's tool tip to toolTip.

If toolTip is empty, the item's tool tip is cleared.

See also
toolTip(), QToolTip

Definition at line 2232 of file qgraphicsitem.cpp.

Referenced by QGraphicsProxyWidget::eventFilter().

2233 {
2234  const QVariant toolTipVariant(itemChange(ItemToolTipChange, toolTip));
2235  d_ptr->setExtra(QGraphicsItemPrivate::ExtraToolTip, toolTipVariant.toString());
2236  itemChange(ItemToolTipHasChanged, toolTipVariant);
2237 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QScopedPointer< QGraphicsItemPrivate > d_ptr
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&#39;s ...
void setExtra(Extra type, const QVariant &value)

◆ setTransform()

void QGraphicsItem::setTransform ( const QTransform matrix,
bool  combine = false 
)

Sets the item's current transformation matrix to matrix.

Since
4.3

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 interation 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 coordiate 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 4696 of file qgraphicsitem.cpp.

Referenced by QGraphicsItemGroup::addToGroup(), QGraphicsItemGroup::removeFromGroup(), resetTransform(), rotate(), scale(), QDeclarativeFlipablePrivate::setBackTransform(), shear(), and translate().

4697 {
4698  if (!d_ptr->transformData)
4700 
4701  QTransform newTransform(combine ? matrix * d_ptr->transformData->transform : matrix);
4702  if (d_ptr->transformData->transform == newTransform)
4703  return;
4704 
4705  // Update and set the new transformation.
4707  d_ptr->setTransformHelper(newTransform);
4710  return;
4711  }
4712 
4713  // Notify the item that the transformation matrix is changing.
4714  const QVariant newTransformVariant(itemChange(ItemTransformChange,
4715  QVariant::fromValue<QTransform>(newTransform)));
4716  newTransform = qvariant_cast<QTransform>(newTransformVariant);
4717  if (d_ptr->transformData->transform == newTransform)
4718  return;
4719 
4720  // Update and set the new transformation.
4721  d_ptr->setTransformHelper(newTransform);
4722 
4723  // Send post-notification.
4724  itemChange(ItemTransformHasChanged, newTransformVariant);
4726 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QScopedPointer< QGraphicsItemPrivate > d_ptr
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&#39;s ...
void setTransformHelper(const QTransform &transform)
Sets the transform transform.
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
TransformData * transformData
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ setTransformations()

void QGraphicsItem::setTransformations ( const QList< QGraphicsTransform *> &  transformations)

Sets a list of graphics transformations (QGraphicsTransform) that currently apply to this item.

Since
4.6

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 4272 of file qgraphicsitem.cpp.

4273 {
4275  if (!d_ptr->transformData)
4278  for (int i = 0; i < transformations.size(); ++i)
4279  transformations.at(i)->d_func()->setItem(this);
4280  d_ptr->transformData->onlyTransform = false;
4283 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QGraphicsTransform * > transformations() const
Returns a list of graphics transforms that currently apply to this item.
void prepareGeometryChange()
Prepares the item for a geometry change.
QList< QGraphicsTransform * > graphicsTransforms
virtual void transformChanged()
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
TransformData * transformData

◆ setTransformOriginPoint() [1/2]

void QGraphicsItem::setTransformOriginPoint ( const QPointF origin)

Sets the origin point for the transformation in item coordinates.

Since
4.6
See also
transformOriginPoint(), {Transformations}

Definition at line 4348 of file qgraphicsitem.cpp.

Referenced by QDeclarativeItem::geometryChanged(), and QDeclarativeItem::setTransformOrigin().

4349 {
4351  QPointF newOrigin = origin;
4352 
4354  // Notify the item that the origin point is changing.
4355  const QVariant newOriginVariant(itemChange(ItemTransformOriginPointChange,
4356  QVariant::fromValue<QPointF>(origin)));
4357  newOrigin = newOriginVariant.toPointF();
4358  }
4359 
4360  if (!d_ptr->transformData)
4362 
4363  if (d_ptr->transformData->xOrigin == newOrigin.x()
4364  && d_ptr->transformData->yOrigin == newOrigin.y()) {
4365  return;
4366  }
4367 
4368  d_ptr->transformData->xOrigin = newOrigin.x();
4369  d_ptr->transformData->yOrigin = newOrigin.y();
4370  d_ptr->transformData->onlyTransform = false;
4372 
4373  // Send post-notification.
4375  itemChange(ItemTransformOriginPointHasChanged, QVariant::fromValue<QPointF>(newOrigin));
4376 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
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&#39;s ...
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void prepareGeometryChange()
Prepares the item for a geometry change.
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
TransformData * transformData

◆ setTransformOriginPoint() [2/2]

void QGraphicsItem::setTransformOriginPoint ( qreal  x,
qreal  y 
)
inline

Sets the origin point for the transformation in item coordinates.

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.

This is equivalent to calling setTransformOriginPoint(QPointF(x, y)).

See also
setTransformOriginPoint(), {Transformations}

Definition at line 320 of file qgraphicsitem.h.

321  { setTransformOriginPoint(QPointF(ax,ay)); }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void setTransformOriginPoint(const QPointF &origin)
Sets the origin point for the transformation in item coordinates.

◆ 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.

See also
isVisible(), show(), hide()

Definition at line 2568 of file qgraphicsitem.cpp.

Referenced by QDeclarativeLoaderPrivate::clear(), QDeclarativeListViewPrivate::createSection(), QGraphicsProxyWidget::eventFilter(), and QDeclarativeListViewPrivate::releaseItem().

2569 {
2570  d_ptr->setVisibleHelper(visible, /* explicit = */ true);
2571 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
void setVisibleHelper(bool newVisible, bool explicitly, bool update=true)
Sets this item&#39;s visibility to newVisible.

◆ setX()

void QGraphicsItem::setX ( qreal  x)

Set's the x coordinate of the item's position.

Since
4.6

Equivalent to calling setPos(x, y()).

See also
x(), setPos()

Definition at line 3840 of file qgraphicsitem.cpp.

Referenced by QDeclarativeListView::createdItem(), QDeclarativeParentChangePrivate::doChange(), QDeclarativeBasePositioner::positionX(), QDeclarativeLayoutItem::setGeometry(), QDeclarativeFlickablePrivate::setRoundedViewportX(), QDeclarativePathViewPrivate::updateItem(), QDeclarativePinchArea::updatePinch(), QDeclarativeParticlesPainter::updateSize(), and QDeclarativeListViewPrivate::updateUnrequestedPositions().

3841 {
3842  if (d_ptr->inDestructor)
3843  return;
3844 
3845  if (qIsNaN(x))
3846  return;
3847 
3848  setPos(QPointF(x, d_ptr->pos.y()));
3849 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void setPos(const QPointF &pos)
Sets the position of the item to pos, which is in parent coordinates.
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
qreal x() const
This convenience function is equivalent to calling pos().
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ setY()

void QGraphicsItem::setY ( qreal  y)

Set's the y coordinate of the item's position.

Since
4.6

Equivalent to calling setPos(x(), y).

See also
x(), setPos()

Definition at line 3873 of file qgraphicsitem.cpp.

Referenced by QDeclarativeListView::createdItem(), QDeclarativeParentChangePrivate::doChange(), QDeclarativeBasePositioner::positionY(), QDeclarativeLayoutItem::setGeometry(), QDeclarativeFlickablePrivate::setRoundedViewportY(), QDeclarativePathViewPrivate::updateItem(), QDeclarativePinchArea::updatePinch(), QDeclarativeParticlesPainter::updateSize(), and QDeclarativeListViewPrivate::updateUnrequestedPositions().

3874 {
3875  if (d_ptr->inDestructor)
3876  return;
3877 
3878  if (qIsNaN(y))
3879  return;
3880 
3881  setPos(QPointF(d_ptr->pos.x(), y));
3882 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void setPos(const QPointF &pos)
Sets the position of the item to pos, which is in parent coordinates.
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
qreal y() const
This convenience function is equivalent to calling pos().

◆ 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 4914 of file qgraphicsitem.cpp.

Referenced by QDeclarativeGridViewPrivate::createItem(), QDeclarativeListViewPrivate::createItem(), QDeclarativeListViewPrivate::createSection(), QmlJSDebugger::LiveLayerItem::LiveLayerItem(), QDeclarativePathView::refill(), QGraphicsScene::setActiveWindow(), QDeclarativeGridViewPrivate::updateFooter(), QDeclarativeListViewPrivate::updateFooter(), QDeclarativeGridViewPrivate::updateHeader(), and QDeclarativeListViewPrivate::updateHeader().

4915 {
4916  const QVariant newZVariant(itemChange(ItemZValueChange, z));
4917  qreal newZ = newZVariant.toReal();
4918  if (newZ == d_ptr->z)
4919  return;
4920 
4921  if (d_ptr->scene && d_ptr->scene->d_func()->indexMethod != QGraphicsScene::NoIndex) {
4922  // Z Value has changed, we have to notify the index.
4923  d_ptr->scene->d_func()->index->itemChange(this, ItemZValueChange, &newZ);
4924  }
4925 
4926  d_ptr->z = newZ;
4927  if (d_ptr->parent)
4929  else if (d_ptr->scene)
4930  d_ptr->scene->d_func()->needSortTopLevelItems = 1;
4931 
4932  if (d_ptr->scene)
4933  d_ptr->scene->d_func()->markDirty(this, QRectF(), /*invalidateChildren=*/true);
4934 
4935  itemChange(ItemZValueHasChanged, newZVariant);
4936 
4939 
4940  if (d_ptr->isObject)
4941  emit static_cast<QGraphicsObject *>(this)->zChanged();
4942 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QGraphicsItem * parent
double qreal
Definition: qglobal.h:1193
QScopedPointer< QGraphicsItemPrivate > d_ptr
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&#39;s ...
QGraphicsScene * scene
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
#define emit
Definition: qobjectdefs.h:76
The QGraphicsObject class provides a base class for all graphics items that require signals...
void setFlag(GraphicsItemFlag flag, bool enabled=true)
If enabled is true, the item flag flag is enabled; otherwise, it is disabled.

◆ 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
{
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 QGraphicsSimpleTextItem, QGraphicsTextItem, QGraphicsPixmapItem, QGraphicsLineItem, QGraphicsPolygonItem, QGraphicsEllipseItem, QGraphicsRectItem, QGraphicsPathItem, and QGraphicsWidget.

Definition at line 5168 of file qgraphicsitem.cpp.

Referenced by clipPath(), collidesWithItem(), collidesWithPath(), contains(), QGraphicsView::fitInView(), QAbstractGraphicsShapeItem::opaqueArea(), QGraphicsSceneIndexPrivate::recursive_items_helper(), setClip(), and QGraphicsLineItem::setLine().

5169 {
5170  QPainterPath path;
5171  path.addRect(boundingRect());
5172  return path;
5173 }
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.

◆ shear()

void QGraphicsItem::shear ( qreal  sh,
qreal  sv 
)

Use.

\obsolete
shear(sh, sv), true);

instead.

Shears the current item transformation by (sh, sv).

See also
setTransform(), transform()

Definition at line 4834 of file qgraphicsitem.cpp.

4835 {
4836  setTransform(QTransform().shear(sh, sv), true);
4837 }
void setTransform(const QTransform &matrix, bool combine=false)
Sets the item&#39;s current transformation matrix to matrix.
void shear(qreal sh, qreal sv)
Use.
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ 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 223 of file qgraphicsitem.h.

Referenced by QmlJSDebugger::BoundingRectHighlighter::createBoundingBox(), QmlJSDebugger::LiveSelectionRectangle::show(), and QmlJSDebugger::LiveSelectionIndicator::show().

223 { setVisible(true); }
void setVisible(bool visible)
If visible is true, the item is made visible.

◆ stackBefore()

void QGraphicsItem::stackBefore ( const QGraphicsItem sibling)

Stacks this item before sibling, which must be a sibling item (i.

Since
4.6

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 5007 of file qgraphicsitem.cpp.

Referenced by QDeclarativeParentChangePrivate::doChange(), QDeclarativeRepeater::itemsInserted(), QDeclarativeRepeater::itemsMoved(), and QDeclarativeRepeater::regenerate().

5008 {
5009  if (sibling == this)
5010  return;
5011  if (!sibling || d_ptr->parent != sibling->parentItem()) {
5012  qWarning("QGraphicsItem::stackUnder: cannot stack under %p, which must be a sibling", sibling);
5013  return;
5014  }
5015  QList<QGraphicsItem *> *siblings = d_ptr->parent
5016  ? &d_ptr->parent->d_ptr->children
5017  : (d_ptr->scene ? &d_ptr->scene->d_func()->topLevelItems : 0);
5018  if (!siblings) {
5019  qWarning("QGraphicsItem::stackUnder: cannot stack under %p, which must be a sibling", sibling);
5020  return;
5021  }
5022 
5023  // First, make sure that the sibling indexes have no holes. This also
5024  // marks the children list for sorting.
5025  if (d_ptr->parent)
5027  else
5028  d_ptr->scene->d_func()->ensureSequentialTopLevelSiblingIndexes();
5029 
5030  // Only move items with the same Z value, and that need moving.
5031  int siblingIndex = sibling->d_ptr->siblingIndex;
5032  int myIndex = d_ptr->siblingIndex;
5033  if (myIndex >= siblingIndex) {
5034  siblings->move(myIndex, siblingIndex);
5035  // Fixup the insertion ordering.
5036  for (int i = 0; i < siblings->size(); ++i) {
5037  int &index = siblings->at(i)->d_ptr->siblingIndex;
5038  if (i != siblingIndex && index >= siblingIndex && index <= myIndex)
5039  ++index;
5040  }
5041  d_ptr->siblingIndex = siblingIndex;
5042  for (int i = 0; i < siblings->size(); ++i) {
5043  int &index = siblings->at(i)->d_ptr->siblingIndex;
5044  if (i != siblingIndex && index >= siblingIndex && index <= myIndex)
5045  siblings->at(i)->d_ptr->siblingOrderChange();
5046  }
5048  }
5049 }
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsScene * scene
void move(int from, int to)
Moves the item at index position from to index position to.
Definition: qlist.h:628
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_CORE_EXPORT void qWarning(const char *,...)
void ensureSequentialSiblingIndex()
Ensures that the list of children is sorted by insertion order, and that the siblingIndexes are packe...
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
quint16 index
QList< QGraphicsItem * > children
virtual void siblingOrderChange()
Subclasses can reimplement this function to be notified when its siblingIndex order is changed...
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ supportsExtension()

bool QGraphicsItem::supportsExtension ( Extension  extension) const
protectedvirtual

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

Warning
This function is not part of the public interface.

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

Definition at line 7890 of file qgraphicsitem.cpp.

7891 {
7893  return false;
7894 }
virtual QVariant extension(const QVariant &variant) const
Note: This is provided as a hook to avoid future problems related to adding virtual functions...
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ toGraphicsObject() [1/2]

QGraphicsObject * QGraphicsItem::toGraphicsObject ( )

◆ toGraphicsObject() [2/2]

const QGraphicsObject * QGraphicsItem::toGraphicsObject ( ) const

Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object, 0 otherwise.

Since
4.6

Definition at line 1767 of file qgraphicsitem.cpp.

1768 {
1769  return d_ptr->isObject ? static_cast<const QGraphicsObject *>(this) : 0;
1770 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsObject class provides a base class for all graphics items that require signals...

◆ toolTip()

QString QGraphicsItem::toolTip ( ) const

Returns the item's tool tip, or an empty QString if no tool tip has been set.

See also
setToolTip(), QToolTip

Definition at line 2221 of file qgraphicsitem.cpp.

Referenced by QGraphicsProxyWidget::event(), and QGraphicsScene::helpEvent().

2222 {
2224 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QVariant extra(Extra type) const

◆ 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 0. 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 1643 of file qgraphicsitem.cpp.

Referenced by QGraphicsScene::drawItems(), QGraphicsSceneBspTreeIndexPrivate::estimateItems(), QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(), and QGraphicsSceneFindItemBspTreeVisitor::visit().

1644 {
1645  QGraphicsItem *parent = const_cast<QGraphicsItem *>(this);
1646  while (QGraphicsItem *grandPa = parent->parentItem())
1647  parent = grandPa;
1648  return parent;
1649 }
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.

◆ topLevelWidget()

QGraphicsWidget * QGraphicsItem::topLevelWidget ( ) const

Returns a pointer to the item's top level widget (i.

Since
4.4

e., the item's ancestor whose parent is 0, or whose parent is not a widget), or 0 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 1698 of file qgraphicsitem.cpp.

Referenced by topLevelWidget().

1699 {
1700  if (const QGraphicsWidget *p = parentWidget())
1701  return p->topLevelWidget();
1702  return isWidget() ? static_cast<QGraphicsWidget *>(const_cast<QGraphicsItem *>(this)) : 0;
1703 }
QGraphicsWidget * parentWidget() const
Returns a pointer to the item&#39;s parent widget.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
bool isWidget() const
Returns true if this item is a widget (i.
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ transform()

QTransform QGraphicsItem::transform ( ) const

Returns this item's transformation matrix.

Since
4.3

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 4070 of file qgraphicsitem.cpp.

Referenced by matrix(), and QGraphicsItemPrivate::setTransformHelper().

4071 {
4072  if (!d_ptr->transformData)
4073  return QTransform();
4074  return d_ptr->transformData->transform;
4075 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
TransformData * transformData
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ transformations()

QList< QGraphicsTransform * > QGraphicsItem::transformations ( ) const

Returns a list of graphics transforms that currently apply to this item.

Since
4.6

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 4242 of file qgraphicsitem.cpp.

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

4243 {
4244  if (!d_ptr->transformData)
4245  return QList<QGraphicsTransform *>();
4247 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QList< QGraphicsTransform * > graphicsTransforms
TransformData * transformData
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ transformOriginPoint()

QPointF QGraphicsItem::transformOriginPoint ( ) const

Returns the origin point for the transformation in item coordinates.

Since
4.6

The default is QPointF(0,0).

See also
setTransformOriginPoint(), {Transformations}

Definition at line 4331 of file qgraphicsitem.cpp.

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

4332 {
4333  if (!d_ptr->transformData)
4334  return QPointF(0,0);
4336 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
TransformData * transformData

◆ translate()

void QGraphicsItem::translate ( qreal  dx,
qreal  dy 
)

Use setPos() or setTransformOriginPoint() instead.

For identical behavior, use

Translates the current item transformation by (dx, dy).

If all you want is to move an item, you should call moveBy() or setPos() instead; this function changes the item's translation, which is conceptually separate from its position.

See also
setTransform(), transform()

Definition at line 4860 of file qgraphicsitem.cpp.

4861 {
4862  setTransform(QTransform::fromTranslate(dx, dy), true);
4863 }
void setTransform(const QTransform &matrix, bool combine=false)
Sets the item&#39;s current transformation matrix to matrix.
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis...
Definition: qtransform.cpp:462

◆ 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
{
...
enum { Type = UserType + 1 };
int type() const
{
// Enable the use of qgraphicsitem_cast with this item.
return Type;
}
...
};
See also
UserType

Reimplemented in QGraphicsItemGroup, QGraphicsSimpleTextItem, QGraphicsTextItem, QGraphicsPixmapItem, QGraphicsLineItem, QGraphicsPolygonItem, QGraphicsEllipseItem, QGraphicsRectItem, QGraphicsPathItem, QGraphicsWidget, QmlJSDebugger::BoundingBoxPolygonItem, QGraphicsSvgItem, QGraphicsProxyWidget, QmlJSDebugger::SelectionRectShape, QmlJSDebugger::LiveLayerItem, and QmlJSDebugger::SubcomponentMaskLayerItem.

Definition at line 7013 of file qgraphicsitem.cpp.

Referenced by QDeclarativeGestureAreaParser::compile(), QMotifStyle::event(), QMacStyle::event(), QmlJSDebugger::isEditorItem(), ShaderEffectItem::lookThroughShaderCode(), qgraphicsitem_cast(), qt_graphicsItem_highlightSelected(), and ~QGraphicsItem().

7014 {
7015  return (int)UserType;
7016 }
The lowest permitted type value for custom items (subclasses of QGraphicsItem or any of the standard ...

◆ ungrabKeyboard()

void QGraphicsItem::ungrabKeyboard ( )

Releases the keyboard grab.

Since
4.4
See also
grabKeyboard(), ungrabMouse()

Definition at line 3791 of file qgraphicsitem.cpp.

3792 {
3793  if (!d_ptr->scene) {
3794  qWarning("QGraphicsItem::ungrabKeyboard: cannot ungrab keyboard without scene");
3795  return;
3796  }
3797  d_ptr->scene->d_func()->ungrabKeyboard(this);
3798 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsScene * scene
Q_CORE_EXPORT void qWarning(const char *,...)

◆ ungrabMouse()

void QGraphicsItem::ungrabMouse ( )

Releases the mouse grab.

Since
4.4
See also
grabMouse(), ungrabKeyboard()

Definition at line 3723 of file qgraphicsitem.cpp.

Referenced by QGraphicsScenePrivate::clearMouseGrabber(), QGraphicsScenePrivate::grabMouse(), QDeclarativePathView::mouseReleaseEvent(), QDeclarativeMouseArea::mouseReleaseEvent(), QDeclarativeFlickable::mouseReleaseEvent(), QDeclarativePinchArea::mouseReleaseEvent(), QDeclarativeMouseArea::sendMouseEvent(), QDeclarativePinchArea::sendMouseEvent(), and setAcceptedMouseButtons().

3724 {
3725  if (!d_ptr->scene) {
3726  qWarning("QGraphicsItem::ungrabMouse: cannot ungrab mouse without scene");
3727  return;
3728  }
3729  d_ptr->scene->d_func()->ungrabMouse(this);
3730 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsScene * scene
Q_CORE_EXPORT void qWarning(const char *,...)

◆ unsetCursor()

void QGraphicsItem::unsetCursor ( )

Clears the cursor from this item.

See also
hasCursor(), setCursor()

Definition at line 2319 of file qgraphicsitem.cpp.

2320 {
2322  d_ptr->hasCursor = 0;
2323  if (d_ptr->scene) {
2324  foreach (QGraphicsView *view, d_ptr->scene->views()) {
2325  if (view->underMouse() && view->itemAt(view->mapFromGlobal(QCursor::pos())) == this) {
2326  QMetaObject::invokeMethod(view, "_q_unsetViewportCursor");
2327  break;
2328  }
2329  }
2330  }
2331 }
void unsetExtra(Extra type)
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsScene * scene
bool underMouse() const
Returns true if the widget is under the mouse cursor; otherwise returns false.
Definition: qwidget.h:996
QList< QGraphicsView * > views() const
Returns a list of all the views that display this scene.
QGraphicsItem * itemAt(const QPoint &pos) const
Returns the item at position pos, which is in viewport coordinates.
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310

◆ 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 6048 of file qgraphicsitem.cpp.

Referenced by QGraphicsItemGroup::addToGroup(), ShaderEffectSource::attachSourceItem(), QGraphicsWidget::changeEvent(), QDeclarativeBorderImage::doUpdate(), QDeclarativeRectangle::doUpdate(), QGraphicsWidget::event(), QGraphicsWidget::focusInEvent(), focusInEvent(), QGraphicsTextItem::focusInEvent(), QGraphicsWidget::focusOutEvent(), focusOutEvent(), QGraphicsTextItem::focusOutEvent(), hoverEnterEvent(), hoverLeaveEvent(), QDeclarativePathView::itemsRemoved(), QDeclarativeGridView::itemsRemoved(), QDeclarativeListView::itemsRemoved(), QDeclarativeBorderImage::load(), QDeclarativeImageBase::load(), ShaderEffectItem::markDirty(), QDeclarativeBorderImage::requestFinished(), QDeclarativeImageBase::requestFinished(), scroll(), QGraphicsWidget::setAutoFillBackground(), QAbstractGraphicsShapeItem::setBrush(), setCacheMode(), QDeclarativeTextInput::setColor(), QDeclarativeTextEdit::setColor(), QDeclarativeRectangle::setColor(), QDeclarativePaintedItem::setContentsScale(), QDeclarativePaintedItem::setContentsSize(), QGraphicsTextItem::setDefaultTextColor(), QGraphicsSvgItem::setElementId(), QDeclarativePaintedItem::setFillColor(), QDeclarativeImage::setFillMode(), QGraphicsPolygonItem::setFillRule(), QDeclarativeTextEdit::setFont(), QDeclarativeRectangle::setGradient(), QDeclarativeBorderImage::setGridScaledImage(), QDeclarativeBorderImage::setHorizontalTileMode(), QGraphicsLineItem::setLine(), QGraphicsSvgItem::setMaximumCacheSize(), QDeclarativeImageBase::setMirror(), QGraphicsPixmapItem::setOffset(), QGraphicsPathItem::setPath(), QAbstractGraphicsShapeItem::setPen(), QGraphicsLineItem::setPen(), QGraphicsPixmapItem::setPixmap(), QGraphicsPolygonItem::setPolygon(), QDeclarativeRectangle::setRadius(), QGraphicsRectItem::setRect(), QGraphicsEllipseItem::setRect(), setSelected(), QDeclarativeTextInput::setSelectedTextColor(), QDeclarativeTextEdit::setSelectedTextColor(), QDeclarativeTextInput::setSelectionColor(), QDeclarativeTextEdit::setSelectionColor(), QGraphicsSvgItem::setSharedRenderer(), QDeclarativeItem::setSmooth(), QGraphicsEllipseItem::setSpanAngle(), QGraphicsEllipseItem::setStartAngle(), QGraphicsSimpleTextItem::setText(), QGraphicsPixmapItem::setTransformationMode(), QDeclarativeBorderImage::setVerticalTileMode(), QDeclarativeTextEdit::updateImgCache(), QDeclarativeTextInput::updateRect(), updateRedirectedToGraphicsProxyWidget(), QDeclarativeTextEdit::updateSize(), and QDeclarativeTextInput::updateSize().

6049 {
6050  if (rect.isEmpty() && !rect.isNull())
6051  return;
6052 
6053  // Make sure we notify effects about invalidated source.
6054 #ifndef QT_NO_GRAPHICSEFFECT
6056 #endif //QT_NO_GRAPHICSEFFECT
6057 
6058 #ifndef QT_NO_GRAPHICSEFFECT
6060 #endif
6061  if (CacheMode(d_ptr->cacheMode) != NoCache) {
6062  // Invalidate cache.
6064  if (!cache->allExposed) {
6065  if (rect.isNull()) {
6066  cache->allExposed = true;
6067  cache->exposed.clear();
6068  } else {
6069  cache->exposed.append(rect);
6070  }
6071  }
6072  // Only invalidate cache; item is already dirty.
6073  if (d_ptr->fullUpdatePending)
6074  return;
6075  }
6076 #ifndef QT_NO_GRAPHICSEFFECT
6077  }
6078 #endif
6079 
6080  if (d_ptr->scene)
6081  d_ptr->scene->d_func()->markDirty(this, rect);
6082 }
void invalidateParentGraphicsEffectsRecursively()
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsScene * scene
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
CacheMode
This enum describes QGraphicsItem&#39;s cache modes.
QVector< QRectF > exposed
QGraphicsItemCache * extraItemCache() const
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:658
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655

◆ update() [2/2]

void QGraphicsItem::update ( qreal  x,
qreal  y,
qreal  width,
qreal  height 
)
inline

This convenience function is equivalent to calling update(QRectF(x, y, width, height)).

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

Definition at line 505 of file qgraphicsitem.h.

506 { update(QRectF(ax, ay, width, height)); }
void update(const QRectF &rect=QRectF())
Schedules a redraw of the area covered by rect in this item.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ updateMicroFocus()

void QGraphicsItem::updateMicroFocus ( )
protected

Updates the item's micro focus.

Since
4.7
See also
QInputContext

Definition at line 7831 of file qgraphicsitem.cpp.

Referenced by QGraphicsObject::updateMicroFocus().

7832 {
7833 #if !defined(QT_NO_IM) && (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN))
7834  if (QWidget *fw = QApplication::focusWidget()) {
7835  if (scene()) {
7836  for (int i = 0 ; i < scene()->views().count() ; ++i) {
7837  if (scene()->views().at(i) == fw) {
7838  if (QInputContext *inputContext = fw->inputContext()) {
7839  inputContext->update();
7840 #ifndef QT_NO_ACCESSIBILITY
7841  // ##### is this correct
7842  if (toGraphicsObject())
7844 #endif
7845  break;
7846  }
7847  }
7848  }
7849  }
7850  }
7851 #endif
7852 }
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QGraphicsObject * toGraphicsObject()
Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object...
QList< QGraphicsView * > views() const
Returns a list of all the views that display this scene.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
The QInputContext class abstracts the input method dependent data and composing state.
Definition: qinputcontext.h:83
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or 0 if no widget in this applicati...

◆ 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()

Reimplemented in QDeclarativeFlickable, and QGraphicsProxyWidget.

Definition at line 7740 of file qgraphicsitem.cpp.

Referenced by sceneEvent(), and QDeclarativeFlickable::wheelEvent().

7741 {
7742  event->ignore();
7743 }

◆ window()

QGraphicsWidget * QGraphicsItem::window ( ) const

Returns the item's window, or 0 if this item does not have a window.

Since
4.4

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 1717 of file qgraphicsitem.cpp.

Referenced by QShortcutMap::correctGraphicsWidgetContext(), QGraphicsWidget::initStyleOption(), QGraphicsScenePrivate::mousePressEventHandler(), and QGraphicsWidget::paintWindowFrame().

1718 {
1719  QGraphicsItem *p = panel();
1720  if (p && p->isWindow())
1721  return static_cast<QGraphicsWidget *>(p);
1722  return 0;
1723 }
bool isWindow() const
Returns true if the item is a QGraphicsWidget window, otherwise returns false.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QGraphicsItem * panel() const
Returns the item&#39;s panel, or 0 if this item does not have a panel.

◆ x()

QGraphicsItem::x ( ) const
inline

◆ y()

QGraphicsItem::y ( ) const
inline

◆ 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 4895 of file qgraphicsitem.cpp.

Referenced by operator<<(), and QGraphicsScene::setActiveWindow().

4896 {
4897  return d_ptr->z;
4898 }
QScopedPointer< QGraphicsItemPrivate > d_ptr

Friends and Related Functions

◆ ::tst_QGraphicsItem

friend class ::tst_QGraphicsItem
friend

Definition at line 493 of file qgraphicsitem.h.

◆ QGestureManager

friend class QGestureManager
friend

Definition at line 491 of file qgraphicsitem.h.

◆ qgraphicsitem_cast()

T qgraphicsitem_cast ( QGraphicsItem item)
related
Since
4.2

Returns the given item cast to type T if item is of type T; otherwise, 0 is returned.

Note
To make this function work correctly with custom items, reimplement the QGraphicsItem::type() function for each custom QGraphicsItem subclass.
See also
QGraphicsItem::type(), QGraphicsItem::UserType

Definition at line 1139 of file qgraphicsitem.h.

1140 {
1141  return int(static_cast<T>(0)->Type) == int(QGraphicsItem::Type)
1142  || (item && int(static_cast<T>(0)->Type) == item->type()) ? static_cast<T>(item) : 0;
1143 }
The type value returned by the virtual type() function in standard graphics item classes in Qt...
virtual int type() const
Returns the type of an item as an int.

◆ QGraphicsItemEffectSourcePrivate

Definition at line 488 of file qgraphicsitem.h.

Referenced by setGraphicsEffect().

◆ QGraphicsItemGroup

friend class QGraphicsItemGroup
friend

Definition at line 473 of file qgraphicsitem.h.

◆ QGraphicsObject

friend class QGraphicsObject
friend

Definition at line 480 of file qgraphicsitem.h.

◆ QGraphicsProxyWidgetPrivate

Definition at line 483 of file qgraphicsitem.h.

◆ QGraphicsScene

friend class QGraphicsScene
friend

Definition at line 474 of file qgraphicsitem.h.

◆ QGraphicsSceneBspTree

Definition at line 477 of file qgraphicsitem.h.

◆ QGraphicsSceneBspTreeIndex

Definition at line 486 of file qgraphicsitem.h.

◆ QGraphicsSceneBspTreeIndexPrivate

Definition at line 487 of file qgraphicsitem.h.

◆ QGraphicsSceneFindItemBspTreeVisitor

Definition at line 476 of file qgraphicsitem.h.

◆ QGraphicsSceneIndex

friend class QGraphicsSceneIndex
friend

Definition at line 484 of file qgraphicsitem.h.

◆ QGraphicsSceneIndexPrivate

Definition at line 485 of file qgraphicsitem.h.

◆ QGraphicsScenePrivate

Definition at line 475 of file qgraphicsitem.h.

◆ QGraphicsTransformPrivate

Definition at line 489 of file qgraphicsitem.h.

◆ QGraphicsView

friend class QGraphicsView
friend

Definition at line 478 of file qgraphicsitem.h.

◆ QGraphicsViewPrivate

friend class QGraphicsViewPrivate
friend

Definition at line 479 of file qgraphicsitem.h.

◆ QGraphicsWidget

friend class QGraphicsWidget
friend

Definition at line 481 of file qgraphicsitem.h.

◆ QGraphicsWidgetPrivate

Definition at line 482 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.

Warning
This function is not part of the public interface.

Definition at line 729 of file qgraphicsitem_p.h.

Referenced by isObscuredBy().

730 {
731  // Siblings? Just check their z-values.
732  const QGraphicsItemPrivate *d1 = item1->d_ptr.data();
733  const QGraphicsItemPrivate *d2 = item2->d_ptr.data();
734  if (d1->parent == d2->parent)
735  return qt_closestLeaf(item1, item2);
736 
737  // Find common ancestor, and each item's ancestor closest to the common
738  // ancestor.
739  int item1Depth = d1->depth();
740  int item2Depth = d2->depth();
741  const QGraphicsItem *p = item1;
742  const QGraphicsItem *t1 = item1;
743  while (item1Depth > item2Depth && (p = p->d_ptr->parent)) {
744  if (p == item2) {
745  // item2 is one of item1's ancestors; item1 is on top
747  }
748  t1 = p;
749  --item1Depth;
750  }
751  p = item2;
752  const QGraphicsItem *t2 = item2;
753  while (item2Depth > item1Depth && (p = p->d_ptr->parent)) {
754  if (p == item1) {
755  // item1 is one of item2's ancestors; item1 is not on top
757  }
758  t2 = p;
759  --item2Depth;
760  }
761 
762  // item1Ancestor is now at the same level as item2Ancestor, but not the same.
763  const QGraphicsItem *p1 = t1;
764  const QGraphicsItem *p2 = t2;
765  while (t1 && t1 != t2) {
766  p1 = t1;
767  p2 = t2;
768  t1 = t1->d_ptr->parent;
769  t2 = t2->d_ptr->parent;
770  }
771 
772  // in case we have a common ancestor, we compare the immediate children in the ancestor's path.
773  // otherwise we compare the respective items' topLevelItems directly.
774  return qt_closestLeaf(p1, p2);
775 }
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr
T * data() const
Returns the value of the pointer referenced by this object.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
friend bool qt_closestLeaf(const QGraphicsItem *, const QGraphicsItem *)

◆ qt_closestLeaf

bool qt_closestLeaf ( const QGraphicsItem item1,
const QGraphicsItem item2 
)
friend
Warning
This function is not part of the public interface.

Definition at line 791 of file qgraphicsitem_p.h.

792 {
793  // Return true if sibling item1 is on top of item2.
794  const QGraphicsItemPrivate *d1 = item1->d_ptr.data();
795  const QGraphicsItemPrivate *d2 = item2->d_ptr.data();
798  if (f1 != f2)
799  return f2;
800  if (d1->z != d2->z)
801  return d1->z > d2->z;
802  return d1->siblingIndex > d2->siblingIndex;
803 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
T * data() const
Returns the value of the pointer referenced by this object.

Properties

◆ d_ptr

QScopedPointer<QGraphicsItemPrivate> QGraphicsItem::d_ptr
protected

Definition at line 464 of file qgraphicsitem.h.

Referenced by QGraphicsScenePrivate::_q_polishItems(), QGraphicsScenePrivate::_q_updateScenePosDescendants(), QGraphicsSceneBspTreeIndexPrivate::_q_updateSortCache(), acceptDrops(), acceptedMouseButtons(), acceptHoverEvents(), acceptsHoverEvents(), acceptTouchEvents(), QGraphicsItemPrivate::addChild(), QGraphicsSceneBspTreeIndexPrivate::addItem(), QGraphicsScene::addItem(), addToIndex(), boundingRegionGranularity(), cacheMode(), QGraphicsItemPrivate::calcEffectiveOpacity(), childItems(), childrenBoundingRect(), QGraphicsItemPrivate::childrenBoundingRectHelper(), clearFocus(), QGraphicsItemPrivate::clearFocusHelper(), QGraphicsItemPrivate::clearSubFocus(), QGraphicsSceneBspTreeIndexPrivate::climbTree(), clipPath(), QGraphicsSceneBspTreeIndexPrivate::closestItemFirst_withCache(), QGraphicsSceneBspTreeIndexPrivate::closestItemLast_withCache(), collidesWithItem(), collidesWithPath(), collidingItems(), commonAncestorItem(), QGraphicsScene::contextMenuEvent(), cursor(), deviceTransform(), QGraphicsScenePrivate::draw(), QDeclarativeImplicitSizePaintedItem::drawContents(), QGraphicsScenePrivate::drawItemHelper(), QGraphicsScene::drawItems(), QGraphicsScenePrivate::drawSubtreeRecursive(), QGraphicsItemPrivate::effectiveBoundingRect(), effectiveOpacity(), QGraphicsItemPrivate::ensureSceneTransformRecursive(), QGraphicsItemPrivate::ensureSequentialSiblingIndex(), ensureVisible(), QGraphicsScenePrivate::enterModal(), QGraphicsSceneBspTreeIndexPrivate::estimateItems(), QGraphicsScenePrivate::filterDescendantEvent(), filtersChildEvents(), QGraphicsView::fitInView(), flags(), focusItem(), focusProxy(), focusScopeItem(), QGraphicsObject::grabGesture(), grabKeyboard(), grabMouse(), graphicsEffect(), group(), handlesChildEvents(), hasCursor(), hasFocus(), inputMethodQuery(), QGraphicsItemPrivate::insertionOrder(), installSceneEventFilter(), QGraphicsItemPrivate::invalidateChildGraphicsEffectsRecursively(), QGraphicsItemPrivate::invalidateDepthRecursively(), QGraphicsItemPrivate::invalidateParentGraphicsEffectsRecursively(), isActive(), isAncestorOf(), isBlockedByModalPanel(), isEnabled(), isPanel(), isSelected(), isVisible(), isVisibleTo(), isWidget(), isWindow(), QGraphicsScenePrivate::itemAcceptsHoverEvents_helper(), QGraphicsSceneBspTreeIndex::itemChange(), QGraphicsSceneBspTree::items(), itemTransform(), mapFromParent(), mapFromScene(), mapRectFromParent(), mapRectFromScene(), mapRectToParent(), mapRectToScene(), mapToParent(), mapToScene(), QGraphicsViewPrivate::mapToViewRect(), QGraphicsScenePrivate::markDirty(), QGraphicsItemPrivate::markParentDirty(), mouseMoveEvent(), mousePressEvent(), QGraphicsTextItem::mousePressEvent(), QGraphicsScenePrivate::mousePressEventHandler(), mouseReleaseEvent(), QGraphicsItemPrivate::movableAncestorIsSelected(), opacity(), QGraphicsView::paintEvent(), panel(), panelModality(), parentItem(), parentObject(), pos(), QGraphicsSceneBspTreeIndex::prepareBoundingRectChange(), prepareGeometryChange(), QGraphicsScenePrivate::processDirtyItemsRecursive(), QGraphicsItem(), QGraphicsObject::QGraphicsObject(), qt_closestItemFirst(), qt_closestLeaf(), QGraphicsSceneIndexPrivate::recursive_items_helper(), QGraphicsScenePrivate::registerTopLevelItem(), QGraphicsItemPrivate::removeChild(), QGraphicsItemGroup::removeFromGroup(), removeFromIndex(), QGraphicsSceneBspTreeIndexPrivate::removeItem(), QGraphicsScenePrivate::removeItemHelper(), removeSceneEventFilter(), QGraphicsScenePrivate::resetDirtyItem(), rotation(), scale(), scene(), sceneBoundingRect(), QGraphicsItemPrivate::sceneEffectiveBoundingRect(), sceneEvent(), sceneMatrix(), sceneTransform(), QGraphicsScenePrivate::sendDragDropEvent(), QGraphicsScenePrivate::sendHoverEvent(), QGraphicsScenePrivate::sendMouseEvent(), QGraphicsScenePrivate::sendTouchBeginEvent(), setAcceptDrops(), setAcceptedMouseButtons(), setAcceptHoverEvents(), setAcceptTouchEvents(), setActive(), setBoundingRegionGranularity(), setCacheMode(), setCursor(), setEnabled(), QGraphicsItemPrivate::setEnabledHelper(), setFiltersChildEvents(), setFlag(), setFlags(), setFocus(), QGraphicsItemPrivate::setFocusHelper(), setFocusProxy(), setGraphicsEffect(), setHandlesChildEvents(), QGraphicsTransformPrivate::setItem(), setMatrix(), QGraphicsSvgItem::setMaximumCacheSize(), setOpacity(), setPanelModality(), setParentItem(), QGraphicsItemPrivate::setParentItemHelper(), setPos(), setRotation(), setScale(), QGraphicsScenePrivate::setScenePosItemEnabled(), setSelected(), QGraphicsItemPrivate::setSubFocus(), setToolTip(), setTransform(), setTransformations(), setTransformOriginPoint(), QGraphicsViewPrivate::setUpdateClip(), setVisible(), QGraphicsItemPrivate::setVisibleHelper(), QGraphicsProxyWidgetPrivate::setWidget_helper(), setX(), setY(), setZValue(), stackBefore(), QGraphicsScenePrivate::storeMouseButtonsForMouseGrabber(), toGraphicsObject(), toolTip(), transform(), transformations(), transformOriginPoint(), QGraphicsScenePrivate::ungrabGesture(), QGraphicsObject::ungrabGesture(), ungrabKeyboard(), ungrabMouse(), QGraphicsScenePrivate::unregisterTopLevelItem(), unsetCursor(), update(), QGraphicsItemPrivate::updateChildWithGraphicsEffectFlagRecursively(), QGraphicsWidgetPrivate::updateFont(), QGraphicsScenePrivate::updateFont(), QGraphicsTransformPrivate::updateItem(), QGraphicsItemPrivate::updatePaintedViewBoundingRects(), QGraphicsWidgetPrivate::updatePalette(), QGraphicsScenePrivate::updatePalette(), QGraphicsScenePrivate::updateTouchPointsForItem(), QGraphicsSceneFindItemBspTreeVisitor::visit(), QGraphicsScene::wheelEvent(), zValue(), QDeclarativeItem::~QDeclarativeItem(), and ~QGraphicsItem().


The documentation for this class was generated from the following files: