QGraphicsScene Class | Qt 4.8 (original) (raw)

The QGraphicsScene class provides a surface for managing a large number of 2D graphical items. More...

Member Function Documentation

QGraphicsScene::QGraphicsScene(QObject * parent = 0)

Constructs a QGraphicsScene object. The parent parameter is passed to QObject's constructor.

QGraphicsScene::QGraphicsScene(const QRectF & sceneRect, QObject * parent = 0)

Constructs a QGraphicsScene object, using sceneRect for its scene rectangle. The parent parameter is passed to QObject's constructor.

See also sceneRect.

QGraphicsScene::QGraphicsScene(qreal x, qreal y, qreal width, qreal height, QObject * parent = 0)

Constructs a QGraphicsScene object, using the rectangle specified by (x, y), and the given width and height for its scene rectangle. The parent parameter is passed to QObject's constructor.

See also sceneRect.

[virtual] QGraphicsScene::~QGraphicsScene()

Removes and deletes all items from the scene object before destroying the scene object. The scene object is removed from the application's global scene list, and it is removed from all associated views.

QGraphicsItem * QGraphicsScene::activePanel() const

Returns the current active panel, or 0 if no panel is currently active.

This function was introduced in Qt 4.6.

See also QGraphicsScene::setActivePanel().

QGraphicsWidget * QGraphicsScene::activeWindow() const

Returns the current active window, or 0 if no window is currently active.

This function was introduced in Qt 4.4.

See also QGraphicsScene::setActiveWindow().

QGraphicsEllipseItem * QGraphicsScene::addEllipse(const QRectF & rect, const QPen & pen = QPen(), const QBrush & brush = QBrush())

Creates and adds an ellipse item to the scene, and returns the item pointer. The geometry of the ellipse is defined by rect, and its pen and brush are initialized to pen and brush.

Note that the item's geometry is provided in item coordinates, and its position is initialized to (0, 0).

If the item is visible (i.e., QGraphicsItem::isVisible() returns true), QGraphicsScene will emit changed() once control goes back to the event loop.

See also addLine(), addPath(), addPixmap(), addRect(), addText(), addItem(), and addWidget().

QGraphicsEllipseItem * QGraphicsScene::addEllipse(qreal x, qreal y, qreal w, qreal h, const QPen & pen = QPen(), const QBrush & brush = QBrush())

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

This function was introduced in Qt 4.3.

void QGraphicsScene::addItem(QGraphicsItem * item)

Adds or moves the item and all its childen to this scene. This scene takes ownership of the item.

If the item is visible (i.e., QGraphicsItem::isVisible() returns true), QGraphicsScene will emit changed() once control goes back to the event loop.

If the item is already in a different scene, it will first be removed from its old scene, and then added to this scene as a top-level.

QGraphicsScene will send ItemSceneChange notifications to item while it is added to the scene. If item does not currently belong to a scene, only one notification is sent. If it does belong to scene already (i.e., it is moved to this scene), QGraphicsScene will send an addition notification as the item is removed from its previous scene.

If the item is a panel, the scene is active, and there is no active panel in the scene, then the item will be activated.

See also removeItem(), addEllipse(), addLine(), addPath(), addPixmap(), addRect(), addText(), addWidget(), and Sorting.

QGraphicsLineItem * QGraphicsScene::addLine(const QLineF & line, const QPen & pen = QPen())

Creates and adds a line item to the scene, and returns the item pointer. The geometry of the line is defined by line, and its pen is initialized to pen.

Note that the item's geometry is provided in item coordinates, and its position is initialized to (0, 0).

If the item is visible (i.e., QGraphicsItem::isVisible() returns true), QGraphicsScene will emit changed() once control goes back to the event loop.

See also addEllipse(), addPath(), addPixmap(), addRect(), addText(), addItem(), and addWidget().

QGraphicsLineItem * QGraphicsScene::addLine(qreal x1, qreal y1, qreal x2, qreal y2, const QPen & pen = QPen())

This convenience function is equivalent to calling addLine(QLineF(x1, y1, x2, y2), pen).

This function was introduced in Qt 4.3.

