Home · All Namespaces · All Classes · Main Classes · Grouped Classes · Modules · Functions

QGraphicsItem Class Reference
[QtGui module]

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

 #include <QGraphicsItem>

Inherited by QAbstractGraphicsShapeItem, QGraphicsItemGroup, QGraphicsLineItem, QGraphicsPixmapItem, QGraphicsSvgItem, QGraphicsTextItem, and QGraphicsWidget.

This class was introduced in Qt 4.2.

Public Types

Public Functions

Static Public Members

Protected Functions

Related Non-Members


Detailed Description

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

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

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:
     QRectF boundingRect() const
     {
         qreal penWidth = 1;
         return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,
                       20 + penWidth / 2, 20 + penWidth / 2);
     }

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

QGraphicsItem supports affine transformations in addition to its base position, pos(). To change the item's transformation, you can either pass a transformation matrix to setTransform(), or call one of the convenience functions rotate(), scale(), translate(), or shear(). 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().

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.

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 functionaly is separate from 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().

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, and The Graphics View Framework.


Member Type Documentation

enum QGraphicsItem::CacheMode

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

ConstantValueDescription
QGraphicsItem::NoCache0The default; all item caching is disabled. QGraphicsItem::paint() is called every time the item needs redrawing.
QGraphicsItem::ItemCoordinateCache1Caching 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.
QGraphicsItem::DeviceCoordinateCache2Caching 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.

This enum was introduced in Qt 4.4.

See also QGraphicsItem::setCacheMode().

enum QGraphicsItem::GraphicsItemChange

ItemVisibleHasChanged, ItemEnabledHasChanged, ItemSelectedHasChanged, ItemParentHasChanged, ItemSceneHasChanged

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

ConstantValueDescription
QGraphicsItem::ItemEnabledChange3The 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().
QGraphicsItem::ItemEnabledHasChanged13The 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.
QGraphicsItem::ItemMatrixChange1The item's affine transformation matrix is changing. This value is obsolete; you can use ItemTransformChange instead.
QGraphicsItem::ItemPositionChange0The item's position changes. This notification is only sent when the item's local position changes, relative to its parent, has changed (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.
QGraphicsItem::ItemPositionHasChanged9The item's position has changed. This notification is only sent 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).
QGraphicsItem::ItemTransformChange8The item's transformation matrix changes. This notification is only sent when the item's local transformation matrix changes (i.e., as a result of calling setTransform(), or one of the convenience transformation functions, such as rotate()). The value argument is the new matrix (i.e., a QTransform); to get the old matrix, call transform(). Do not call setTransform() or any of the transformation convenience functions in itemChange() as this notification is delivered; instead, you can return the new matrix from itemChange().
QGraphicsItem::ItemTransformHasChanged10The item's transformation matrix has changed. This notification is only sent after the item's local trasformation 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).
QGraphicsItem::ItemSelectedChange4The 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().
QGraphicsItem::ItemSelectedHasChanged14The 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.
QGraphicsItem::ItemVisibleChange2The 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().
QGraphicsItem::ItemVisibleHasChanged12The 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.
QGraphicsItem::ItemParentChange5The item's parent changes. The value argument is the new parent item (i.e., a QGraphicsItem pointer). Do not call setParentItem() in itemChange() as this notification is delivered; instead, you can return the new parent from itemChange().
QGraphicsItem::ItemParentHasChanged15The 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.
QGraphicsItem::ItemChildAddedChange6A 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.
QGraphicsItem::ItemChildRemovedChange7A 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.
QGraphicsItem::ItemSceneChange11The 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 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.
QGraphicsItem::ItemSceneHasChanged16The item's scene has changed. 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.
QGraphicsItem::ItemCursorChange17The 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().
QGraphicsItem::ItemCursorHasChanged18The 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.
QGraphicsItem::ItemToolTipChange19The 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().
QGraphicsItem::ItemToolTipHasChanged20The 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.
QGraphicsItem::ItemFlagsChange21The 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().
QGraphicsItem::ItemFlagsHaveChanged22The 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.
QGraphicsItem::ItemZValueChange23The 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().
QGraphicsItem::ItemZValueHasChanged24The 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.

enum QGraphicsItem::GraphicsItemFlag
flags QGraphicsItem::GraphicsItemFlags

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.