QGraphicsPathItem * QGraphicsScene::addPath(const QPainterPath & path, const QPen & pen = QPen(), const QBrush & brush = QBrush())

Creates and adds a path item to the scene, and returns the item pointer. The geometry of the path is defined by path, and its pen and brush are initialized to pen and brush.

Note that the item's geometry is provided in item coordinates, and its position is initialized to (0, 0).

If the item is visible (i.e., QGraphicsItem::isVisible() returns true), QGraphicsScene will emit changed() once control goes back to the event loop.

See also addEllipse(), addLine(), addPixmap(), addRect(), addText(), addItem(), and addWidget().

QGraphicsPixmapItem * QGraphicsScene::addPixmap(const QPixmap & pixmap)

Creates and adds a pixmap item to the scene, and returns the item pointer. The pixmap is defined by pixmap.

Note that the item's geometry is provided in item coordinates, and its position is initialized to (0, 0).

If the item is visible (i.e., QGraphicsItem::isVisible() returns true), QGraphicsScene will emit changed() once control goes back to the event loop.

See also addEllipse(), addLine(), addPath(), addRect(), addText(), addItem(), and addWidget().

QGraphicsPolygonItem * QGraphicsScene::addPolygon(const QPolygonF & polygon, const QPen & pen = QPen(), const QBrush & brush = QBrush())

Creates and adds a polygon item to the scene, and returns the item pointer. The polygon is defined by polygon, and its pen and brush are initialized to pen and brush.

Note that the item's geometry is provided in item coordinates, and its position is initialized to (0, 0).

If the item is visible (i.e., QGraphicsItem::isVisible() returns true), QGraphicsScene will emit changed() once control goes back to the event loop.

See also addEllipse(), addLine(), addPath(), addRect(), addText(), addItem(), and addWidget().

QGraphicsRectItem * QGraphicsScene::addRect(const QRectF & rect, const QPen & pen = QPen(), const QBrush & brush = QBrush())

Creates and adds a rectangle item to the scene, and returns the item pointer. The geometry of the rectangle is defined by rect, and its pen and brush are initialized to pen and brush.

Note that the item's geometry is provided in item coordinates, and its position is initialized to (0, 0). For example, if a QRect(50, 50, 100, 100) is added, its top-left corner will be at (50, 50) relative to the origin in the items coordinate system.

If the item is visible (i.e., QGraphicsItem::isVisible() returns true), QGraphicsScene will emit changed() once control goes back to the event loop.

See also addEllipse(), addLine(), addPixmap(), addPixmap(), addText(), addItem(), and addWidget().

QGraphicsRectItem * QGraphicsScene::addRect(qreal x, qreal y, qreal w, qreal h, const QPen & pen = QPen(), const QBrush & brush = QBrush())

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

This function was introduced in Qt 4.3.

QGraphicsSimpleTextItem * QGraphicsScene::addSimpleText(const QString & text, const QFont & font = QFont())

Creates and adds a QGraphicsSimpleTextItem to the scene, and returns the item pointer. The text string is initialized to text, and its font is initialized to font.

The item's position is initialized to (0, 0).

If the item is visible (i.e., QGraphicsItem::isVisible() returns true), QGraphicsScene will emit changed() once control goes back to the event loop.

See also addEllipse(), addLine(), addPixmap(), addPixmap(), addRect(), addItem(), and addWidget().

QGraphicsTextItem * QGraphicsScene::addText(const QString & text, const QFont & font = QFont())

Creates and adds a text item to the scene, and returns the item pointer. The text string is initialized to text, and its font is initialized to font.

The item's position is initialized to (0, 0).

If the item is visible (i.e., QGraphicsItem::isVisible() returns true), QGraphicsScene will emit changed() once control goes back to the event loop.

See also addEllipse(), addLine(), addPixmap(), addPixmap(), addRect(), addItem(), and addWidget().

QGraphicsProxyWidget * QGraphicsScene::addWidget(QWidget * widget, Qt::WindowFlags wFlags = 0)

Creates a new QGraphicsProxyWidget for widget, adds it to the scene, and returns a pointer to the proxy. wFlags set the default window flags for the embedding proxy widget.

The item's position is initialized to (0, 0).

If the item is visible (i.e., QGraphicsItem::isVisible() returns true), QGraphicsScene will emit changed() once control goes back to the event loop.

Note that widgets with the Qt::WA_PaintOnScreen widget attribute set and widgets that wrap an external application or controller are not supported. Examples are QGLWidget and QAxWidget.

See also addEllipse(), addLine(), addPixmap(), addPixmap(), addRect(), addText(), addSimpleText(), and addItem().

[slot] void QGraphicsScene::advance()

This slot advances the scene by one step, by calling QGraphicsItem::advance() for all items on the scene. This is done in two phases: in the first phase, all items are notified that the scene is about to change, and in the second phase all items are notified that they can move. In the first phase, QGraphicsItem::advance() is called passing a value of 0 as an argument, and 1 is passed in the second phase.

See also QGraphicsItem::advance(), QGraphicsItemAnimation, and QTimeLine.

[signal] void QGraphicsScene::changed(const QList<QRectF> & region)

This signal is emitted by QGraphicsScene when control reaches the event loop, if the scene content changes. The region parameter contains a list of scene rectangles that indicate the area that has been changed.

See also QGraphicsView::updateScene().

[slot] void QGraphicsScene::clear()

Removes and deletes all items from the scene, but otherwise leaves the state of the scene unchanged.

This function was introduced in Qt 4.4.

See also addItem().

void QGraphicsScene::clearFocus()

Clears focus from the scene. If any item has focus when this function is called, it will lose focus, and regain focus again once the scene regains focus.

A scene that does not have focus ignores key events.

See also hasFocus(), setFocus(), and setFocusItem().

[slot] void QGraphicsScene::clearSelection()

Clears the current selection.

See also setSelectionArea() and selectedItems().

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

Returns a list of all items that collide with item. Collisions are determined by calling QGraphicsItem::collidesWithItem(); the collision detection is determined by mode. By default, all items whose shape intersects item or is contained inside item's shape are returned.

The items are returned in descending stacking order (i.e., the first item in the list is the uppermost item, and the last item is the lowermost item).

See also items(), itemAt(), QGraphicsItem::collidesWithItem(), and Sorting.

This event handler, for event contextMenuEvent, can be reimplemented in a subclass to receive context menu events. The default implementation forwards the event to the topmost item that accepts context menu events at the position of the event. If no items accept context menu events at this position, the event is ignored.

See also QGraphicsItem::contextMenuEvent().

QGraphicsItemGroup * QGraphicsScene::createItemGroup(const QList<QGraphicsItem *> & items)

Groups all items in items into a new QGraphicsItemGroup, and returns a pointer to the group. The group is created with the common ancestor of items as its parent, and with position (0, 0). The items are all reparented to the group, and their positions and transformations are mapped to the group. If items is empty, this function will return an empty top-level QGraphicsItemGroup.

QGraphicsScene has ownership of the group item; you do not need to delete it. To dismantle (ungroup) a group, call destroyItemGroup().

See also destroyItemGroup() and QGraphicsItemGroup::addToGroup().

void QGraphicsScene::destroyItemGroup(QGraphicsItemGroup * group)

Reparents all items in group to group's parent item, then removes group from the scene, and finally deletes it. The items' positions and transformations are mapped from the group to the group's parent.

See also createItemGroup() and QGraphicsItemGroup::removeFromGroup().

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

This event handler, for event event, can be reimplemented in a subclass to receive drag enter events for the scene.

The default implementation accepts the event and prepares the scene to accept drag move events.

See also QGraphicsItem::dragEnterEvent(), dragMoveEvent(), dragLeaveEvent(), and dropEvent().

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

This event handler, for event event, can be reimplemented in a subclass to receive drag leave events for the scene.

See also QGraphicsItem::dragLeaveEvent(), dragEnterEvent(), dragMoveEvent(), and dropEvent().

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

This event handler, for event event, can be reimplemented in a subclass to receive drag move events for the scene.

See also QGraphicsItem::dragMoveEvent(), dragEnterEvent(), dragLeaveEvent(), and dropEvent().

[virtual protected] void QGraphicsScene::drawBackground(QPainter * painter, const QRectF & rect)