ConstantValueDescription
QGraphicsItem::ItemIsMovable0x1The 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.
QGraphicsItem::ItemIsSelectable0x2The 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.
QGraphicsItem::ItemIsFocusable0x4The item supports keyboard input focus (i.e., it is an input item). Enabling this flag will allow the item to accept focus, which again allows the delivery of key events to QGraphicsItem::keyPressEvent() and QGraphicsItem::keyReleaseEvent().
QGraphicsItem::ItemClipsToShape0x8The item clips (i.e., restricts) its own painting to inside its shape. Its paintEvent() function cannot draw outside its shape. For complex shapes, this function can be expensive. It is disabled by default. This behavior is enforced by QGraphicsView::drawItems() or QGraphicsScene::drawItems(). This flag was introduced in Qt 4.3.
QGraphicsItem::ItemClipsChildrenToShape0x10The 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.
QGraphicsItem::ItemIgnoresTransformations0x20The 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.

The GraphicsItemFlags type is a typedef for QFlags<GraphicsItemFlag>. It stores an OR combination of GraphicsItemFlag values.


Member Function Documentation

QGraphicsItem::QGraphicsItem ( QGraphicsItem * parent = 0 )

Constructs a QGraphicsItem with the given 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() and setParentItem().

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.

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

bool QGraphicsItem::acceptHoverEvents () const

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

This function was introduced in Qt 4.4.

See also setAcceptHoverEvents() and setAcceptedMouseButtons().

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() and mousePressEvent().

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 and QTimeLine.

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 (scale(), rotate(), etc.).

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:

 QRectF CircleItem::boundingRect() const
 {
     qreal penWidth = 1;
     return QRectF(-radius - penWidth / 2, -radius - penWidth / 2,
                   diameter + penWidth, diameter + penWidth);
 }

See also boundingRegion(), shape(), contains(), The Graphics View Coordinate System, and prepareGeometryChange().

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

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

The bounding region describes a coarse outline of the item's visual contents. Although it's expensive to calculate, it's also more precise than boundingRect(), and it can help to avoid unnecessary repainting when an item is updated. This is particularily 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.

This function was introduced in Qt 4.4.

See also boundingRegionGranularity().

qreal QGraphicsItem::boundingRegionGranularity () const

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

This function was introduced in Qt 4.4.

See also setBoundingRegionGranularity().

CacheMode QGraphicsItem::cacheMode () const

Returns the cache mode for this item. The default mode is NoCache (i.e., cache is disabled and all painting is immediate).

This function was introduced in Qt 4.4.

See also setCacheMode().

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

Returns a list of this item's children. The items are returned in no particular order.

This function was introduced in Qt 4.4.

See also setParentItem().

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() and sceneBoundingRect().

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() and QGraphicsWidget::focusPolicy.

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 ways items collide is determined by mode. 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.

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() and shape().

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.

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

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 mode. The default value for mode is Qt::IntersectsItemShape; All items whose shape intersects or is contained by this item's shape are returned.

See also QGraphicsScene::collidingItems() and collidesWithItem().

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.

This function was introduced in Qt 4.4.

See also isAncestorOf().

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(), and collidesWithPath().

void QGraphicsItem::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event )   [virtual protected]

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

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 parent's cursor is used.

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

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

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

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

Example:

 QGraphicsRectItem rect;
 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.

This function was introduced in Qt 4.3.

See also transform(), setTransform(), scenePos(), and The Graphics View Coordinate System.

void QGraphicsItem::dragEnterEvent ( QGraphicsSceneDragDropEvent * event )   [virtual protected]

This event handler, for event event, can be reimplemented to receive drag enter events for this item. Drag enter events are generated as the cursor enters the item's area.

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

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

 CustomItem::CustomItem()
 {
     setAcceptDrops(true);
     ...
 }

 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(), and dragLeaveEvent().

void QGraphicsItem::dragLeaveEvent ( QGraphicsSceneDragDropEvent * event )   [virtual protected]

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(), and dragMoveEvent().

void QGraphicsItem::dragMoveEvent ( QGraphicsSceneDragDropEvent * event )   [virtual protected]

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(), and dragLeaveEvent().

void QGraphicsItem::dropEvent ( QGraphicsSceneDragDropEvent * event )   [virtual protected]

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(), and dragLeaveEvent().

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

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

This is an overloaded member function, provided for convenience.

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

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() and setFlag().

void QGraphicsItem::focusInEvent ( QFocusEvent * event )   [virtual protected]

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() and sceneEvent().