Draws the background of the scene using painter, before any items and the foreground are drawn. Reimplement this function to provide a custom background for the scene.

All painting is done in scene coordinates. The rect parameter is the exposed rectangle.

If all you want is to define a color, texture, or gradient for the background, you can call setBackgroundBrush() instead.

See also drawForeground() and drawItems().

[virtual protected] void QGraphicsScene::drawForeground(QPainter * painter, const QRectF & rect)

Draws the foreground of the scene using painter, after the background and all items have been drawn. Reimplement this function to provide a custom foreground for the scene.

All painting is done in scene coordinates. The rect parameter is the exposed rectangle.

If all you want is to define a color, texture or gradient for the foreground, you can call setForegroundBrush() instead.

See also drawBackground() and drawItems().

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

This event handler, for event event, can be reimplemented in a subclass to receive drop events for the scene.

See also QGraphicsItem::dropEvent(), dragEnterEvent(), dragMoveEvent(), and dragLeaveEvent().

[virtual protected] bool QGraphicsScene::event(QEvent * event)

Reimplemented from QObject::event().

Processes the event event, and dispatches it to the respective event handlers.

In addition to calling the convenience event handlers, this function is responsible for converting mouse move events to hover events for when there is no mouse grabber item. Hover events are delivered directly to items; there is no convenience function for them.

Unlike QWidget, QGraphicsScene does not have the convenience functions enterEvent() and leaveEvent(). Use this function to obtain those events instead.

See also contextMenuEvent(), keyPressEvent(), keyReleaseEvent(), mousePressEvent(), mouseMoveEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), focusInEvent(), and focusOutEvent().

[virtual protected] bool QGraphicsScene::eventFilter(QObject * watched, QEvent * event)

Reimplemented from QObject::eventFilter().

QGraphicsScene filters QApplication's events to detect palette and font changes.

[virtual protected] void QGraphicsScene::focusInEvent(QFocusEvent * focusEvent)

This event handler, for event focusEvent, can be reimplemented in a subclass to receive focus in events.

The default implementation sets focus on the scene, and then on the last focus item.

See also QGraphicsItem::focusOutEvent().

QGraphicsItem * QGraphicsScene::focusItem() const

When the scene is active, this functions returns the scene's current focus item, or 0 if no item currently has focus. When the scene is inactive, this functions returns the item that will gain input focus when the scene becomes active.

The focus item receives keyboard input when the scene receives a key event.

See also setFocusItem(), QGraphicsItem::hasFocus(), and isActive().

[protected slot] bool QGraphicsScene::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. If next is true, this function searches forward; if next is false, it searches backward.

You can reimplement this function in a subclass of QGraphicsScene to provide fine-grained control over how tab focus passes inside your scene. The default implementation is based on the tab focus chain defined by QGraphicsWidget::setTabOrder().

This function was introduced in Qt 4.4.

[virtual protected] void QGraphicsScene::focusOutEvent(QFocusEvent * focusEvent)

This event handler, for event focusEvent, can be reimplemented in a subclass to receive focus out events.

The default implementation removes focus from any focus item, then removes focus from the scene.

See also QGraphicsItem::focusInEvent().

bool QGraphicsScene::hasFocus() const

Returns true if the scene has focus; otherwise returns false. If the scene has focus, it will will forward key events from QKeyEvent to any item that has focus.

See also setFocus() and setFocusItem().

qreal QGraphicsScene::height() const

This convenience function is equivalent to calling sceneRect().height().

See also width().

[virtual protected] void QGraphicsScene::helpEvent(QGraphicsSceneHelpEvent * helpEvent)

This event handler, for event helpEvent, can be reimplemented in a subclass to receive help events. The events are of type QEvent::ToolTip, which are created when a tooltip is requested.

The default implementation shows the tooltip of the topmost item, i.e., the item with the highest z-value, at the mouse cursor position. If no item has a tooltip set, this function does nothing.

See also QGraphicsItem::toolTip() and QGraphicsSceneHelpEvent.

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

This event handler, for event event, can be reimplemented in a subclass to receive input method events for the scene.

The default implementation forwards the event to the focusItem(). If no item currently has focus or the current focus item does not accept input methods, this function does nothing.

See also QGraphicsItem::inputMethodEvent().

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

This method is used by input methods to query a set of properties of the scene to be able to support complex input method operations as support for surrounding text and reconversions.

The query parameter specifies which property is queried.

See also QWidget::inputMethodQuery().

[slot] void QGraphicsScene::invalidate(const QRectF & rect = QRectF(), SceneLayers layers = AllLayers)

Invalidates and schedules a redraw of the layers in rect on the scene. Any cached content in layers is unconditionally invalidated and redrawn.

You can use this function overload to notify QGraphicsScene of changes to the background or the foreground of the scene. This function is commonly used for scenes with tile-based backgrounds to notify changes when QGraphicsView has enabled CacheBackground.

Example:

QRectF TileScene::rectForTile(int x, int y) const {

return [QRectF](qrectf.html)(x * tileWidth, y * tileHeight, tileWidth, tileHeight);

}

void TileScene::setTile(int x, int y, const QPixmap &pixmap) {

if (x >= 0 && x < numTilesH && y >= 0 && y < numTilesV) {
    tiles[y][x] = pixmap;
    invalidate(rectForTile(x, y), BackgroundLayer);
}

}

void TileScene::drawBackground(QPainter *painter, const QRectF &exposed) {

for (int y = 0; y < numTilesV; ++y) {
    for (int x = 0; x < numTilesH; ++x) {
        [QRectF](qrectf.html) rect = rectForTile(x, y);
        if (exposed.intersects(rect))
            painter->drawPixmap(rect.topLeft(), tiles[y][x]);
    }
}

}

Note that QGraphicsView currently supports background caching only (see QGraphicsView::CacheBackground). This function is equivalent to calling update() if any layer but BackgroundLayer is passed.

See also QGraphicsView::resetCachedContent().

void QGraphicsScene::invalidate(qreal x, qreal y, qreal w, qreal h, SceneLayers layers = AllLayers)

This is an overloaded function.

This convenience function is equivalent to calling invalidate(QRectF(x, y, w, h), layers);

This function was introduced in Qt 4.3.

bool QGraphicsScene::isActive() const