void QGraphicsItem::focusOutEvent ( QFocusEvent * event )   [virtual protected]

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() and sceneEvent().

void QGraphicsItem::grabKeyboard ()

Grabs the keyboard input.

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

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.

This function was introduced in Qt 4.4.

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

void QGraphicsItem::grabMouse ()

Grabs the mouse input.

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

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.

This function was introduced in Qt 4.4.

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

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 setGroup(), QGraphicsItemGroup, and QGraphicsScene::createItemGroup().

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

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

bool QGraphicsItem::hasFocus () const

Returns true if this item has keyboard input focus; otherwise, returns false.

See also QGraphicsScene::focusItem(), setFocus(), and QGraphicsScene::setFocusItem().

void QGraphicsItem::hide ()

Hides the item. (Items are visible by default.)

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

See also show() and setVisible().

void QGraphicsItem::hoverEnterEvent ( QGraphicsSceneHoverEvent * event )   [virtual protected]

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(), and setAcceptHoverEvents().

void QGraphicsItem::hoverLeaveEvent ( QGraphicsSceneHoverEvent * event )   [virtual protected]

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(), and setAcceptHoverEvents().

void QGraphicsItem::hoverMoveEvent ( QGraphicsSceneHoverEvent * event )   [virtual protected]

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(), and setAcceptHoverEvents().

void QGraphicsItem::inputMethodEvent ( QInputMethodEvent * event )   [virtual protected]

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() and sceneEvent().

QVariant QGraphicsItem::inputMethodQuery ( Qt::InputMethodQuery query ) const   [virtual protected]

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

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:

 QGraphicsScene scene;
 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(), and sceneEvent().

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

bool QGraphicsItem::isEnabled () const

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

See also setEnabled().

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

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

This is an overloaded member function, provided for convenience.

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

This function was introduced in Qt 4.3.

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

This is an overloaded member function, provided for convenience.

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

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

This function was introduced in Qt 4.3.

See also opaqueArea().

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() and isObscured().

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() and QGraphicsScene::setSelectionArea().

bool QGraphicsItem::isUnderMouse () const

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

This function was introduced in Qt 4,4.

See also QGraphicsScene::views() and QCursor::pos().

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

bool QGraphicsItem::isVisibleTo ( const QGraphicsItem * parent ) const

Returns true if the item is visible to parent; otherwise, false is returned. 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. If any ancestor is hidden, the item itself will be implicitly hidden, in which case this function will return false.

This function was introduced in Qt 4.4.

See also isVisible() and setVisible().

bool QGraphicsItem::isWidget () const

Returns true if this item is a widget (i.e., QGraphicsWidget); otherwise, returns false.

This function was introduced in Qt 4.4.

bool QGraphicsItem::isWindow () const

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

This function was introduced in Qt 4.4.

See also QGraphicsWidget::windowFlags().

QVariant QGraphicsItem::itemChange ( GraphicsItemChange change, const QVariant & value )   [virtual protected]

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.

void QGraphicsItem::keyPressEvent ( QKeyEvent * event )   [virtual protected]

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.

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

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(), and sceneEvent().

void QGraphicsItem::keyReleaseEvent ( QKeyEvent * event )   [virtual protected]

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.

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

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(), and sceneEvent().

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 mapFromParent(), mapFromScene(), transform(), mapToItem(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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 mapToItem(), mapFromParent(), transform(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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 mapToItem(), mapFromParent(), transform(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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 mapFromParent(), mapFromScene(), mapToItem(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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

This function was introduced in Qt 4.3.

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

This is an overloaded member function, provided for convenience.

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

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(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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

This function was introduced in Qt 4.3.

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

This is an overloaded member function, provided for convenience.

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

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(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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

This function was introduced in Qt 4.3.

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

This is an overloaded member function, provided for convenience.

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

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 mapToParent(), mapToScene(), transform(), mapFromItem(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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 mapToParent(), mapToScene(), mapFromItem(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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 mapToParent(), mapToScene(), mapFromItem(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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 mapToParent(), mapToScene(), mapFromItem(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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

This function was introduced in Qt 4.3.

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

This is an overloaded member function, provided for convenience.

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

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(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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

This function was introduced in Qt 4.3.

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

This is an overloaded member function, provided for convenience.

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

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(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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(), and The Graphics View Coordinate System.

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

This is an overloaded member function, provided for convenience.

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

This