Returns true if the scene is active (e.g., it's viewed by at least one QGraphicsView that is active); otherwise returns false.

This function was introduced in Qt 4.6.

See also QGraphicsItem::isActive() and QWidget::isActiveWindow().

QGraphicsItem * QGraphicsScene::itemAt(const QPointF & position, const QTransform & deviceTransform) const

Returns the topmost visible item at the specified position, or 0 if there are no items at this position.

deviceTransform is the transformation that applies to the view, and needs to be provided if the scene contains items that ignore transformations.

This function was introduced in Qt 4.6.

See also items(), collidingItems(), and Sorting.

QGraphicsItem * QGraphicsScene::itemAt(qreal x, qreal y, const QTransform & deviceTransform) const

This is an overloaded function.

Returns the topmost item at the position specified by (x, y), or 0 if there are no items at this position.

deviceTransform is the transformation that applies to the view, and needs to be provided if the scene contains items that ignore transformations.

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

This function was introduced in Qt 4.6.

QList<QGraphicsItem *> QGraphicsScene::items() const

Returns a list of all items in the scene in descending stacking order.

See also addItem(), removeItem(), and Sorting.

QList<QGraphicsItem *> QGraphicsScene::items(Qt::SortOrder order) const

Returns an ordered list of all items on the scene. order decides the stacking order.

See also addItem(), removeItem(), and Sorting.

QList<QGraphicsItem *> QGraphicsScene::items(const QPointF & pos, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform & deviceTransform = QTransform()) const

Returns all visible items that, depending on mode, are at the specified pos in a list sorted using order.

The default value for mode is Qt::IntersectsItemShape; all items whose exact shape intersects with pos are returned.

deviceTransform is the transformation that applies to the view, and needs to be provided if the scene contains items that ignore transformations.

This function was introduced in Qt 4.6.

See also itemAt() and Sorting.

QList<QGraphicsItem *> QGraphicsScene::items(qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform & deviceTransform = QTransform()) const

This is an overloaded function.

Returns all visible items that, depending on mode, are either inside or intersect with the rectangle defined by x, y, w and h, in a list sorted using order.

deviceTransform is the transformation that applies to the view, and needs to be provided if the scene contains items that ignore transformations.

This function was introduced in Qt 4.6.

QList<QGraphicsItem *> QGraphicsScene::items(const QRectF & rect, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform & deviceTransform = QTransform()) const

This is an overloaded function.

Returns all visible items that, depending on mode, are either inside or intersect with the specified rect and return a list sorted using order.

The default value for mode is Qt::IntersectsItemShape; all items whose exact shape intersects with or is contained by rect are returned.

deviceTransform is the transformation that applies to the view, and needs to be provided if the scene contains items that ignore transformations.

This function was introduced in Qt 4.6.

See also itemAt() and Sorting.

QList<QGraphicsItem *> QGraphicsScene::items(const QPolygonF & polygon, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform & deviceTransform = QTransform()) const

This is an overloaded function.

Returns all visible items that, depending on mode, are either inside or intersect with the specified polygon and return a list sorted using order.

The default value for mode is Qt::IntersectsItemShape; all items whose exact shape intersects with or is contained by polygon are returned.

deviceTransform is the transformation that applies to the view, and needs to be provided if the scene contains items that ignore transformations.

This function was introduced in Qt 4.6.

See also itemAt() and Sorting.

QList<QGraphicsItem *> QGraphicsScene::items(const QPainterPath & path, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform & deviceTransform = QTransform()) const

This is an overloaded function.

Returns all visible items that, depending on mode, are either inside or intersect with the specified path and return a list sorted using order.

The default value for mode is Qt::IntersectsItemShape; all items whose exact shape intersects with or is contained by path are returned.

deviceTransform is the transformation that applies to the view, and needs to be provided if the scene contains items that ignore transformations.

This function was introduced in Qt 4.6.

See also itemAt() and Sorting.

QRectF QGraphicsScene::itemsBoundingRect() const

Calculates and returns the bounding rect of all items on the scene. This function works by iterating over all items, and because if this, it can be slow for large scenes.

See also sceneRect().

[virtual protected] void QGraphicsScene::keyPressEvent(QKeyEvent * keyEvent)

This event handler, for event keyEvent, can be reimplemented in a subclass to receive keypress events. The default implementation forwards the event to current focus item.

See also QGraphicsItem::keyPressEvent() and focusItem().

[virtual protected] void QGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent)

This event handler, for event keyEvent, can be reimplemented in a subclass to receive key release events. The default implementation forwards the event to current focus item.

See also QGraphicsItem::keyReleaseEvent() and focusItem().

[virtual protected] void QGraphicsScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * mouseEvent)

This event handler, for event mouseEvent, can be reimplemented in a subclass to receive mouse doubleclick events for the scene.

If someone doubleclicks on the scene, the scene 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. If the doubleclick event is delivered to a different item than the one that received the first press and release, it will be delivered as a press event. However, tripleclick events are not delivered as doubleclick events in this case.

The default implementation is similar to mousePressEvent().

See also QGraphicsItem::mousePressEvent(), QGraphicsItem::mouseMoveEvent(), QGraphicsItem::mouseReleaseEvent(), and QGraphicsItem::setAcceptedMouseButtons().

QGraphicsItem * QGraphicsScene::mouseGrabberItem() const

Returns the current mouse grabber item, or 0 if no item is currently grabbing the mouse. The mouse grabber item is the item that receives all mouse events sent to the scene.

An item becomes a mouse grabber when it receives and accepts a mouse press event, and it stays the mouse grabber until either of the following events occur:

If the item loses its mouse grab, the scene will ignore all mouse events until a new item grabs the mouse (i.e., until a new item receives a mouse press event).

[virtual protected] void QGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)

This event handler, for event mouseEvent, can be reimplemented in a subclass to receive mouse move events for the scene.

The default implementation depends on the mouse grabber state. If there is a mouse grabber item, the event is sent to the mouse grabber. If there are any items that accept hover events at the current position, the event is translated into a hover event and accepted; otherwise it's ignored.

See also QGraphicsItem::mousePressEvent(), QGraphicsItem::mouseReleaseEvent(), QGraphicsItem::mouseDoubleClickEvent(), and QGraphicsItem::setAcceptedMouseButtons().

[virtual protected] void QGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent)

This event handler, for event mouseEvent, can be reimplemented in a subclass to receive mouse press events for the scene.

The default implementation depends on the state of the scene. If there is a mouse grabber item, then the event is sent to the mouse grabber. Otherwise, it is forwarded to the topmost item that accepts mouse events at the scene position from the event, and that item promptly becomes the mouse grabber item.

If there is no item at the given position on the scene, the selection area is reset, any focus item loses its input focus, and the event is then ignored.

See also QGraphicsItem::mousePressEvent() and QGraphicsItem::setAcceptedMouseButtons().

[virtual protected] void QGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent)

This event handler, for event mouseEvent, can be reimplemented in a subclass to receive mouse release events for the scene.

The default implementation depends on the mouse grabber state. If there is no mouse grabber, the event is ignored. Otherwise, if there is a mouse grabber item, the event is sent to the mouse grabber. If this mouse release represents the last pressed button on the mouse, the mouse grabber item then loses the mouse grab.

See also QGraphicsItem::mousePressEvent(), QGraphicsItem::mouseMoveEvent(), QGraphicsItem::mouseDoubleClickEvent(), and QGraphicsItem::setAcceptedMouseButtons().

void QGraphicsScene::removeItem(QGraphicsItem * item)

Removes the item item and all its children from the scene. The ownership of item is passed on to the caller (i.e., QGraphicsScene will no longer delete item when destroyed).

See also addItem().

void QGraphicsScene::render(QPainter * painter, const QRectF & target = QRectF(), const QRectF & source = QRectF(), Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio)

Renders the source rect from scene into target, using painter. This function is useful for capturing the contents of the scene onto a paint device, such as a QImage (e.g., to take a screenshot), or for printing with QPrinter. For example:

If source is a null rect, this function will use sceneRect() to determine what to render. If target is a null rect, the dimensions of painter's paint device will be used.

The source rect contents will be transformed according to aspectRatioMode to fit into the target rect. By default, the aspect ratio is kept, and source is scaled to fit in target.

See also QGraphicsView::render().

[signal] void QGraphicsScene::sceneRectChanged(const QRectF & rect)

This signal is emitted by QGraphicsScene whenever the scene rect changes. The rect parameter is the new scene rectangle.

See also QGraphicsView::updateSceneRect().

QList<QGraphicsItem *> QGraphicsScene::selectedItems() const

Returns a list of all currently selected items. The items are returned in no particular order.

See also setSelectionArea().

QPainterPath QGraphicsScene::selectionArea() const

Returns the selection area that was previously set with setSelectionArea(), or an empty QPainterPath if no selection area has been set.

See also setSelectionArea().

[signal] void QGraphicsScene::selectionChanged()

This signal is emitted by QGraphicsScene whenever the selection changes. You can call selectedItems() to get the new list of selected items.

The selection changes whenever an item is selected or unselected, a selection area is set, cleared or otherwise changed, if a preselected item is added to the scene, or if a selected item is removed from the scene.

QGraphicsScene emits this signal only once for group selection operations. For example, if you set a selection area, select or unselect a QGraphicsItemGroup, or if you add or remove from the scene a parent item that contains several selected items, selectionChanged() is emitted only once after the operation has completed (instead of once for each item).

This function was introduced in Qt 4.3.

See also setSelectionArea(), selectedItems(), and QGraphicsItem::setSelected().

bool QGraphicsScene::sendEvent(QGraphicsItem * item, QEvent * event)

Sends event event to item item through possible event filters.

The event is sent only if the item is enabled.

Returns false if the event was filtered or if the item is disabled. Otherwise returns the value that was returned from the event handler.

This function was introduced in Qt 4.6.

See also QGraphicsItem::sceneEvent() and QGraphicsItem::sceneEventFilter().

void QGraphicsScene::setActivePanel(QGraphicsItem * item)

Activates item, which must be an item in this scene. You can also pass 0 for item, in which case QGraphicsScene will deactivate any currently active panel.

If the scene is currently inactive, item remains inactive until the scene becomes active (or, ir item is 0, no item will be activated).

This function was introduced in Qt 4.6.

See also activePanel(), isActive(), and QGraphicsItem::isActive().

void QGraphicsScene::setActiveWindow(QGraphicsWidget * widget)

Activates widget, which must be a widget in this scene. You can also pass 0 for widget, in which case QGraphicsScene will deactivate any currently active window.

This function was introduced in Qt 4.4.

See also activeWindow() and QGraphicsWidget::isActiveWindow().

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

Sets focus on the scene by sending a QFocusEvent to the scene, passing focusReason as the reason. If the scene regains focus after having previously lost it while an item had focus, the last focus item will receive focus with focusReason as the reason.

If the scene already has focus, this function does nothing.

See also hasFocus(), clearFocus(), and setFocusItem().

void QGraphicsScene::setFocusItem(QGraphicsItem * item, Qt::FocusReason focusReason = Qt::OtherFocusReason)

Sets the scene's focus item to item, with the focus reason focusReason, after removing focus from any previous item that may have had focus.

If item is 0, or if it either does not accept focus (i.e., it does not have the QGraphicsItem::ItemIsFocusable flag enabled), or is not visible or not enabled, this function only removes focus from any previous focusitem.

If item is not 0, and the scene does not currently have focus (i.e., hasFocus() returns false), this function will call setFocus() automatically.

See also focusItem(), hasFocus(), and setFocus().

void QGraphicsScene::setSelectionArea(const QPainterPath & path, const QTransform & deviceTransform)

Sets the selection area to path. All items within this area are immediately selected, and all items outside are unselected. You can get the list of all selected items by calling selectedItems().

deviceTransform is the transformation that applies to the view, and needs to be provided if the scene contains items that ignore transformations.

For an item to be selected, it must be marked as selectable (QGraphicsItem::ItemIsSelectable).

This function was introduced in Qt 4.6.

See also clearSelection() and selectionArea().

void QGraphicsScene::setSelectionArea(const QPainterPath & path, Qt::ItemSelectionMode mode, const QTransform & deviceTransform)

This is an overloaded function.

Sets the selection area to path using mode to determine if items are included in the selection area.

deviceTransform is the transformation that applies to the view, and needs to be provided if the scene contains items that ignore transformations.

This function was introduced in Qt 4.6.

See also clearSelection() and selectionArea().

void QGraphicsScene::setStyle(QStyle * style)

Sets or replaces the style of the scene to style, and reparents the style to this scene. Any previously assigned style is deleted. The scene's style defaults to QApplication::style(), and serves as the default for all QGraphicsWidget items in the scene.

Changing the style, either directly by calling this function, or indirectly by calling QApplication::setStyle(), will automatically update the style for all widgets in the scene that do not have a style explicitly assigned to them.

If style is 0, QGraphicsScene will revert to QApplication::style().

This function was introduced in Qt 4.4.

See also style().

QStyle * QGraphicsScene::style() const

Returns the scene's style, or the same as QApplication::style() if the scene has not been explicitly assigned a style.

This function was introduced in Qt 4.4.

See also setStyle().

[slot] void QGraphicsScene::update(const QRectF & rect = QRectF())

Schedules a redraw of the area rect on the scene.

See also sceneRect() and changed().

void QGraphicsScene::update(qreal x, qreal y, qreal w, qreal h)

This is an overloaded function.

This function is equivalent to calling update(QRectF(x, y, w, h));

This function was introduced in Qt 4.3.

QList<QGraphicsView *> QGraphicsScene::views() const

Returns a list of all the views that display this scene.

See also QGraphicsView::scene().

[virtual protected] void QGraphicsScene::wheelEvent(QGraphicsSceneWheelEvent * wheelEvent)

This event handler, for event wheelEvent, can be reimplemented in a subclass to receive mouse wheel events for the scene.

By default, the event is delivered to the topmost visible item under the cursor. If ignored, the event propagates to the item beneath, and again until the event is accepted, or it reaches the scene. If no items accept the event, it is ignored.

See also QGraphicsItem::wheelEvent().

qreal QGraphicsScene::width() const

This convenience function is equivalent to calling sceneRect().width().

See also height().