Qt 4.8
Public Types | Public Slots | Signals | Public Functions | Protected Slots | Protected Functions | Properties | Friends | List of all members
QGraphicsScene Class Reference

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

#include <qgraphicsscene.h>

Inheritance diagram for QGraphicsScene:
QObject QDeclarativeScene

Public Types

enum  ItemIndexMethod { BspTreeIndex, NoIndex = -1 }
 This enum describes the indexing algorithms QGraphicsScene provides for managing positional information about items on the scene. More...
 
enum  SceneLayer { ItemLayer = 0x1, BackgroundLayer = 0x2, ForegroundLayer = 0x4, AllLayers = 0xffff }
 This enum describes the rendering layers in a QGraphicsScene. More...
 

Public Slots

void advance ()
 This slot advances the scene by one step, by calling QGraphicsItem::advance() for all items on the scene. More...
 
void clear ()
 Removes and deletes all items from the scene, but otherwise leaves the state of the scene unchanged. More...
 
void clearSelection ()
 Clears the current selection. More...
 
void invalidate (const QRectF &rect=QRectF(), SceneLayers layers=AllLayers)
 Invalidates and schedules a redraw of the layers in rect on the scene. More...
 
void update (const QRectF &rect=QRectF())
 Schedules a redraw of the area rect on the scene. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void changed (const QList< QRectF > &region)
 This signal is emitted by QGraphicsScene when control reaches the event loop, if the scene content changes. More...
 
void sceneRectChanged (const QRectF &rect)
 This signal is emitted by QGraphicsScene whenever the scene rect changes. More...
 
void selectionChanged ()
 This signal is emitted by QGraphicsScene whenever the selection changes. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

QGraphicsItemactivePanel () const
 Returns the current active panel, or 0 if no panel is currently active. More...
 
QGraphicsWidgetactiveWindow () const
 Returns the current active window, or 0 if no window is currently active. More...
 
QGraphicsEllipseItemaddEllipse (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. More...
 
QGraphicsEllipseItemaddEllipse (qreal x, qreal y, qreal w, qreal h, const QPen &pen=QPen(), const QBrush &brush=QBrush())
 
void addItem (QGraphicsItem *item)
 Adds or moves the item and all its childen to this scene. More...
 
QGraphicsLineItemaddLine (const QLineF &line, const QPen &pen=QPen())
 Creates and adds a line item to the scene, and returns the item pointer. More...
 
QGraphicsLineItemaddLine (qreal x1, qreal y1, qreal x2, qreal y2, const QPen &pen=QPen())
 
QGraphicsPathItemaddPath (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. More...
 
QGraphicsPixmapItemaddPixmap (const QPixmap &pixmap)
 Creates and adds a pixmap item to the scene, and returns the item pointer. More...
 
QGraphicsPolygonItemaddPolygon (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. More...
 
QGraphicsRectItemaddRect (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. More...
 
QGraphicsRectItemaddRect (qreal x, qreal y, qreal w, qreal h, const QPen &pen=QPen(), const QBrush &brush=QBrush())
 
QGraphicsSimpleTextItemaddSimpleText (const QString &text, const QFont &font=QFont())
 Creates and adds a QGraphicsSimpleTextItem to the scene, and returns the item pointer. More...
 
QGraphicsTextItemaddText (const QString &text, const QFont &font=QFont())
 Creates and adds a text item to the scene, and returns the item pointer. More...
 
QGraphicsProxyWidgetaddWidget (QWidget *widget, Qt::WindowFlags wFlags=0)
 Creates a new QGraphicsProxyWidget for widget, adds it to the scene, and returns a pointer to the proxy. More...
 
QBrush backgroundBrush () const
 
int bspTreeDepth () const
 
void clearFocus ()
 Clears focus from the scene. More...
 
QList< QGraphicsItem * > collidingItems (const QGraphicsItem *item, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 Returns a list of all items that collide with item. More...
 
QGraphicsItemGroupcreateItemGroup (const QList< QGraphicsItem *> &items)
 Groups all items in items into a new QGraphicsItemGroup, and returns a pointer to the group. More...
 
void destroyItemGroup (QGraphicsItemGroup *group)
 Reparents all items in group to group's parent item, then removes group from the scene, and finally deletes it. More...
 
QGraphicsItemfocusItem () const
 When the scene is active, this functions returns the scene's current focus item, or 0 if no item currently has focus. More...
 
QFont font () const
 
QBrush foregroundBrush () const
 
bool hasFocus () const
 Returns true if the scene has focus; otherwise returns false. More...
 
qreal height () const
 This convenience function is equivalent to calling sceneRect(). More...
 
virtual QVariant 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. More...
 
void invalidate (qreal x, qreal y, qreal w, qreal h, SceneLayers layers=AllLayers)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool isActive () const
 Returns true if the scene is active (e. More...
 
bool isSortCacheEnabled () const
 
QGraphicsItemitemAt (const QPointF &pos) const
 Returns the topmost visible item at the specified position, or 0 if there are no items at this position. More...
 
QGraphicsItemitemAt (const QPointF &pos, const QTransform &deviceTransform) const
 Returns the topmost visible item at the specified position, or 0 if there are no items at this position. More...
 
QGraphicsItemitemAt (qreal x, qreal y) const
 Returns the topmost item at the position specified by (x, y), or 0 if there are no items at this position. More...
 
QGraphicsItemitemAt (qreal x, qreal y, const QTransform &deviceTransform) const
 Returns the topmost item at the position specified by (x, y), or 0 if there are no items at this position. More...
 
ItemIndexMethod itemIndexMethod () const
 
QList< QGraphicsItem * > items () const
 Returns a list of all items in the scene in descending stacking order. More...
 
QList< QGraphicsItem * > items (Qt::SortOrder order) const
 Returns an ordered list of all items on the scene. More...
 
QList< QGraphicsItem * > 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. More...
 
QList< QGraphicsItem * > items (const QRectF &rect, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform=QTransform()) const
 Returns all visible items that, depending on mode, are either inside or intersect with the specified rect and return a list sorted using order. More...
 
QList< QGraphicsItem * > items (const QPolygonF &polygon, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform=QTransform()) const
 Returns all visible items that, depending on mode, are either inside or intersect with the specified polygon and return a list sorted using order. More...
 
QList< QGraphicsItem * > items (const QPainterPath &path, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform=QTransform()) const
 Returns all visible items that, depending on mode, are either inside or intersect with the specified path and return a list sorted using order. More...
 
QList< QGraphicsItem * > items (const QPointF &pos) const
 Returns all visible items at position pos in the scene. More...
 
QList< QGraphicsItem * > items (const QRectF &rect, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 Returns all visible items that, depending on mode, are either inside or intersect with the specified rectangle. More...
 
QList< QGraphicsItem * > items (const QPolygonF &polygon, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
QList< QGraphicsItem * > items (const QPainterPath &path, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
QList< QGraphicsItem * > items (qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 
QList< QGraphicsItem * > items (qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform=QTransform()) const
 Returns all visible items that, depending on mode, are either inside or intersect with the rectangle defined by x, y,. More...
 
QRectF itemsBoundingRect () const
 Calculates and returns the bounding rect of all items on the scene. More...
 
QGraphicsItemmouseGrabberItem () const
 Returns the current mouse grabber item, or 0 if no item is currently grabbing the mouse. More...
 
QPalette palette () const
 
 QGraphicsScene (QObject *parent=0)
 Constructs a QGraphicsScene object. More...
 
 QGraphicsScene (const QRectF &sceneRect, QObject *parent=0)
 Constructs a QGraphicsScene object, using sceneRect for its scene rectangle. More...
 
 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. More...
 
void removeItem (QGraphicsItem *item)
 Removes the item item and all its children from the scene. More...
 
void 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. More...
 
QRectF sceneRect () const
 
QList< QGraphicsItem * > selectedItems () const
 Returns a list of all currently selected items. More...
 
QPainterPath selectionArea () const
 Returns the selection area that was previously set with setSelectionArea(), or an empty QPainterPath if no selection area has been set. More...
 
bool sendEvent (QGraphicsItem *item, QEvent *event)
 Sends event event to item item through possible event filters. More...
 
void setActivePanel (QGraphicsItem *item)
 Activates item, which must be an item in this scene. More...
 
void setActiveWindow (QGraphicsWidget *widget)
 Activates widget, which must be a widget in this scene. More...
 
void setBackgroundBrush (const QBrush &brush)
 
void setBspTreeDepth (int depth)
 
void setFocus (Qt::FocusReason focusReason=Qt::OtherFocusReason)
 Sets focus on the scene by sending a QFocusEvent to the scene, passing focusReason as the reason. More...
 
void 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. More...
 
void setFont (const QFont &font)
 
void setForegroundBrush (const QBrush &brush)
 
void setItemIndexMethod (ItemIndexMethod method)
 
void setPalette (const QPalette &palette)
 
void setSceneRect (const QRectF &rect)
 
void setSceneRect (qreal x, qreal y, qreal w, qreal h)
 
void setSelectionArea (const QPainterPath &path)
 Sets the selection area to path. More...
 
void setSelectionArea (const QPainterPath &path, const QTransform &deviceTransform)
 Sets the selection area to path. More...
 
void setSelectionArea (const QPainterPath &path, Qt::ItemSelectionMode mode)
 Sets the selection area to path using mode to determine if items are included in the selection area. More...
 
void setSelectionArea (const QPainterPath &path, Qt::ItemSelectionMode mode, const QTransform &deviceTransform)
 Sets the selection area to path using mode to determine if items are included in the selection area. More...
 
void setSortCacheEnabled (bool enabled)
 
void setStickyFocus (bool enabled)
 
void setStyle (QStyle *style)
 Sets or replaces the style of the scene to style, and reparents the style to this scene. More...
 
bool stickyFocus () const
 
QStylestyle () const
 Returns the scene's style, or the same as QApplication::style() if the scene has not been explicitly assigned a style. More...
 
void update (qreal x, qreal y, qreal w, qreal h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
QList< QGraphicsView * > views () const
 Returns a list of all the views that display this scene. More...
 
qreal width () const
 This convenience function is equivalent to calling sceneRect(). More...
 
virtual ~QGraphicsScene ()
 Removes and deletes all items from the scene object before destroying the scene object. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Slots

bool focusNextPrevChild (bool next)
 Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it cannot. More...
 

Protected Functions

virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *event)
 This event handler, for event contextMenuEvent, can be reimplemented in a subclass to receive context menu events. More...
 
virtual void dragEnterEvent (QGraphicsSceneDragDropEvent *event)
 This event handler, for event event, can be reimplemented in a subclass to receive drag enter events for the scene. More...
 
virtual void dragLeaveEvent (QGraphicsSceneDragDropEvent *event)
 This event handler, for event event, can be reimplemented in a subclass to receive drag leave events for the scene. More...
 
virtual void dragMoveEvent (QGraphicsSceneDragDropEvent *event)
 This event handler, for event event, can be reimplemented in a subclass to receive drag move events for the scene. More...
 
virtual void drawBackground (QPainter *painter, const QRectF &rect)
 Draws the background of the scene using painter, before any items and the foreground are drawn. More...
 
virtual void drawForeground (QPainter *painter, const QRectF &rect)
 Draws the foreground of the scene using painter, after the background and all items have been drawn. More...
 
virtual void drawItems (QPainter *painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem options[], QWidget *widget=0)
 Paints the given items using the provided painter, after the background has been drawn, and before the foreground has been drawn. More...
 
virtual void dropEvent (QGraphicsSceneDragDropEvent *event)
 This event handler, for event event, can be reimplemented in a subclass to receive drop events for the scene. More...
 
bool event (QEvent *event)
 Processes the event event, and dispatches it to the respective event handlers. More...
 
bool eventFilter (QObject *watched, QEvent *event)
 QGraphicsScene filters QApplication's events to detect palette and font changes. More...
 
virtual void focusInEvent (QFocusEvent *event)
 This event handler, for event focusEvent, can be reimplemented in a subclass to receive focus in events. More...
 
virtual void focusOutEvent (QFocusEvent *event)
 This event handler, for event focusEvent, can be reimplemented in a subclass to receive focus out events. More...
 
virtual void helpEvent (QGraphicsSceneHelpEvent *event)
 This event handler, for event helpEvent, can be reimplemented in a subclass to receive help events. More...
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 This event handler, for event event, can be reimplemented in a subclass to receive input method events for the scene. More...
 
virtual void keyPressEvent (QKeyEvent *event)
 This event handler, for event keyEvent, can be reimplemented in a subclass to receive keypress events. More...
 
virtual void keyReleaseEvent (QKeyEvent *event)
 This event handler, for event keyEvent, can be reimplemented in a subclass to receive key release events. More...
 
virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event)
 This event handler, for event mouseEvent, can be reimplemented in a subclass to receive mouse doubleclick events for the scene. More...
 
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event)
 This event handler, for event mouseEvent, can be reimplemented in a subclass to receive mouse move events for the scene. More...
 
virtual void mousePressEvent (QGraphicsSceneMouseEvent *event)
 This event handler, for event mouseEvent, can be reimplemented in a subclass to receive mouse press events for the scene. More...
 
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event)
 This event handler, for event mouseEvent, can be reimplemented in a subclass to receive mouse release events for the scene. More...
 
virtual void wheelEvent (QGraphicsSceneWheelEvent *event)
 This event handler, for event wheelEvent, can be reimplemented in a subclass to receive mouse wheel events for the scene. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Properties

QBrush backgroundBrush
 the background brush of the scene. More...
 
int bspTreeDepth
 the depth of QGraphicsScene's BSP index tree More...
 
QFont font
 the scene's default font More...
 
QBrush foregroundBrush
 the foreground brush of the scene. More...
 
ItemIndexMethod itemIndexMethod
 the item indexing method. More...
 
QPalette palette
 the scene's default palette More...
 
QRectF sceneRect
 the scene rectangle; the bounding rectangle of the scene More...
 
bool sortCacheEnabled
 whether sort caching is enabled More...
 
bool stickyFocus
 whether clicking into the scene background will clear focus More...
 

Friends

class QGesture
 
class QGraphicsEffect
 
class QGraphicsItem
 
class QGraphicsItemEffectSourcePrivate
 
class QGraphicsItemPrivate
 
class QGraphicsObject
 
class QGraphicsSceneBspTreeIndex
 
class QGraphicsSceneBspTreeIndexPrivate
 
class QGraphicsSceneIndex
 
class QGraphicsSceneIndexPrivate
 
class QGraphicsView
 
class QGraphicsViewPrivate
 
class QGraphicsWidget
 
class QGraphicsWidgetPrivate
 

Additional Inherited Members

- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

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

Since
4.2

The class serves as a container for QGraphicsItems. It is used together with QGraphicsView for visualizing graphical items, such as lines, rectangles, text, or even custom items, on a 2D surface. QGraphicsScene is part of the Graphics View Framework.

QGraphicsScene also provides functionality that lets you efficiently determine both the location of items, and for determining what items are visible within an arbitrary area on the scene. With the QGraphicsView widget, you can either visualize the whole scene, or zoom in and view only parts of the scene.

Example:

scene.addText("Hello, world!");
QGraphicsView view(&scene);
view.show();

Note that QGraphicsScene has no visual appearance of its own; it only manages the items. You need to create a QGraphicsView widget to visualize the scene.

To add items to a scene, you start off by constructing a QGraphicsScene object. Then, you have two options: either add your existing QGraphicsItem objects by calling addItem(), or you can call one of the convenience functions addEllipse(), addLine(), addPath(), addPixmap(), addPolygon(), addRect(), or addText(), which all return a pointer to the newly added item. The dimensions of the items added with these functions are relative to the item's coordinate system, and the items position is initialized to (0, 0) in the scene.

You can then visualize the scene using QGraphicsView. When the scene changes, (e.g., when an item moves or is transformed) QGraphicsScene emits the changed() signal. To remove an item, call removeItem().

QGraphicsScene uses an indexing algorithm to manage the location of items efficiently. By default, a BSP (Binary Space Partitioning) tree is used; an algorithm suitable for large scenes where most items remain static (i.e., do not move around). You can choose to disable this index by calling setItemIndexMethod(). For more information about the available indexing algorithms, see the itemIndexMethod property.

The scene's bounding rect is set by calling setSceneRect(). Items can be placed at any position on the scene, and the size of the scene is by default unlimited. The scene rect is used only for internal bookkeeping, maintaining the scene's item index. If the scene rect is unset, QGraphicsScene will use the bounding area of all items, as returned by itemsBoundingRect(), as the scene rect. However, itemsBoundingRect() is a relatively time consuming function, as it operates by collecting positional information for every item on the scene. Because of this, you should always set the scene rect when operating on large scenes.

One of QGraphicsScene's greatest strengths is its ability to efficiently determine the location of items. Even with millions of items on the scene, the items() functions can determine the location of an item within few milliseconds. There are several overloads to items(): one that finds items at a certain position, one that finds items inside or intersecting with a polygon or a rectangle, and more. The list of returned items is sorted by stacking order, with the topmost item being the first item in the list. For convenience, there is also an itemAt() function that returns the topmost item at a given position.

QGraphicsScene maintains selection information for the scene. To select items, call setSelectionArea(), and to clear the current selection, call clearSelection(). Call selectedItems() to get the list of all selected items.

Event Handling and Propagation

Another responsibility that QGraphicsScene has, is to propagate events from QGraphicsView. To send an event to a scene, you construct an event that inherits QEvent, and then send it using, for example, QApplication::sendEvent(). event() is responsible for dispatching the event to the individual items. Some common events are handled by convenience event handlers. For example, key press events are handled by keyPressEvent(), and mouse press events are handled by mousePressEvent().

Key events are delivered to the {focus item}. To set the focus item, you can either call setFocusItem(), passing an item that accepts focus, or the item itself can call QGraphicsItem::setFocus(). Call focusItem() to get the current focus item. For compatibility with widgets, the scene also maintains its own focus information. By default, the scene does not have focus, and all key events are discarded. If setFocus() is called, or if an item on the scene gains focus, the scene automatically gains focus. If the scene has focus, hasFocus() will return true, and key events will be forwarded to the focus item, if any. If the scene loses focus, (i.e., someone calls clearFocus()) while an item has focus, the scene will maintain its item focus information, and once the scene regains focus, it will make sure the last focus item regains focus.

For mouse-over effects, QGraphicsScene dispatches {hover events}. If an item accepts hover events (see QGraphicsItem::acceptHoverEvents()), it will receive a QEvent::GraphicsSceneHoverEnter event when the mouse enters its area. As the mouse continues moving inside the item's area, QGraphicsScene will send it QEvent::GraphicsSceneHoverMove events. When the mouse leaves the item's area, the item will receive a QEvent::GraphicsSceneHoverLeave event.

All mouse events are delivered to the current {mouse grabber} item. An item becomes the scene's mouse grabber if it accepts mouse events (see QGraphicsItem::acceptedMouseButtons()) and it receives a mouse press. It stays the mouse grabber until it receives a mouse release when no other mouse buttons are pressed. You can call mouseGrabberItem() to determine what item is currently grabbing the mouse.

See also
QGraphicsItem, QGraphicsView

Definition at line 101 of file qgraphicsscene.h.

Enumerations

◆ ItemIndexMethod

This enum describes the indexing algorithms QGraphicsScene provides for managing positional information about items on the scene.

  • BspTreeIndex A Binary Space Partitioning tree is applied. All QGraphicsScene's item location algorithms are of an order close to logarithmic complexity, by making use of binary search. Adding, moving and removing items is logarithmic. This approach is best for static scenes (i.e., scenes where most items do not move).
  • NoIndex No index is applied. Item location is of linear complexity, as all items on the scene are searched. Adding, moving and removing items, however, is done in constant time. This approach is ideal for dynamic scenes, where many items are added, moved or removed continuously.
See also
setItemIndexMethod(), bspTreeDepth
Enumerator
BspTreeIndex 
NoIndex 

Definition at line 115 of file qgraphicsscene.h.

◆ SceneLayer

This enum describes the rendering layers in a QGraphicsScene.

Since
4.3

When QGraphicsScene draws the scene contents, it renders each of these layers separately, in order.

Each layer represents a flag that can be OR'ed together when calling functions such as invalidate() or QGraphicsView::invalidateScene().

  • ItemLayer The item layer. QGraphicsScene renders all items are in this layer by calling the virtual function drawItems(). The item layer is drawn after the background layer, but before the foreground layer.
  • BackgroundLayer The background layer. QGraphicsScene renders the scene's background in this layer by calling the virtual function drawBackground(). The background layer is drawn first of all layers.
  • ForegroundLayer The foreground layer. QGraphicsScene renders the scene's foreground in this layer by calling the virtual function drawForeground(). The foreground layer is drawn last of all layers.
  • AllLayers All layers; this value represents a combination of all three layers.
See also
invalidate(), QGraphicsView::invalidateScene()
Enumerator
ItemLayer 
BackgroundLayer 
ForegroundLayer 
AllLayers 

Definition at line 120 of file qgraphicsscene.h.

Constructors and Destructors

◆ QGraphicsScene() [1/3]

QGraphicsScene::QGraphicsScene ( QObject parent = 0)

Constructs a QGraphicsScene object.

The parent parameter is passed to QObject's constructor.

Definition at line 1638 of file qgraphicsscene.cpp.

1639  : QObject(*new QGraphicsScenePrivate, parent)
1640 {
1641  d_func()->init();
1642 }
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ QGraphicsScene() [2/3]

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

Definition at line 1651 of file qgraphicsscene.cpp.

1652  : QObject(*new QGraphicsScenePrivate, parent)
1653 {
1654  d_func()->init();
1655  setSceneRect(sceneRect);
1656 }
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
void setSceneRect(const QRectF &rect)

◆ QGraphicsScene() [3/3]

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

Definition at line 1666 of file qgraphicsscene.cpp.

1667  : QObject(*new QGraphicsScenePrivate, parent)
1668 {
1669  d_func()->init();
1670  setSceneRect(x, y, width, height);
1671 }
qreal height() const
This convenience function is equivalent to calling sceneRect().
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
void setSceneRect(const QRectF &rect)
qreal width() const
This convenience function is equivalent to calling sceneRect().

◆ ~QGraphicsScene()

QGraphicsScene::~QGraphicsScene ( )
virtual

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.

Definition at line 1679 of file qgraphicsscene.cpp.

1680 {
1682 
1683  // Remove this scene from qApp's global scene list.
1685  qApp->d_func()->scene_list.removeAll(this);
1686 
1687  clear();
1688 
1689  // Remove this scene from all associated views.
1690  for (int j = 0; j < d->views.size(); ++j)
1691  d->views.at(j)->setScene(0);
1692 }
double d
Definition: qnumeric_p.h:62
void clear()
Removes and deletes all items from the scene, but otherwise leaves the state of the scene unchanged...
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482
#define qApp

Functions

◆ activePanel()

QGraphicsItem * QGraphicsScene::activePanel ( ) const

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

Since
4.6
See also
QGraphicsScene::setActivePanel()

Definition at line 5818 of file qgraphicsscene.cpp.

Referenced by QGraphicsItem::hasFocus(), and QGraphicsItem::isActive().

5819 {
5820  Q_D(const QGraphicsScene);
5821  return d->activePanel;
5822 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ activeWindow()

QGraphicsWidget * QGraphicsScene::activeWindow ( ) const

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

Since
4.4
See also
QGraphicsScene::setActiveWindow()

Definition at line 5855 of file qgraphicsscene.cpp.

Referenced by QShortcutMap::correctGraphicsWidgetContext().

5856 {
5857  Q_D(const QGraphicsScene);
5858  if (d->activePanel && d->activePanel->isWindow())
5859  return static_cast<QGraphicsWidget *>(d->activePanel);
5860  return 0;
5861 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ addEllipse() [1/2]

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(), addWidget()

Definition at line 2833 of file qgraphicsscene.cpp.

2834 {
2835  QGraphicsEllipseItem *item = new QGraphicsEllipseItem(rect);
2836  item->setPen(pen);
2837  item->setBrush(brush);
2838  addItem(item);
2839  return item;
2840 }
The QGraphicsEllipseItem class provides an ellipse item that you can add to a QGraphicsScene.
void addItem(QGraphicsItem *item)
Adds or moves the item and all its childen to this scene.
void setPen(const QPen &pen)
Sets the pen for this item to pen.
void setBrush(const QBrush &brush)
Sets the item&#39;s brush to brush.

◆ addEllipse() [2/2]

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

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

Definition at line 203 of file qgraphicsscene.h.

204  { return addEllipse(QRectF(x, y, w, h), pen, brush); }
QGraphicsEllipseItem * addEllipse(const QRectF &rect, const QPen &pen=QPen(), const QBrush &brush=QBrush())
Creates and adds an ellipse item to the scene, and returns the item pointer.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ addItem()

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(), {QGraphicsItem::Sorting}{Sorting}

Definition at line 2650 of file qgraphicsscene.cpp.

Referenced by addEllipse(), addItem(), addLine(), addPath(), addPixmap(), addPolygon(), addRect(), addSimpleText(), addText(), QGraphicsItem::addToIndex(), addWidget(), createItemGroup(), QmlJSDebugger::LiveLayerItem::LiveLayerItem(), QGraphicsItem::QGraphicsItem(), removeItem(), and QDeclarativeView::setRootObject().

2651 {
2653  if (!item) {
2654  qWarning("QGraphicsScene::addItem: cannot add null item");
2655  return;
2656  }
2657  if (item->d_ptr->scene == this) {
2658  qWarning("QGraphicsScene::addItem: item has already been added to this scene");
2659  return;
2660  }
2661  // Remove this item from its existing scene
2662  if (QGraphicsScene *oldScene = item->d_ptr->scene)
2663  oldScene->removeItem(item);
2664 
2665  // Notify the item that its scene is changing, and allow the item to
2666  // react.
2667  const QVariant newSceneVariant(item->itemChange(QGraphicsItem::ItemSceneChange,
2668  QVariant::fromValue<QGraphicsScene *>(this)));
2669  QGraphicsScene *targetScene = qvariant_cast<QGraphicsScene *>(newSceneVariant);
2670  if (targetScene != this) {
2671  if (targetScene && item->d_ptr->scene != targetScene)
2672  targetScene->addItem(item);
2673  return;
2674  }
2675 
2676  // QDeclarativeItems do not rely on initial itemChanged message, as the componentComplete
2677  // function allows far more opportunity for delayed-construction optimization.
2678  if (!item->d_ptr->isDeclarativeItem) {
2679  if (d->unpolishedItems.isEmpty()) {
2680  QMetaMethod method = metaObject()->method(d->polishItemsIndex);
2681  method.invoke(this, Qt::QueuedConnection);
2682  }
2683  d->unpolishedItems.append(item);
2684  item->d_ptr->pendingPolish = true;
2685  }
2686 
2687  // Detach this item from its parent if the parent's scene is different
2688  // from this scene.
2689  if (QGraphicsItem *itemParent = item->d_ptr->parent) {
2690  if (itemParent->d_ptr->scene != this)
2691  item->setParentItem(0);
2692  }
2693 
2694  // Add the item to this scene
2695  item->d_func()->scene = targetScene;
2696 
2697  // Add the item in the index
2698  d->index->addItem(item);
2699 
2700  // Add to list of toplevels if this item is a toplevel.
2701  if (!item->d_ptr->parent)
2702  d->registerTopLevelItem(item);
2703 
2704  // Add to list of items that require an update. We cannot assume that the
2705  // item is fully constructed, so calling item->update() can lead to a pure
2706  // virtual function call to boundingRect().
2707  d->markDirty(item);
2708  d->dirtyGrowingItemsBoundingRect = true;
2709 
2710  // Disable selectionChanged() for individual items
2711  ++d->selectionChanging;
2712  int oldSelectedItemSize = d->selectedItems.size();
2713 
2714  // Enable mouse tracking if the item accepts hover events or has a cursor set.
2715  if (d->allItemsIgnoreHoverEvents && d->itemAcceptsHoverEvents_helper(item)) {
2716  d->allItemsIgnoreHoverEvents = false;
2717  d->enableMouseTrackingOnViews();
2718  }
2719 #ifndef QT_NO_CURSOR
2720  if (d->allItemsUseDefaultCursor && item->d_ptr->hasCursor) {
2721  d->allItemsUseDefaultCursor = false;
2722  if (d->allItemsIgnoreHoverEvents) // already enabled otherwise
2723  d->enableMouseTrackingOnViews();
2724  }
2725 #endif //QT_NO_CURSOR
2726 
2727  // Enable touch events if the item accepts touch events.
2728  if (d->allItemsIgnoreTouchEvents && item->d_ptr->acceptTouchEvents) {
2729  d->allItemsIgnoreTouchEvents = false;
2730  d->enableTouchEventsOnViews();
2731  }
2732 
2733 #ifndef QT_NO_GESTURES
2734  foreach (Qt::GestureType gesture, item->d_ptr->gestureContext.keys())
2735  d->grabGesture(item, gesture);
2736 #endif
2737 
2738  // Update selection lists
2739  if (item->isSelected())
2740  d->selectedItems << item;
2741  if (item->isWidget() && item->isVisible() && static_cast<QGraphicsWidget *>(item)->windowType() == Qt::Popup)
2742  d->addPopup(static_cast<QGraphicsWidget *>(item));
2743  if (item->isPanel() && item->isVisible() && item->panelModality() != QGraphicsItem::NonModal)
2744  d->enterModal(item);
2745 
2746  // Update creation order focus chain. Make sure to leave the widget's
2747  // internal tab order intact.
2748  if (item->isWidget()) {
2749  QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
2750  if (!d->tabFocusFirst) {
2751  // No first tab focus widget - make this the first tab focus
2752  // widget.
2753  d->tabFocusFirst = widget;
2754  } else if (!widget->parentWidget()) {
2755  // Adding a widget that is not part of a tab focus chain.
2756  QGraphicsWidget *last = d->tabFocusFirst->d_func()->focusPrev;
2757  QGraphicsWidget *lastNew = widget->d_func()->focusPrev;
2758  last->d_func()->focusNext = widget;
2759  widget->d_func()->focusPrev = last;
2760  d->tabFocusFirst->d_func()->focusPrev = lastNew;
2761  lastNew->d_func()->focusNext = d->tabFocusFirst;
2762  }
2763  }
2764 
2765  // Add all children recursively
2766  item->d_ptr->ensureSortedChildren();
2767  for (int i = 0; i < item->d_ptr->children.size(); ++i)
2768  addItem(item->d_ptr->children.at(i));
2769 
2770  // Resolve font and palette.
2771  item->d_ptr->resolveFont(d->font.resolve());
2772  item->d_ptr->resolvePalette(d->palette.resolve());
2773 
2774 
2775  // Reenable selectionChanged() for individual items
2776  --d->selectionChanging;
2777  if (!d->selectionChanging && d->selectedItems.size() != oldSelectedItemSize)
2779 
2780  // Deliver post-change notification
2781  item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant);
2782 
2783  // Update explicit activation
2784  bool autoActivate = true;
2785  if (!d->childExplicitActivation && item->d_ptr->explicitActivate)
2786  d->childExplicitActivation = item->d_ptr->wantsActive ? 1 : 2;
2787  if (d->childExplicitActivation && item->isPanel()) {
2788  if (d->childExplicitActivation == 1)
2789  setActivePanel(item);
2790  else
2791  autoActivate = false;
2792  d->childExplicitActivation = 0;
2793  } else if (!item->d_ptr->parent) {
2794  d->childExplicitActivation = 0;
2795  }
2796 
2797  // Auto-activate this item's panel if nothing else has been activated
2798  if (autoActivate) {
2799  if (!d->lastActivePanel && !d->activePanel && item->isPanel()) {
2800  if (isActive())
2801  setActivePanel(item);
2802  else
2803  d->lastActivePanel = item;
2804  }
2805  }
2806 
2808  d->registerScenePosItem(item);
2809 
2810  // Ensure that newly added items that have subfocus set, gain
2811  // focus automatically if there isn't a focus item already.
2812  if (!d->focusItem && item != d->lastFocusItem && item->focusItem() == item)
2813  item->focusItem()->setFocus();
2814 
2815  d->updateInputMethodSensitivityInViews();
2816 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
QGraphicsItem * parent
QGraphicsItem * focusItem() const
If this item, a child or descendant of this item currently has input focus, this function will return...
QGraphicsWidget * parentWidget() const
Returns a pointer to the item&#39;s parent widget.
QPointer< QWidget > widget
QScopedPointer< QGraphicsItemPrivate > d_ptr
void setParentItem(QGraphicsItem *parent)
Sets this item&#39;s parent item to newParent.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
This virtual function is called by QGraphicsItem to notify custom items that some part of the item&#39;s ...
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
QGraphicsScene * scene
void addItem(QGraphicsItem *item)
Adds or moves the item and all its childen to this scene.
PanelModality panelModality() const
Returns the modality for this item.
bool isSelected() const
Returns true if this item is selected; otherwise, false is returned.
#define Q_D(Class)
Definition: qglobal.h:2482
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
Q_CORE_EXPORT void qWarning(const char *,...)
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
Definition: qmap.h:818
virtual void resolvePalette(uint inheritedMask)
GestureType
Definition: qnamespace.h:1759
QMap< Qt::GestureType, Qt::GestureFlags > gestureContext
bool isActive() const
Returns true if the scene is active (e.
void setActivePanel(QGraphicsItem *item)
Activates item, which must be an item in this scene.
void selectionChanged()
This signal is emitted by QGraphicsScene whenever the selection changes.
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
if(void) toggleToolbarShown
bool isWidget() const
Returns true if this item is a widget (i.
virtual void resolveFont(uint inheritedMask)
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
QList< QGraphicsItem * > children
bool invoke(QObject *object, Qt::ConnectionType connectionType, QGenericReturnArgument returnValue, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
Invokes this method on the object object.
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
void setFocus(Qt::FocusReason focusReason=Qt::OtherFocusReason)
Gives keyboard input focus to this item.

◆ addLine() [1/2]

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(), addWidget()

Definition at line 2865 of file qgraphicsscene.cpp.

2866 {
2867  QGraphicsLineItem *item = new QGraphicsLineItem(line);
2868  item->setPen(pen);
2869  addItem(item);
2870  return item;
2871 }
void setPen(const QPen &pen)
Sets the item&#39;s pen to pen.
void addItem(QGraphicsItem *item)
Adds or moves the item and all its childen to this scene.
The QGraphicsLineItem class provides a line item that you can add to a QGraphicsScene.

◆ addLine() [2/2]

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

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

Definition at line 205 of file qgraphicsscene.h.

206  { return addLine(QLineF(x1, y1, x2, y2), pen); }
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
QGraphicsLineItem * addLine(const QLineF &line, const QPen &pen=QPen())
Creates and adds a line item to the scene, and returns the item pointer.

◆ addPath()

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(), addWidget()

Definition at line 2896 of file qgraphicsscene.cpp.

2897 {
2898  QGraphicsPathItem *item = new QGraphicsPathItem(path);
2899  item->setPen(pen);
2900  item->setBrush(brush);
2901  addItem(item);
2902  return item;
2903 }
void addItem(QGraphicsItem *item)
Adds or moves the item and all its childen to this scene.
void setPen(const QPen &pen)
Sets the pen for this item to pen.
void setBrush(const QBrush &brush)
Sets the item&#39;s brush to brush.
The QGraphicsPathItem class provides a path item that you can add to a QGraphicsScene.

◆ addPixmap()

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(), addWidget()

Definition at line 2919 of file qgraphicsscene.cpp.

2920 {
2921  QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
2922  addItem(item);
2923  return item;
2924 }
void addItem(QGraphicsItem *item)
Adds or moves the item and all its childen to this scene.
The QGraphicsPixmapItem class provides a pixmap item that you can add to a QGraphicsScene.

◆ addPolygon()

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(), addWidget()

Definition at line 2941 of file qgraphicsscene.cpp.

2943 {
2944  QGraphicsPolygonItem *item = new QGraphicsPolygonItem(polygon);
2945  item->setPen(pen);
2946  item->setBrush(brush);
2947  addItem(item);
2948  return item;
2949 }
void addItem(QGraphicsItem *item)
Adds or moves the item and all its childen to this scene.
The QGraphicsPolygonItem class provides a polygon item that you can add to a QGraphicsScene.
void setPen(const QPen &pen)
Sets the pen for this item to pen.
void setBrush(const QBrush &brush)
Sets the item&#39;s brush to brush.

◆ addRect() [1/2]

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(), addWidget()

Definition at line 2968 of file qgraphicsscene.cpp.

2969 {
2970  QGraphicsRectItem *item = new QGraphicsRectItem(rect);
2971  item->setPen(pen);
2972  item->setBrush(brush);
2973  addItem(item);
2974  return item;
2975 }
The QGraphicsRectItem class provides a rectangle item that you can add to a QGraphicsScene.
void addItem(QGraphicsItem *item)
Adds or moves the item and all its childen to this scene.
void setPen(const QPen &pen)
Sets the pen for this item to pen.
void setBrush(const QBrush &brush)
Sets the item&#39;s brush to brush.

◆ addRect() [2/2]

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

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

Definition at line 207 of file qgraphicsscene.h.

208  { return addRect(QRectF(x, y, w, h), pen, brush); }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QGraphicsRectItem * 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.

◆ addSimpleText()

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(), addWidget()

Definition at line 3021 of file qgraphicsscene.cpp.

3022 {
3024  item->setFont(font);
3025  addItem(item);
3026  return item;
3027 }
void setFont(const QFont &font)
Sets the font that is used to draw the item&#39;s text to font.
void addItem(QGraphicsItem *item)
Adds or moves the item and all its childen to this scene.
The QGraphicsSimpleTextItem class provides a simple text path item that you can add to a QGraphicsSce...

◆ addText()

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(), addWidget()

Definition at line 2999 of file qgraphicsscene.cpp.

3000 {
3001  QGraphicsTextItem *item = new QGraphicsTextItem(text);
3002  item->setFont(font);
3003  addItem(item);
3004  return item;
3005 }
void setFont(const QFont &font)
Sets the font used to render the text item to font.
void addItem(QGraphicsItem *item)
Adds or moves the item and all its childen to this scene.
The QGraphicsTextItem class provides a text item that you can add to a QGraphicsScene to display form...

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

Definition at line 3047 of file qgraphicsscene.cpp.

3048 {
3049  QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(0, wFlags);
3050  proxy->setWidget(widget);
3051  addItem(proxy);
3052  return proxy;
3053 }
void setWidget(QWidget *widget)
Embeds widget into this proxy widget.
void addItem(QGraphicsItem *item)
Adds or moves the item and all its childen to this scene.
The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene...

◆ advance

void QGraphicsScene::advance ( )
slot

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, QTimeLine

Definition at line 3461 of file qgraphicsscene.cpp.

3462 {
3463  for (int i = 0; i < 2; ++i) {
3464  foreach (QGraphicsItem *item, items())
3465  item->advance(i);
3466  }
3467 }
virtual void advance(int phase)
This virtual function is called twice for all items by the QGraphicsScene::advance() slot...
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QList< QGraphicsItem * > items() const
Returns a list of all items in the scene in descending stacking order.

◆ backgroundBrush()

QBrush QGraphicsScene::backgroundBrush ( ) const

Referenced by drawBackground(), and mouseGrabberItem().

◆ bspTreeDepth()

int QGraphicsScene::bspTreeDepth ( ) const

Referenced by setItemIndexMethod().

◆ changed

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

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

Referenced by clearSelection(), and setSelectionArea().

◆ clear

void QGraphicsScene::clear ( )
slot

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

Since
4.4
See also
addItem()

Definition at line 2538 of file qgraphicsscene.cpp.

Referenced by QGraphicsItem::mouseReleaseEvent(), and ~QGraphicsScene().

2539 {
2541  // NB! We have to clear the index before deleting items; otherwise the
2542  // index might try to access dangling item pointers.
2543  d->index->clear();
2544  // NB! QGraphicsScenePrivate::unregisterTopLevelItem() removes items
2545  while (!d->topLevelItems.isEmpty())
2546  delete d->topLevelItems.first();
2547  Q_ASSERT(d->topLevelItems.isEmpty());
2548  d->lastItemCount = 0;
2549  d->allItemsIgnoreHoverEvents = true;
2550  d->allItemsUseDefaultCursor = true;
2551  d->allItemsIgnoreTouchEvents = true;
2552 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482

◆ clearFocus()

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(), setFocusItem()

Definition at line 3178 of file qgraphicsscene.cpp.

3179 {
3181  if (d->hasFocus) {
3182  d->hasFocus = false;
3183  d->passiveFocusItem = d->focusItem;
3185  }
3186 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482
void setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReason=Qt::OtherFocusReason)
Sets the scene&#39;s focus item to item, with the focus reason focusReason, after removing focus from any...

◆ clearSelection

void QGraphicsScene::clearSelection ( )
slot

Clears the current selection.

See also
setSelectionArea(), selectedItems()

Definition at line 2508 of file qgraphicsscene.cpp.

Referenced by QGraphicsItem::mousePressEvent(), and QGraphicsItem::mouseReleaseEvent().

2509 {
2511 
2512  // Disable emitting selectionChanged
2513  ++d->selectionChanging;
2514  bool changed = !d->selectedItems.isEmpty();
2515 
2516  foreach (QGraphicsItem *item, d->selectedItems)
2517  item->setSelected(false);
2518  d->selectedItems.clear();
2519 
2520  // Reenable emitting selectionChanged() for individual items.
2521  --d->selectionChanging;
2522 
2523  if (!d->selectionChanging && changed)
2525 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
void setSelected(bool selected)
If selected is true and this item is selectable, this item is selected; otherwise, it is unselected.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_D(Class)
Definition: qglobal.h:2482
#define emit
Definition: qobjectdefs.h:76
void changed(const QList< QRectF > &region)
This signal is emitted by QGraphicsScene when control reaches the event loop, if the scene content ch...
void selectionChanged()
This signal is emitted by QGraphicsScene whenever the selection changes.

◆ collidingItems()

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(), {QGraphicsItem::Sorting}{Sorting}

Definition at line 2255 of file qgraphicsscene.cpp.

Referenced by QGraphicsItem::collidingItems().

2257 {
2258  Q_D(const QGraphicsScene);
2259  if (!item) {
2260  qWarning("QGraphicsScene::collidingItems: cannot find collisions for null item");
2261  return QList<QGraphicsItem *>();
2262  }
2263 
2264  // Does not support ItemIgnoresTransformations.
2266  foreach (QGraphicsItem *itemInVicinity, d->index->estimateItems(item->sceneBoundingRect(), Qt::DescendingOrder)) {
2267  if (item != itemInVicinity && item->collidesWithItem(itemInVicinity, mode))
2268  tmp << itemInVicinity;
2269  }
2270  return tmp;
2271 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_D(Class)
Definition: qglobal.h:2482
virtual bool collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
Returns true if this item collides with other; otherwise returns false.
Q_CORE_EXPORT void qWarning(const char *,...)
QRectF sceneBoundingRect() const
Returns the bounding rect of this item in scene coordinates, by combining sceneTransform() with bound...
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ contextMenuEvent()

void QGraphicsScene::contextMenuEvent ( QGraphicsSceneContextMenuEvent contextMenuEvent)
protectedvirtual

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

Definition at line 3722 of file qgraphicsscene.cpp.

Referenced by event().

3723 {
3725  // Ignore by default.
3726  contextMenuEvent->ignore();
3727 
3728  // Send the event to all items at this position until one item accepts the
3729  // event.
3730  foreach (QGraphicsItem *item, d->itemsAtPosition(contextMenuEvent->screenPos(),
3731  contextMenuEvent->scenePos(),
3732  contextMenuEvent->widget())) {
3733  contextMenuEvent->setPos(item->d_ptr->genericMapFromScene(contextMenuEvent->scenePos(),
3734  contextMenuEvent->widget()));
3735  contextMenuEvent->accept();
3736  if (!d->sendEvent(item, contextMenuEvent))
3737  break;
3738 
3739  if (contextMenuEvent->isAccepted())
3740  break;
3741  }
3742 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QPointF genericMapFromScene(const QPointF &pos, const QWidget *viewport) const
Maps the point pos from scene to item coordinates.
QPointF scenePos() const
Returns the position of the mouse cursor in scene coordinates at the moment the the context menu was ...
QWidget * widget() const
Returns the widget where the event originated, or 0 if the event originates from another application...
#define Q_D(Class)
Definition: qglobal.h:2482
void setPos(const QPointF &pos)
Sets the position associated with the context menu to the given point in item coordinates.
bool isAccepted() const
Definition: qcoreevent.h:307
QPoint screenPos() const
Returns the position of the mouse cursor in screen coordinates at the moment the the context menu was...
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309

◆ createItemGroup()

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(), QGraphicsItemGroup::addToGroup()

Definition at line 2567 of file qgraphicsscene.cpp.

2568 {
2569  // Build a list of the first item's ancestors
2570  QList<QGraphicsItem *> ancestors;
2571  int n = 0;
2572  if (!items.isEmpty()) {
2573  QGraphicsItem *parent = items.at(n++);
2574  while ((parent = parent->parentItem()))
2575  ancestors.append(parent);
2576  }
2577 
2578  // Find the common ancestor for all items
2579  QGraphicsItem *commonAncestor = 0;
2580  if (!ancestors.isEmpty()) {
2581  while (n < items.size()) {
2582  int commonIndex = -1;
2583  QGraphicsItem *parent = items.at(n++);
2584  do {
2585  int index = ancestors.indexOf(parent, qMax(0, commonIndex));
2586  if (index != -1) {
2587  commonIndex = index;
2588  break;
2589  }
2590  } while ((parent = parent->parentItem()));
2591 
2592  if (commonIndex == -1) {
2593  commonAncestor = 0;
2594  break;
2595  }
2596 
2597  commonAncestor = ancestors.at(commonIndex);
2598  }
2599  }
2600 
2601  // Create a new group at that level
2602  QGraphicsItemGroup *group = new QGraphicsItemGroup(commonAncestor);
2603  if (!commonAncestor)
2604  addItem(group);
2605  foreach (QGraphicsItem *item, items)
2606  group->addToGroup(item);
2607  return group;
2608 }
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
void addItem(QGraphicsItem *item)
Adds or moves the item and all its childen to this scene.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void addToGroup(QGraphicsItem *item)
Adds the given item and item&#39;s child items to this item group.
The QGraphicsItemGroup class provides a container that treats a group of items as a single item...
quint16 index
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ destroyItemGroup()

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(), QGraphicsItemGroup::removeFromGroup()

Definition at line 2617 of file qgraphicsscene.cpp.

2618 {
2619  foreach (QGraphicsItem *item, group->children())
2620  group->removeFromGroup(item);
2621  removeItem(group);
2622  delete group;
2623 }
void removeFromGroup(QGraphicsItem *item)
Removes the specified item from this group.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
void removeItem(QGraphicsItem *item)
Removes the item item and all its children from the scene.
QList< QGraphicsItem * > children() const
Use childItems() instead.

◆ dragEnterEvent()

void QGraphicsScene::dragEnterEvent ( QGraphicsSceneDragDropEvent event)
protectedvirtual

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(), dropEvent()

Definition at line 3754 of file qgraphicsscene.cpp.

Referenced by event().

3755 {
3757  d->dragDropItem = 0;
3758  d->lastDropAction = Qt::IgnoreAction;
3759  event->accept();
3760 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ dragLeaveEvent()

void QGraphicsScene::dragLeaveEvent ( QGraphicsSceneDragDropEvent event)
protectedvirtual

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(), dropEvent()

Definition at line 3852 of file qgraphicsscene.cpp.

Referenced by event().

3853 {
3855  if (d->dragDropItem) {
3856  // Leave the last drag drop item
3857  d->sendDragDropEvent(d->dragDropItem, event);
3858  d->dragDropItem = 0;
3859  }
3860 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ dragMoveEvent()

void QGraphicsScene::dragMoveEvent ( QGraphicsSceneDragDropEvent event)
protectedvirtual

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(), dropEvent()

Definition at line 3769 of file qgraphicsscene.cpp.

Referenced by event().

3770 {
3772  event->ignore();
3773 
3774  if (!d->mouseGrabberItems.isEmpty()) {
3775  // Mouse grabbers that start drag events lose the mouse grab.
3776  d->clearMouseGrabber();
3777  d->mouseGrabberButtonDownPos.clear();
3778  d->mouseGrabberButtonDownScenePos.clear();
3779  d->mouseGrabberButtonDownScreenPos.clear();
3780  }
3781 
3782  bool eventDelivered = false;
3783 
3784  // Find the topmost enabled items under the cursor. They are all
3785  // candidates for accepting drag & drop events.
3786  foreach (QGraphicsItem *item, d->itemsAtPosition(event->screenPos(),
3787  event->scenePos(),
3788  event->widget())) {
3789  if (!item->isEnabled() || !item->acceptDrops())
3790  continue;
3791 
3792  if (item != d->dragDropItem) {
3793  // Enter the new drag drop item. If it accepts the event, we send
3794  // the leave to the parent item.
3796  d->cloneDragDropEvent(&dragEnter, event);
3797  dragEnter.setDropAction(event->proposedAction());
3798  d->sendDragDropEvent(item, &dragEnter);
3799  event->setAccepted(dragEnter.isAccepted());
3800  event->setDropAction(dragEnter.dropAction());
3801  if (!event->isAccepted()) {
3802  // Propagate to the item under
3803  continue;
3804  }
3805 
3806  d->lastDropAction = event->dropAction();
3807 
3808  if (d->dragDropItem) {
3809  // Leave the last drag drop item. A perfect implementation
3810  // would set the position of this event to the point where
3811  // this event and the last event intersect with the item's
3812  // shape, but that's not easy to do. :-)
3814  d->cloneDragDropEvent(&dragLeave, event);
3815  d->sendDragDropEvent(d->dragDropItem, &dragLeave);
3816  }
3817 
3818  // We've got a new drag & drop item
3819  d->dragDropItem = item;
3820  }
3821 
3822  // Send the move event.
3823  event->setDropAction(d->lastDropAction);
3824  event->accept();
3825  d->sendDragDropEvent(item, event);
3826  if (event->isAccepted())
3827  d->lastDropAction = event->dropAction();
3828  eventDelivered = true;
3829  break;
3830  }
3831 
3832  if (!eventDelivered) {
3833  if (d->dragDropItem) {
3834  // Leave the last drag drop item
3836  d->cloneDragDropEvent(&dragLeave, event);
3837  d->sendDragDropEvent(d->dragDropItem, &dragLeave);
3838  d->dragDropItem = 0;
3839  }
3840  // Propagate
3841  event->setDropAction(Qt::IgnoreAction);
3842  }
3843 }
Qt::DropAction dropAction() const
Returns the action that was performed in this drag and drop.
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
bool acceptDrops() const
Returns true if this item can accept drag and drop events; otherwise, returns false.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
bool isEnabled() const
Returns true if the item is enabled; otherwise, false is returned.
#define Q_D(Class)
Definition: qglobal.h:2482
bool isAccepted() const
Definition: qcoreevent.h:307
QPoint screenPos() const
Returns the position of the mouse relative to the screen.
Qt::DropAction proposedAction() const
Returns the drop action that is proposed, i.e., preferred.
The QGraphicsSceneDragDropEvent class provides events for drag and drop in the graphics view framewor...

◆ drawBackground()

void QGraphicsScene::drawBackground ( QPainter painter,
const QRectF rect 
)
protectedvirtual

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(), drawItems()

Definition at line 4381 of file qgraphicsscene.cpp.

Referenced by render().

4382 {
4384 
4385  if (d->backgroundBrush.style() != Qt::NoBrush) {
4386  if (d->painterStateProtection)
4387  painter->save();
4388  painter->setBrushOrigin(0, 0);
4389  painter->fillRect(rect, backgroundBrush());
4390  if (d->painterStateProtection)
4391  painter->restore();
4392  }
4393 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
#define Q_D(Class)
Definition: qglobal.h:2482
void setBrushOrigin(int x, int y)
Sets the brush&#39;s origin to point (x, y).
Definition: qpainter.h:825
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
QBrush backgroundBrush() const
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ drawForeground()

void QGraphicsScene::drawForeground ( QPainter painter,
const QRectF rect 
)
protectedvirtual

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(), drawItems()

Definition at line 4408 of file qgraphicsscene.cpp.

Referenced by render().

4409 {
4411 
4412  if (d->foregroundBrush.style() != Qt::NoBrush) {
4413  if (d->painterStateProtection)
4414  painter->save();
4415  painter->setBrushOrigin(0, 0);
4416  painter->fillRect(rect, foregroundBrush());
4417  if (d->painterStateProtection)
4418  painter->restore();
4419  }
4420 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
#define Q_D(Class)
Definition: qglobal.h:2482
void setBrushOrigin(int x, int y)
Sets the brush&#39;s origin to point (x, y).
Definition: qpainter.h:825
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
QBrush foregroundBrush() const
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ drawItems()

void QGraphicsScene::drawItems ( QPainter painter,
int  numItems,
QGraphicsItem items[],
const QStyleOptionGraphicsItem  options[],
QWidget widget = 0 
)
protectedvirtual

Paints the given items using the provided painter, after the background has been drawn, and before the foreground has been drawn.

All painting is done in scene coordinates. Before drawing each item, the painter must be transformed using QGraphicsItem::sceneTransform().

The options parameter is the list of style option objects for each item in items. The numItems parameter is the number of items in items and options in options. The widget parameter is optional; if specified, it should point to the widget that is being painted on.

The default implementation prepares the painter matrix, and calls QGraphicsItem::paint() on all items. Reimplement this function to provide custom painting of all items for the scene; gaining complete control over how each item is drawn. In some cases this can increase drawing performance significantly.

Example:

void CustomScene::drawItems(QPainter *painter, int numItems,
const QStyleOptionGraphicsItem options[],
{
for (int i = 0; i < numItems; ++i) {
// Draw the item
painter->save();
painter->setMatrix(items[i]->sceneMatrix(), true);
items[i]->paint(painter, &options[i], widget);
painter->restore();
}
}

Since Qt 4.6, this function is not called anymore unless the QGraphicsView::IndirectPainting flag is given as an Optimization flag.

See also
drawBackground(), drawForeground()

Definition at line 5483 of file qgraphicsscene.cpp.

Referenced by render().

5487 {
5489  // Make sure we don't have unpolished items before we draw.
5490  if (!d->unpolishedItems.isEmpty())
5491  d->_q_polishItems();
5492 
5493  const qreal opacity = painter->opacity();
5494  QTransform viewTransform = painter->worldTransform();
5495  Q_UNUSED(options);
5496 
5497  // Determine view, expose and flags.
5498  QGraphicsView *view = widget ? qobject_cast<QGraphicsView *>(widget->parentWidget()) : 0;
5499  QRegion *expose = 0;
5500  const quint32 oldRectAdjust = d->rectAdjust;
5501  if (view) {
5502  d->updateAll = false;
5503  expose = &view->d_func()->exposedRegion;
5505  d->rectAdjust = 1;
5506  else
5507  d->rectAdjust = 2;
5508  }
5509 
5510  // Find all toplevels, they are already sorted.
5511  QList<QGraphicsItem *> topLevelItems;
5512  for (int i = 0; i < numItems; ++i) {
5513  QGraphicsItem *item = items[i]->topLevelItem();
5514  if (!item->d_ptr->itemDiscovered) {
5515  topLevelItems << item;
5516  item->d_ptr->itemDiscovered = 1;
5517  d->drawSubtreeRecursive(item, painter, &viewTransform, expose, widget);
5518  }
5519  }
5520 
5521  d->rectAdjust = oldRectAdjust;
5522  // Reset discovery bits.
5523  for (int i = 0; i < topLevelItems.size(); ++i)
5524  topLevelItems.at(i)->d_ptr->itemDiscovered = 0;
5525 
5526  painter->setWorldTransform(viewTransform);
5527  painter->setOpacity(opacity);
5528 }
double d
Definition: qnumeric_p.h:62
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
double qreal
Definition: qglobal.h:1193
qreal opacity() const
Returns the opacity of the painter.
Definition: qpainter.cpp:2115
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_D(Class)
Definition: qglobal.h:2482
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QGraphicsItem * topLevelItem() const
Returns this item&#39;s top-level item.
OptimizationFlags optimizationFlags
flags that can be used to tune QGraphicsView&#39;s performance.
Definition: qgraphicsview.h:83
const QTransform & worldTransform() const
Returns the world transformation matrix.
Definition: qpainter.cpp:9652
unsigned int quint32
Definition: qglobal.h:938
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void setWorldTransform(const QTransform &matrix, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9630
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
void setOpacity(qreal opacity)
Sets the opacity of the painter to opacity.
Definition: qpainter.cpp:2139
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ dropEvent()

void QGraphicsScene::dropEvent ( QGraphicsSceneDragDropEvent event)
protectedvirtual

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

Definition at line 3869 of file qgraphicsscene.cpp.

Referenced by event().

3870 {
3871  Q_UNUSED(event);
3873  if (d->dragDropItem) {
3874  // Drop on the last drag drop item
3875  d->sendDragDropEvent(d->dragDropItem, event);
3876  d->dragDropItem = 0;
3877  }
3878 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ event()

bool QGraphicsScene::event ( QEvent event)
protectedvirtual

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 QWidget::enterEvent() and QWidget::leaveEvent(). Use this function to obtain those events instead.

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

Reimplemented from QObject.

Definition at line 3487 of file qgraphicsscene.cpp.

Referenced by setFocus(), and setStyle().

3488 {
3490 
3491  switch (event->type()) {
3499  case QEvent::TouchBegin:
3500  case QEvent::TouchUpdate:
3501  case QEvent::TouchEnd:
3502  // Reset the under-mouse list to ensure that this event gets fresh
3503  // item-under-mouse data. Be careful about this list; if people delete
3504  // items from inside event handlers, this list can quickly end up
3505  // having stale pointers in it. We need to clear it before dispatching
3506  // events that use it.
3507  // ### this should only be cleared if we received a new mouse move event,
3508  // which relies on us fixing the replay mechanism in QGraphicsView.
3509  d->cachedItemsUnderMouse.clear();
3510  default:
3511  break;
3512  }
3513 
3514  switch (event->type()) {
3516  dragEnterEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));
3517  break;
3519  dragMoveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));
3520  break;
3522  dragLeaveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));
3523  break;
3525  dropEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));
3526  break;
3528  contextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent *>(event));
3529  break;
3530  case QEvent::KeyPress:
3531  if (!d->focusItem) {
3532  QKeyEvent *k = static_cast<QKeyEvent *>(event);
3533  if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) {
3534  if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier?
3535  bool res = false;
3536  if (k->key() == Qt::Key_Backtab
3537  || (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier))) {
3538  res = focusNextPrevChild(false);
3539  } else if (k->key() == Qt::Key_Tab) {
3540  res = focusNextPrevChild(true);
3541  }
3542  if (!res)
3543  event->ignore();
3544  return true;
3545  }
3546  }
3547  }
3548  keyPressEvent(static_cast<QKeyEvent *>(event));
3549  break;
3550  case QEvent::KeyRelease:
3551  keyReleaseEvent(static_cast<QKeyEvent *>(event));
3552  break;
3553  case QEvent::ShortcutOverride: {
3555  while (parent) {
3556  d->sendEvent(parent, event);
3557  if (event->isAccepted())
3558  return true;
3559  parent = parent->parentItem();
3560  }
3561  }
3562  return false;
3564  {
3566  d->lastSceneMousePos = mouseEvent->scenePos();
3567  mouseMoveEvent(mouseEvent);
3568  break;
3569  }
3571  mousePressEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
3572  break;
3574  mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
3575  break;
3577  mouseDoubleClickEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
3578  break;
3580  wheelEvent(static_cast<QGraphicsSceneWheelEvent *>(event));
3581  break;
3582  case QEvent::FocusIn:
3583  focusInEvent(static_cast<QFocusEvent *>(event));
3584  break;
3585  case QEvent::FocusOut:
3586  focusOutEvent(static_cast<QFocusEvent *>(event));
3587  break;
3591  {
3592  QGraphicsSceneHoverEvent *hoverEvent = static_cast<QGraphicsSceneHoverEvent *>(event);
3593  d->lastSceneMousePos = hoverEvent->scenePos();
3594  d->dispatchHoverEvent(hoverEvent);
3595  break;
3596  }
3597  case QEvent::Leave:
3598  // hackieshly unpacking the viewport pointer from the leave event.
3599  d->leaveScene(reinterpret_cast<QWidget *>(event->d));
3600  break;
3602  helpEvent(static_cast<QGraphicsSceneHelpEvent *>(event));
3603  break;
3604  case QEvent::InputMethod:
3605  inputMethodEvent(static_cast<QInputMethodEvent *>(event));
3606  break;
3608  if (!d->activationRefCount++) {
3609  if (d->lastActivePanel) {
3610  // Activate the last panel.
3611  d->setActivePanelHelper(d->lastActivePanel, true);
3612  } else if (d->tabFocusFirst && d->tabFocusFirst->isPanel()) {
3613  // Activate the panel of the first item in the tab focus
3614  // chain.
3615  d->setActivePanelHelper(d->tabFocusFirst, true);
3616  } else {
3617  // Activate all toplevel items.
3619  foreach (QGraphicsItem *item, items()) {
3620  if (item->isVisible() && !item->isPanel() && !item->parentItem())
3621  sendEvent(item, &event);
3622  }
3623  }
3624  }
3625  break;
3627  if (d->activationRefCount > 0)
3628  --d->activationRefCount;
3629  if (!d->activationRefCount) {
3630  if (d->activePanel) {
3631  // Deactivate the active panel (but keep it so we can
3632  // reactivate it later).
3633  QGraphicsItem *lastActivePanel = d->activePanel;
3634  d->setActivePanelHelper(0, true);
3635  d->lastActivePanel = lastActivePanel;
3636  } else {
3637  // Activate all toplevel items.
3639  foreach (QGraphicsItem *item, items()) {
3640  if (item->isVisible() && !item->isPanel() && !item->parentItem())
3641  sendEvent(item, &event);
3642  }
3643  }
3644  }
3645  break;
3647  // Resolve the existing scene font.
3648  d->resolveFont();
3649  break;
3650  }
3651  case QEvent::FontChange:
3652  // Update the entire scene when the font changes.
3653  update();
3654  break;
3656  // Resolve the existing scene palette.
3657  d->resolvePalette();
3658  break;
3659  }
3660  case QEvent::PaletteChange:
3661  // Update the entire scene when the palette changes.
3662  update();
3663  break;
3664  case QEvent::StyleChange:
3665  // Reresolve all widgets' styles. Update all top-level widgets'
3666  // geometries that do not have an explicit style set.
3667  update();
3668  break;
3669  case QEvent::TouchBegin:
3670  case QEvent::TouchUpdate:
3671  case QEvent::TouchEnd:
3672  d->touchEventHandler(static_cast<QTouchEvent *>(event));
3673  break;
3674 #ifndef QT_NO_GESTURES
3675  case QEvent::Gesture:
3677  d->gestureEventHandler(static_cast<QGestureEvent *>(event));
3678  break;
3679 #endif // QT_NO_GESTURES
3680  default:
3681  return QObject::event(event);
3682  }
3683  return true;
3684 }
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event mouseEvent, can be reimplemented in a subclass to receive mouse release...
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
The QKeyEvent class describes a key event.
Definition: qevent.h:224
virtual void dropEvent(QGraphicsSceneDragDropEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive drop events for th...
virtual void focusInEvent(QFocusEvent *event)
This event handler, for event focusEvent, can be reimplemented in a subclass to receive focus in even...
virtual void helpEvent(QGraphicsSceneHelpEvent *event)
This event handler, for event helpEvent, can be reimplemented in a subclass to receive help events...
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive drag enter events ...
QList< QGraphicsItem * > items() const
Returns a list of all items in the scene in descending stacking order.
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event mouseEvent, can be reimplemented in a subclass to receive mouse press e...
virtual void keyPressEvent(QKeyEvent *event)
This event handler, for event keyEvent, can be reimplemented in a subclass to receive keypress events...
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
bool focusNextPrevChild(bool next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it cannot.
#define Q_D(Class)
Definition: qglobal.h:2482
bool sendEvent(QGraphicsItem *item, QEvent *event)
Sends event event to item item through possible event filters.
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
virtual void keyReleaseEvent(QKeyEvent *event)
This event handler, for event keyEvent, can be reimplemented in a subclass to receive key release eve...
bool isAccepted() const
Definition: qcoreevent.h:307
QGraphicsItem * focusItem() const
When the scene is active, this functions returns the scene&#39;s current focus item, or 0 if no item curr...
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event mouseEvent, can be reimplemented in a subclass to receive mouse move ev...
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event mouseEvent, can be reimplemented in a subclass to receive mouse doublec...
virtual void inputMethodEvent(QInputMethodEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive input method event...
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
This event handler, for event contextMenuEvent, can be reimplemented in a subclass to receive context...
bool event(QEvent *event)
Processes the event event, and dispatches it to the respective event handlers.
void update(qreal x, qreal y, qreal w, qreal h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive drag move events f...
QEventPrivate * d
Definition: qcoreevent.h:315
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
QPointF scenePos() const
Returns the mouse cursor position in scene coordinates.
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
virtual void focusOutEvent(QFocusEvent *event)
This event handler, for event focusEvent, can be reimplemented in a subclass to receive focus out eve...
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71
QPointF scenePos() const
Returns the position of the mouse cursor in scene coordinates at the moment the hover event was sent...
virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive drag leave events ...
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
virtual void wheelEvent(QGraphicsSceneWheelEvent *event)
This event handler, for event wheelEvent, can be reimplemented in a subclass to receive mouse wheel e...
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.

◆ eventFilter()

bool QGraphicsScene::eventFilter ( QObject watched,
QEvent event 
)
protectedvirtual

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

Reimplemented Function

Reimplemented from QObject.

Definition at line 3695 of file qgraphicsscene.cpp.

3696 {
3697  if (watched != qApp)
3698  return false;
3699 
3700  switch (event->type()) {
3703  break;
3706  break;
3707  default:
3708  break;
3709  }
3710  return false;
3711 }
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
#define qApp
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303

◆ focusInEvent()

void QGraphicsScene::focusInEvent ( QFocusEvent focusEvent)
protectedvirtual

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

Definition at line 3889 of file qgraphicsscene.cpp.

Referenced by event().

3890 {
3892 
3893  d->hasFocus = true;
3894  switch (focusEvent->reason()) {
3895  case Qt::TabFocusReason:
3896  if (!focusNextPrevChild(true))
3897  focusEvent->ignore();
3898  break;
3900  if (!focusNextPrevChild(false))
3901  focusEvent->ignore();
3902  break;
3903  default:
3904  if (d->passiveFocusItem) {
3905  // Set focus on the last focus item
3906  setFocusItem(d->passiveFocusItem, focusEvent->reason());
3907  }
3908  break;
3909  }
3910 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
bool focusNextPrevChild(bool next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it cannot.
#define Q_D(Class)
Definition: qglobal.h:2482
void setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReason=Qt::OtherFocusReason)
Sets the scene&#39;s focus item to item, with the focus reason focusReason, after removing focus from any...
Qt::FocusReason reason()
Definition: qevent.cpp:1197
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310

◆ focusItem()

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(), isActive()

Definition at line 3106 of file qgraphicsscene.cpp.

Referenced by QShortcutMap::correctGraphicsWidgetContext(), QMotifStyle::event(), QMacStyle::event(), event(), QUIKitSoftwareInputHandler::eventFilter(), focusNextPrevChild(), QDeclarativeItem::hasActiveFocus(), QGraphicsItem::hasFocus(), keyPressEvent(), keyReleaseEvent(), QGraphicsItemPrivate::setEnabledHelper(), QGraphicsItemPrivate::setFocusHelper(), QGraphicsItemPrivate::setVisibleHelper(), QGraphicsViewPrivate::updateInputMethodSensitivity(), and wheelEvent().

3107 {
3108  Q_D(const QGraphicsScene);
3109  return isActive() ? d->focusItem : d->passiveFocusItem;
3110 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482
bool isActive() const
Returns true if the scene is active (e.

◆ focusNextPrevChild

bool QGraphicsScene::focusNextPrevChild ( bool  next)
protectedslot

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.

Since
4.4

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

Definition at line 5546 of file qgraphicsscene.cpp.

Referenced by event(), focusInEvent(), and QGraphicsItem::sceneEvent().

5547 {
5549 
5550  QGraphicsItem *item = focusItem();
5551  if (item && !item->isWidget()) {
5552  // Tab out of the scene.
5553  return false;
5554  }
5555  if (!item) {
5556  if (d->lastFocusItem && !d->lastFocusItem->isWidget()) {
5557  // Restore focus to the last focusable non-widget item that had
5558  // focus.
5559  setFocusItem(d->lastFocusItem, next ? Qt::TabFocusReason : Qt::BacktabFocusReason);
5560  return true;
5561  }
5562  }
5563  if (!d->tabFocusFirst) {
5564  // No widgets...
5565  return false;
5566  }
5567 
5568  // The item must be a widget.
5569  QGraphicsWidget *widget = 0;
5570  if (!item) {
5571  widget = next ? d->tabFocusFirst : d->tabFocusFirst->d_func()->focusPrev;
5572  } else {
5573  QGraphicsWidget *test = static_cast<QGraphicsWidget *>(item);
5574  widget = next ? test->d_func()->focusNext : test->d_func()->focusPrev;
5575  if ((next && widget == d->tabFocusFirst) || (!next && widget == d->tabFocusFirst->d_func()->focusPrev))
5576  return false;
5577  }
5578  QGraphicsWidget *widgetThatHadFocus = widget;
5579 
5580  // Run around the focus chain until we find a widget that can take tab focus.
5581  do {
5582  if (widget->flags() & QGraphicsItem::ItemIsFocusable
5583  && widget->isEnabled() && widget->isVisibleTo(0)
5584  && (widget->focusPolicy() & Qt::TabFocus)
5585  && (!item || !item->isPanel() || item->isAncestorOf(widget))
5586  ) {
5588  return true;
5589  }
5590  widget = next ? widget->d_func()->focusNext : widget->d_func()->focusPrev;
5591  if ((next && widget == d->tabFocusFirst) || (!next && widget == d->tabFocusFirst->d_func()->focusPrev))
5592  return false;
5593  } while (widget != widgetThatHadFocus);
5594 
5595  return false;
5596 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
QPointer< QWidget > widget
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
bool isEnabled() const
Returns true if the item is enabled; otherwise, false is returned.
#define Q_D(Class)
Definition: qglobal.h:2482
QGraphicsItem * focusItem() const
When the scene is active, this functions returns the scene&#39;s current focus item, or 0 if no item curr...
void setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReason=Qt::OtherFocusReason)
Sets the scene&#39;s focus item to item, with the focus reason focusReason, after removing focus from any...
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
bool isAncestorOf(const QGraphicsItem *child) const
Returns true if this item is an ancestor of child (i.e., if this item is child&#39;s parent, or one of child&#39;s parent&#39;s ancestors).
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
bool isWidget() const
Returns true if this item is a widget (i.
bool isVisibleTo(const QGraphicsItem *parent) const
Returns true if the item is visible to parent; otherwise, false is returned.
Qt::FocusPolicy focusPolicy
the way the widget accepts keyboard focus
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ focusOutEvent()

void QGraphicsScene::focusOutEvent ( QFocusEvent focusEvent)
protectedvirtual

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

Definition at line 3921 of file qgraphicsscene.cpp.

Referenced by event().

3922 {
3924  d->hasFocus = false;
3925  d->passiveFocusItem = d->focusItem;
3926  setFocusItem(0, focusEvent->reason());
3927 
3928  // Remove all popups when the scene loses focus.
3929  if (!d->popupWidgets.isEmpty())
3930  d->removePopup(d->popupWidgets.first());
3931 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482
void setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReason=Qt::OtherFocusReason)
Sets the scene&#39;s focus item to item, with the focus reason focusReason, after removing focus from any...
Qt::FocusReason reason()
Definition: qevent.cpp:1197

◆ font()

QFont QGraphicsScene::font ( ) const

Referenced by setStyle().

◆ foregroundBrush()

QBrush QGraphicsScene::foregroundBrush ( ) const

◆ hasFocus()

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(), setFocusItem()

Definition at line 3144 of file qgraphicsscene.cpp.

Referenced by QDeclarativeTextEditPrivate::focusChanged(), and QDeclarativeTextInputPrivate::focusChanged().

3145 {
3146  Q_D(const QGraphicsScene);
3147  return d->hasFocus;
3148 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ height()

qreal QGraphicsScene::height ( ) const
inline

This convenience function is equivalent to calling sceneRect().

height().

 \sa width()

Definition at line 135 of file qgraphicsscene.h.

135 { return sceneRect().height(); }
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
QRectF sceneRect() const

◆ helpEvent()

void QGraphicsScene::helpEvent ( QGraphicsSceneHelpEvent helpEvent)
protectedvirtual

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(), QGraphicsSceneHelpEvent

Definition at line 3946 of file qgraphicsscene.cpp.

Referenced by event().

3947 {
3948 #ifdef QT_NO_TOOLTIP
3949  Q_UNUSED(helpEvent);
3950 #else
3951  // Find the first item that does tooltips
3953  QList<QGraphicsItem *> itemsAtPos = d->itemsAtPosition(helpEvent->screenPos(),
3954  helpEvent->scenePos(),
3955  helpEvent->widget());
3956  QGraphicsItem *toolTipItem = 0;
3957  for (int i = 0; i < itemsAtPos.size(); ++i) {
3958  QGraphicsItem *tmp = itemsAtPos.at(i);
3959  if (tmp->d_func()->isProxyWidget()) {
3960  // if the item is a proxy widget, the event is forwarded to it
3961  sendEvent(tmp, helpEvent);
3962  if (helpEvent->isAccepted())
3963  return;
3964  }
3965  if (!tmp->toolTip().isEmpty()) {
3966  toolTipItem = tmp;
3967  break;
3968  }
3969  }
3970 
3971  // Show or hide the tooltip
3972  QString text;
3973  QPoint point;
3974  if (toolTipItem && !toolTipItem->toolTip().isEmpty()) {
3975  text = toolTipItem->toolTip();
3976  point = helpEvent->screenPos();
3977  }
3978  QToolTip::showText(point, text, helpEvent->widget());
3979  helpEvent->setAccepted(!text.isEmpty());
3980 #endif
3981 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
QPointF scenePos() const
Returns the position of the mouse cursor in scene coordinates at the moment the help event was sent...
void setAccepted(bool accepted)
Definition: qcoreevent.h:306
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QWidget * widget() const
Returns the widget where the event originated, or 0 if the event originates from another application...
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
bool sendEvent(QGraphicsItem *item, QEvent *event)
Sends event event to item item through possible event filters.
bool isAccepted() const
Definition: qcoreevent.h:307
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QPoint screenPos() const
Returns the position of the mouse cursor in screen coordinates at the moment the help event was sent...
QString toolTip() const
Returns the item&#39;s tool tip, or an empty QString if no tool tip has been set.
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
#define text
Definition: qobjectdefs.h:80
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtooltip.cpp:497

◆ inputMethodEvent()

void QGraphicsScene::inputMethodEvent ( QInputMethodEvent event)
protectedvirtual

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

Definition at line 4361 of file qgraphicsscene.cpp.

Referenced by event().

4362 {
4364  if (d->focusItem && (d->focusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod))
4365  d->sendEvent(d->focusItem, event);
4366 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ inputMethodQuery()

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

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

Definition at line 3329 of file qgraphicsscene.cpp.

3330 {
3331  Q_D(const QGraphicsScene);
3332  if (!d->focusItem || !(d->focusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod))
3333  return QVariant();
3334  const QTransform matrix = d->focusItem->sceneTransform();
3335  QVariant value = d->focusItem->inputMethodQuery(query);
3336  if (value.type() == QVariant::RectF)
3337  value = matrix.mapRect(value.toRectF());
3338  else if (value.type() == QVariant::PointF)
3339  value = matrix.map(value.toPointF());
3340  else if (value.type() == QVariant::Rect)
3341  value = matrix.mapRect(value.toRect());
3342  else if (value.type() == QVariant::Point)
3343  value = matrix.map(value.toPoint());
3344  return value;
3345 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
QPointF toPointF() const
Returns the variant as a QPointF if the variant has type() Point or PointF ; otherwise returns a null...
Definition: qvariant.cpp:2509
QRectF toRectF() const
Returns the variant as a QRectF if the variant has type() Rect or RectF ; otherwise returns an invali...
Definition: qvariant.cpp:2463
#define Q_D(Class)
Definition: qglobal.h:2482
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
QRect toRect() const
Returns the variant as a QRect if the variant has type() Rect ; otherwise returns an invalid QRect...
Definition: qvariant.cpp:2416
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
QPoint toPoint() const
Returns the variant as a QPoint if the variant has type() Point or PointF ; otherwise returns a null ...
Definition: qvariant.cpp:2400
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ invalidate() [1/2]

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

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

Since
4.3

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

Definition at line 234 of file qgraphicsscene.h.

235  { invalidate(QRectF(x, y, w, h), layers); }
void invalidate(qreal x, qreal y, qreal w, qreal h, SceneLayers layers=AllLayers)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ invalidate [2/2]

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

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 the rectangle for the tile at position (x, y).
return QRectF(x * tileWidth, y * tileHeight, tileWidth, tileHeight);
}
void TileScene::setTile(int x, int y, const QPixmap &pixmap)
{
// Sets or replaces the tile at position (x, y) with 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)
{
// Draws all tiles that intersect the exposed area.
for (int y = 0; y < numTilesV; ++y) {
for (int x = 0; x < numTilesH; ++x) {
QRectF 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()

Definition at line 3424 of file qgraphicsscene.cpp.

3425 {
3426  foreach (QGraphicsView *view, views())
3427  view->invalidateScene(rect, layers);
3428  update(rect);
3429 }
void invalidateScene(const QRectF &rect=QRectF(), QGraphicsScene::SceneLayers layers=QGraphicsScene::AllLayers)
Invalidates and schedules a redraw of layers inside rect.
QList< QGraphicsView * > views() const
Returns a list of all the views that display this scene.
void update(qreal x, qreal y, qreal w, qreal h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ isActive()

bool QGraphicsScene::isActive ( ) const

Returns true if the scene is active (e.

Since
4.6

g., it's viewed by at least one QGraphicsView that is active); otherwise returns false.

See also
QGraphicsItem::isActive(), QWidget::isActiveWindow()

Definition at line 5803 of file qgraphicsscene.cpp.

Referenced by addItem(), focusItem(), QGraphicsItem::hasFocus(), QGraphicsItem::isActive(), setFocus(), QGraphicsItemPrivate::setFocusHelper(), and QGraphicsItemPrivate::setSubFocus().

5804 {
5805  Q_D(const QGraphicsScene);
5806  return d->activationRefCount > 0;
5807 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ isSortCacheEnabled()

bool QGraphicsScene::isSortCacheEnabled ( ) const

Definition at line 1964 of file qgraphicsscene.cpp.

1965 {
1966  Q_D(const QGraphicsScene);
1967  return d->sortCacheEnabled;
1968 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ itemAt() [1/4]

QGraphicsItem * QGraphicsScene::itemAt ( const QPointF position) const

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

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

This function is deprecated and returns incorrect results if the scene contains items that ignore transformations. Use the overload that takes a QTransform instead.

See also
items(), collidingItems(), {QGraphicsItem::Sorting}{Sorting}

Definition at line 2289 of file qgraphicsscene.cpp.

2290 {
2291  QList<QGraphicsItem *> itemsAtPoint = items(position);
2292  return itemsAtPoint.isEmpty() ? 0 : itemsAtPoint.first();
2293 }
QList< QGraphicsItem * > items() const
Returns a list of all items in the scene in descending stacking order.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ itemAt() [2/4]

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.

Since
4.6

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

See also
items(), collidingItems(), {QGraphicsItem::Sorting}{Sorting}

Definition at line 2309 of file qgraphicsscene.cpp.

2310 {
2311  QList<QGraphicsItem *> itemsAtPoint = items(position, Qt::IntersectsItemShape,
2312  Qt::DescendingOrder, deviceTransform);
2313  return itemsAtPoint.isEmpty() ? 0 : itemsAtPoint.first();
2314 }
QList< QGraphicsItem * > items() const
Returns a list of all items in the scene in descending stacking order.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ itemAt() [3/4]

QGraphicsScene::itemAt ( qreal  x,
qreal  y 
) const
inline

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

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

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

This function is deprecated and returns incorrect results if the scene contains items that ignore transformations. Use the overload that takes a QTransform instead.

Definition at line 178 of file qgraphicsscene.h.

179  { return itemAt(QPointF(x, y)); }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QGraphicsItem * itemAt(const QPointF &pos) const
Returns the topmost visible item at the specified position, or 0 if there are no items at this positi...

◆ itemAt() [4/4]

QGraphicsScene::itemAt ( qreal  x,
qreal  y,
const QTransform deviceTransform 
) const
inline

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

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

Since
4.6

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

Definition at line 180 of file qgraphicsscene.h.

181  { return itemAt(QPointF(x, y), deviceTransform); }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QGraphicsItem * itemAt(const QPointF &pos) const
Returns the topmost visible item at the specified position, or 0 if there are no items at this positi...

◆ itemIndexMethod()

ItemIndexMethod QGraphicsScene::itemIndexMethod ( ) const

Referenced by render().

◆ items() [1/12]

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

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

See also
addItem(), removeItem(), {QGraphicsItem::Sorting}{Sorting}

Definition at line 1998 of file qgraphicsscene.cpp.

Referenced by advance(), QGraphicsScenePrivate::cancelGesturesForChildren(), QGraphicsScenePrivate::enterModal(), event(), QGraphicsViewPrivate::findItems(), QGraphicsScenePrivate::gestureTargetsAtHotSpots(), itemAt(), itemsBoundingRect(), QGraphicsScenePrivate::leaveModal(), render(), setActiveWindow(), setSelectionArea(), and setStyle().

1999 {
2000  Q_D(const QGraphicsScene);
2001  return d->index->items(Qt::DescendingOrder);
2002 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ items() [2/12]

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(), {QGraphicsItem::Sorting}{Sorting}

Definition at line 2010 of file qgraphicsscene.cpp.

2011 {
2012  Q_D(const QGraphicsScene);
2013  return d->index->items(order);
2014 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ items() [3/12]

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.

Since
4.6

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.

See also
itemAt(), {QGraphicsItem::Sorting}{Sorting}

Definition at line 2155 of file qgraphicsscene.cpp.

2157 {
2158  Q_D(const QGraphicsScene);
2159  return d->index->items(pos, mode, order, deviceTransform);
2160 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ items() [4/12]

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

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

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

Since
4.6

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.

See also
itemAt(), {QGraphicsItem::Sorting}{Sorting}

Definition at line 2182 of file qgraphicsscene.cpp.

2184 {
2185  Q_D(const QGraphicsScene);
2186  return d->index->items(rect, mode, order, deviceTransform);
2187 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ items() [5/12]

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

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

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

Since
4.6

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.

See also
itemAt(), {QGraphicsItem::Sorting}{Sorting}

Definition at line 2209 of file qgraphicsscene.cpp.

2211 {
2212  Q_D(const QGraphicsScene);
2213  return d->index->items(polygon, mode, order, deviceTransform);
2214 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ items() [6/12]

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

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

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

Since
4.6

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.

See also
itemAt(), {QGraphicsItem::Sorting}{Sorting}

Definition at line 2236 of file qgraphicsscene.cpp.

2238 {
2239  Q_D(const QGraphicsScene);
2240  return d->index->items(path, mode, order, deviceTransform);
2241 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ items() [7/12]

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

Returns all visible items at position pos in the scene.

The items are listed in descending stacking order (i.e., the first item in the list is the top-most item, and the last item is the bottom-most item).

This function is deprecated and returns incorrect results if the scene contains items that ignore transformations. Use the overload that takes a QTransform instead.

See also
itemAt(), {QGraphicsItem::Sorting}{Sorting}

Definition at line 2032 of file qgraphicsscene.cpp.

2033 {
2034  Q_D(const QGraphicsScene);
2035  return d->index->items(pos, Qt::IntersectsItemShape, Qt::DescendingOrder);
2036 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ items() [8/12]

QList< QGraphicsItem * > QGraphicsScene::items ( const QRectF rectangle,
Qt::ItemSelectionMode  mode = Qt::IntersectsItemShape 
) const

Returns all visible items that, depending on mode, are either inside or intersect with the specified rectangle.

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

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

This function is deprecated and returns incorrect results if the scene contains items that ignore transformations. Use the overload that takes a QTransform instead.

See also
itemAt(), {QGraphicsItem::Sorting}{Sorting}

Definition at line 2057 of file qgraphicsscene.cpp.

2058 {
2059  Q_D(const QGraphicsScene);
2060  return d->index->items(rectangle, mode, Qt::DescendingOrder);
2061 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ items() [9/12]

QList< QGraphicsItem * > QGraphicsScene::items ( const QPolygonF polygon,
Qt::ItemSelectionMode  mode = Qt::IntersectsItemShape 
) const

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

Returns all visible items that, depending on mode, are either inside or intersect with the polygon polygon.

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

This function is deprecated and returns incorrect results if the scene contains items that ignore transformations. Use the overload that takes a QTransform instead.

See also
itemAt(), {QGraphicsItem::Sorting}{Sorting}

Definition at line 2108 of file qgraphicsscene.cpp.

2109 {
2110  Q_D(const QGraphicsScene);
2111  return d->index->items(polygon, mode, Qt::DescendingOrder);
2112 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ items() [10/12]

QList< QGraphicsItem * > QGraphicsScene::items ( const QPainterPath path,
Qt::ItemSelectionMode  mode = Qt::IntersectsItemShape 
) const

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

Returns all visible items that, depending on path, are either inside or intersect with the path path.

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

This function is deprecated and returns incorrect results if the scene contains items that ignore transformations. Use the overload that takes a QTransform instead.

See also
itemAt(), {QGraphicsItem::Sorting}{Sorting}

Definition at line 2131 of file qgraphicsscene.cpp.

2132 {
2133  Q_D(const QGraphicsScene);
2134  return d->index->items(path, mode, Qt::DescendingOrder);
2135 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ items() [11/12]

QList< QGraphicsItem * > QGraphicsScene::items ( qreal  x,
qreal  y,
qreal  w,
qreal  h,
Qt::ItemSelectionMode  mode = Qt::IntersectsItemShape 
) const
inline
Since
4.3

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

This function is deprecated and returns incorrect results if the scene contains items that ignore transformations. Use the overload that takes a QTransform instead.

Definition at line 173 of file qgraphicsscene.h.

174  { return items(QRectF(x, y, w, h), mode); } // ### obsolete
QList< QGraphicsItem * > items() const
Returns a list of all items in the scene in descending stacking order.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ items() [12/12]

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

Returns all visible items that, depending on mode, are either inside or intersect with the rectangle defined by x, y,.

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

Since
4.6

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.

Definition at line 175 of file qgraphicsscene.h.

177  { return items(QRectF(x, y, w, h), mode, order, deviceTransform); }
QList< QGraphicsItem * > items() const
Returns a list of all items in the scene in descending stacking order.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ itemsBoundingRect()

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

Definition at line 1984 of file qgraphicsscene.cpp.

Referenced by ~QGraphicsScene().

1985 {
1986  // Does not take untransformable items into account.
1988  foreach (QGraphicsItem *item, items())
1989  boundingRect |= item->sceneBoundingRect();
1990  return boundingRect;
1991 }
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QList< QGraphicsItem * > items() const
Returns a list of all items in the scene in descending stacking order.
static const QRectF boundingRect(const QPointF *points, int pointCount)
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QRectF sceneBoundingRect() const
Returns the bounding rect of this item in scene coordinates, by combining sceneTransform() with bound...

◆ keyPressEvent()

void QGraphicsScene::keyPressEvent ( QKeyEvent keyEvent)
protectedvirtual

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(), focusItem()

Reimplemented in QDeclarativeScene.

Definition at line 4112 of file qgraphicsscene.cpp.

Referenced by event(), and QDeclarativeScene::keyPressEvent().

4113 {
4114  // ### Merge this function with keyReleaseEvent; they are identical
4115  // ### (except this comment).
4117  QGraphicsItem *item = !d->keyboardGrabberItems.isEmpty() ? d->keyboardGrabberItems.last() : 0;
4118  if (!item)
4119  item = focusItem();
4120  if (item) {
4121  QGraphicsItem *p = item;
4122  do {
4123  // Accept the event by default
4124  keyEvent->accept();
4125  // Send it; QGraphicsItem::keyPressEvent ignores it. If the event
4126  // is filtered out, stop propagating it.
4127  if (p->isBlockedByModalPanel())
4128  break;
4129  if (!d->sendEvent(p, keyEvent))
4130  break;
4131  } while (!keyEvent->isAccepted() && !p->isPanel() && (p = p->parentItem()));
4132  } else {
4133  keyEvent->ignore();
4134  }
4135 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
bool isBlockedByModalPanel(QGraphicsItem **blockingPanel=0) const
Returns true if this item is blocked by a modal panel, false otherwise.
#define Q_D(Class)
Definition: qglobal.h:2482
bool isAccepted() const
Definition: qcoreevent.h:307
QGraphicsItem * focusItem() const
When the scene is active, this functions returns the scene&#39;s current focus item, or 0 if no item curr...
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309

◆ keyReleaseEvent()

void QGraphicsScene::keyReleaseEvent ( QKeyEvent keyEvent)
protectedvirtual

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(), focusItem()

Reimplemented in QDeclarativeScene.

Definition at line 4144 of file qgraphicsscene.cpp.

Referenced by event(), and QDeclarativeScene::keyReleaseEvent().

4145 {
4146  // ### Merge this function with keyPressEvent; they are identical (except
4147  // ### this comment).
4149  QGraphicsItem *item = !d->keyboardGrabberItems.isEmpty() ? d->keyboardGrabberItems.last() : 0;
4150  if (!item)
4151  item = focusItem();
4152  if (item) {
4153  QGraphicsItem *p = item;
4154  do {
4155  // Accept the event by default
4156  keyEvent->accept();
4157  // Send it; QGraphicsItem::keyPressEvent ignores it. If the event
4158  // is filtered out, stop propagating it.
4159  if (p->isBlockedByModalPanel())
4160  break;
4161  if (!d->sendEvent(p, keyEvent))
4162  break;
4163  } while (!keyEvent->isAccepted() && !p->isPanel() && (p = p->parentItem()));
4164  } else {
4165  keyEvent->ignore();
4166  }
4167 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
bool isBlockedByModalPanel(QGraphicsItem **blockingPanel=0) const
Returns true if this item is blocked by a modal panel, false otherwise.
#define Q_D(Class)
Definition: qglobal.h:2482
bool isAccepted() const
Definition: qcoreevent.h:307
QGraphicsItem * focusItem() const
When the scene is active, this functions returns the scene&#39;s current focus item, or 0 if no item curr...
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309

◆ mouseDoubleClickEvent()

void QGraphicsScene::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent mouseEvent)
protectedvirtual

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(), QGraphicsItem::setAcceptedMouseButtons()

Definition at line 4287 of file qgraphicsscene.cpp.

Referenced by event().

4288 {
4290  d->mousePressEventHandler(mouseEvent);
4291 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ mouseGrabberItem()

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 receives a mouse release event when there are no other buttons pressed, it loses the mouse grab.
  • If the item becomes invisible (i.e., someone calls {item->setVisible(false)}), or if it becomes disabled (i.e., someone calls {item->setEnabled(false)}), it loses the mouse grab.
  • If the item is removed from the scene, it loses the mouse grab.

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

Definition at line 3242 of file qgraphicsscene.cpp.

Referenced by QDeclarativeMouseArea::mouseReleaseEvent(), QDeclarativePinchArea::mouseReleaseEvent(), QDeclarativePathView::sendMouseEvent(), QDeclarativeMouseArea::sendMouseEvent(), QDeclarativeFlickable::sendMouseEvent(), QDeclarativePinchArea::sendMouseEvent(), QGraphicsItem::setAcceptedMouseButtons(), QGraphicsItemPrivate::setEnabledHelper(), QDeclarativeFlickable::timerEvent(), and QDeclarativePinchArea::updatePinch().

3243 {
3244  Q_D(const QGraphicsScene);
3245  return !d->mouseGrabberItems.isEmpty() ? d->mouseGrabberItems.last() : 0;
3246 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ mouseMoveEvent()

void QGraphicsScene::mouseMoveEvent ( QGraphicsSceneMouseEvent mouseEvent)
protectedvirtual

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(), QGraphicsItem::setAcceptedMouseButtons()

Reimplemented in QDeclarativeScene.

Definition at line 4211 of file qgraphicsscene.cpp.

Referenced by event(), and QDeclarativeScene::mouseMoveEvent().

4212 {
4214  if (d->mouseGrabberItems.isEmpty()) {
4215  if (mouseEvent->buttons())
4216  return;
4218  _q_hoverFromMouseEvent(&hover, mouseEvent);
4219  mouseEvent->setAccepted(d->dispatchHoverEvent(&hover));
4220  return;
4221  }
4222 
4223  // Forward the event to the mouse grabber
4224  d->sendMouseEvent(mouseEvent);
4225  mouseEvent->accept();
4226 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
void setAccepted(bool accepted)
Definition: qcoreevent.h:306
#define Q_D(Class)
Definition: qglobal.h:2482
static void _q_hoverFromMouseEvent(QGraphicsSceneHoverEvent *hover, const QGraphicsSceneMouseEvent *mouseEvent)
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.

◆ mousePressEvent()

void QGraphicsScene::mousePressEvent ( QGraphicsSceneMouseEvent mouseEvent)
protectedvirtual

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(), QGraphicsItem::setAcceptedMouseButtons()

Reimplemented in QDeclarativeScene.

Definition at line 4186 of file qgraphicsscene.cpp.

Referenced by event(), and QDeclarativeScene::mousePressEvent().

4187 {
4189  if (d->mouseGrabberItems.isEmpty()) {
4190  // Dispatch hover events
4192  _q_hoverFromMouseEvent(&hover, mouseEvent);
4193  d->dispatchHoverEvent(&hover);
4194  }
4195 
4196  d->mousePressEventHandler(mouseEvent);
4197 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482
static void _q_hoverFromMouseEvent(QGraphicsSceneHoverEvent *hover, const QGraphicsSceneMouseEvent *mouseEvent)
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.

◆ mouseReleaseEvent()

void QGraphicsScene::mouseReleaseEvent ( QGraphicsSceneMouseEvent mouseEvent)
protectedvirtual

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(), QGraphicsItem::setAcceptedMouseButtons()

Reimplemented in QDeclarativeScene.

Definition at line 4241 of file qgraphicsscene.cpp.

Referenced by event(), and QDeclarativeScene::mouseReleaseEvent().

4242 {
4244  if (d->mouseGrabberItems.isEmpty()) {
4245  mouseEvent->ignore();
4246  return;
4247  }
4248 
4249  // Forward the event to the mouse grabber
4250  d->sendMouseEvent(mouseEvent);
4251  mouseEvent->accept();
4252 
4253  // Reset the mouse grabber when the last mouse button has been released.
4254  if (!mouseEvent->buttons()) {
4255  if (!d->mouseGrabberItems.isEmpty()) {
4256  d->lastMouseGrabberItem = d->mouseGrabberItems.last();
4257  if (d->lastMouseGrabberItemHasImplicitMouseGrab)
4258  d->mouseGrabberItems.last()->ungrabMouse();
4259  } else {
4260  d->lastMouseGrabberItem = 0;
4261  }
4262 
4263  // Generate a hoverevent
4264  QGraphicsSceneHoverEvent hoverEvent;
4265  _q_hoverFromMouseEvent(&hoverEvent, mouseEvent);
4266  d->dispatchHoverEvent(&hoverEvent);
4267  }
4268 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482
static void _q_hoverFromMouseEvent(QGraphicsSceneHoverEvent *hover, const QGraphicsSceneMouseEvent *mouseEvent)
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.

◆ palette()

QPalette QGraphicsScene::palette ( ) const

Referenced by setFont().

◆ removeItem()

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

Definition at line 3062 of file qgraphicsscene.cpp.

Referenced by QmlJSDebugger::LiveSelectionIndicator::clear(), QDeclarativeLoaderPrivate::clear(), QDeclarativeFlickablePrivate::data_clear(), destroyItemGroup(), QDeclarativeVisualItemModel::release(), QDeclarativeVisualDataModel::release(), QGraphicsItem::removeFromIndex(), QGraphicsScenePrivate::removeItemHelper(), QDeclarativeGridView::setFooter(), QDeclarativeListView::setFooter(), QDeclarativeGridView::setHeader(), QDeclarativeListView::setHeader(), QGraphicsProxyWidgetPrivate::unembedSubWindow(), and QmlJSDebugger::LiveSelectionRectangle::~LiveSelectionRectangle().

3063 {
3064  // ### Refactoring: This function shares much functionality with _q_removeItemLater()
3066  if (!item) {
3067  qWarning("QGraphicsScene::removeItem: cannot remove 0-item");
3068  return;
3069  }
3070  if (item->scene() != this) {
3071  qWarning("QGraphicsScene::removeItem: item %p's scene (%p)"
3072  " is different from this scene (%p)",
3073  item, item->scene(), this);
3074  return;
3075  }
3076 
3077  // Notify the item that it's scene is changing to 0, allowing the item to
3078  // react.
3079  const QVariant newSceneVariant(item->itemChange(QGraphicsItem::ItemSceneChange,
3080  QVariant::fromValue<QGraphicsScene *>(0)));
3081  QGraphicsScene *targetScene = qvariant_cast<QGraphicsScene *>(newSceneVariant);
3082  if (targetScene != 0 && targetScene != this) {
3083  targetScene->addItem(item);
3084  return;
3085  }
3086 
3087  d->removeItemHelper(item);
3088 
3089  // Deliver post-change notification
3090  item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant);
3091 
3092  d->updateInputMethodSensitivityInViews();
3093 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
This virtual function is called by QGraphicsItem to notify custom items that some part of the item&#39;s ...
void addItem(QGraphicsItem *item)
Adds or moves the item and all its childen to this scene.
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.

◆ render()

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:

scene.addItem(...
...
QPainter painter(&printer);
scene.render(&painter);

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

Definition at line 1779 of file qgraphicsscene.cpp.

1781 {
1782  // ### Switch to using the recursive rendering algorithm instead.
1783 
1784  // Default source rect = scene rect
1785  QRectF sourceRect = source;
1786  if (sourceRect.isNull())
1787  sourceRect = sceneRect();
1788 
1789  // Default target rect = device rect
1790  QRectF targetRect = target;
1791  if (targetRect.isNull()) {
1792  if (painter->device()->devType() == QInternal::Picture)
1793  targetRect = sourceRect;
1794  else
1795  targetRect.setRect(0, 0, painter->device()->width(), painter->device()->height());
1796  }
1797 
1798  // Find the ideal x / y scaling ratio to fit \a source into \a target.
1799  qreal xratio = targetRect.width() / sourceRect.width();
1800  qreal yratio = targetRect.height() / sourceRect.height();
1801 
1802  // Scale according to the aspect ratio mode.
1803  switch (aspectRatioMode) {
1804  case Qt::KeepAspectRatio:
1805  xratio = yratio = qMin(xratio, yratio);
1806  break;
1808  xratio = yratio = qMax(xratio, yratio);
1809  break;
1810  case Qt::IgnoreAspectRatio:
1811  break;
1812  }
1813 
1814  // Find all items to draw, and reverse the list (we want to draw
1815  // in reverse order).
1817  QGraphicsItem **itemArray = new QGraphicsItem *[itemList.size()];
1818  int numItems = itemList.size();
1819  for (int i = 0; i < numItems; ++i)
1820  itemArray[numItems - i - 1] = itemList.at(i);
1821  itemList.clear();
1822 
1823  painter->save();
1824 
1825  // Transform the painter.
1826  painter->setClipRect(targetRect, Qt::IntersectClip);
1827  QTransform painterTransform;
1828  painterTransform *= QTransform()
1829  .translate(targetRect.left(), targetRect.top())
1830  .scale(xratio, yratio)
1831  .translate(-sourceRect.left(), -sourceRect.top());
1832  painter->setWorldTransform(painterTransform, true);
1833 
1834  // Two unit vectors.
1835  QLineF v1(0, 0, 1, 0);
1836  QLineF v2(0, 0, 0, 1);
1837 
1838  // Generate the style options
1839  QStyleOptionGraphicsItem *styleOptionArray = new QStyleOptionGraphicsItem[numItems];
1840  for (int i = 0; i < numItems; ++i)
1841  itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], painterTransform, targetRect.toRect());
1842 
1843  // Render the scene.
1844  drawBackground(painter, sourceRect);
1845  drawItems(painter, numItems, itemArray, styleOptionArray);
1846  drawForeground(painter, sourceRect);
1847 
1848  delete [] itemArray;
1849  delete [] styleOptionArray;
1850 
1851  painter->restore();
1852 }
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or 0 if the painter is not acti...
Definition: qpainter.cpp:1530
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
virtual void drawBackground(QPainter *painter, const QRectF &rect)
Draws the background of the scene using painter, before any items and the foreground are drawn...
int height() const
Definition: qpaintdevice.h:92
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
Definition: qpainter.cpp:2801
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
QList< QGraphicsItem * > items() const
Returns a list of all items in the scene in descending stacking order.
virtual void drawForeground(QPainter *painter, const QRectF &rect)
Draws the foreground of the scene using painter, after the background and all items have been drawn...
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
Definition: qtransform.cpp:417
virtual int devType() const
Definition: qpaintdevice.h:167
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
int width() const
Definition: qpaintdevice.h:91
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QRectF sceneRect() const
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
void setRect(qreal x, qreal y, qreal w, qreal h)
Sets the coordinates of the rectangle&#39;s top-left corner to (x, y), and its size to the given width an...
Definition: qrect.h:754
void clear()
Removes all items from the list.
Definition: qlist.h:764
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void setWorldTransform(const QTransform &matrix, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9630
QScopedPointer< QObjectData > d_ptr
Definition: qobject.h:320
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
virtual void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem options[], QWidget *widget=0)
Paints the given items using the provided painter, after the background has been drawn, and before the foreground has been drawn.
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem...
Definition: qstyleoption.h:867
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ sceneRect()

QRectF QGraphicsScene::sceneRect ( ) const

Referenced by render(), and ~QGraphicsScene().

◆ sceneRectChanged

QGraphicsScene::sceneRectChanged ( const QRectF rect)
signal

This signal is emitted by QGraphicsScene whenever the scene rect changes.

The rect parameter is the new scene rectangle.

See also
QGraphicsView::updateSceneRect()

Referenced by setSceneRect(), and ~QGraphicsScene().

◆ selectedItems()

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

Returns a list of all currently selected items.

The items are returned in no particular order.

See also
setSelectionArea()

Definition at line 2359 of file qgraphicsscene.cpp.

Referenced by QGraphicsItem::mouseMoveEvent(), QGraphicsItem::mouseReleaseEvent(), and selectedItems().

2360 {
2361  Q_D(const QGraphicsScene);
2362 
2363  // Optimization: Lazily removes items that are not selected.
2364  QGraphicsScene *that = const_cast<QGraphicsScene *>(this);
2365  QSet<QGraphicsItem *> actuallySelectedSet;
2366  foreach (QGraphicsItem *item, that->d_func()->selectedItems) {
2367  if (item->isSelected())
2368  actuallySelectedSet << item;
2369  }
2370 
2371  that->d_func()->selectedItems = actuallySelectedSet;
2372 
2373  return d->selectedItems.values();
2374 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
bool isSelected() const
Returns true if this item is selected; otherwise, false is returned.
#define Q_D(Class)
Definition: qglobal.h:2482
QList< QGraphicsItem * > selectedItems() const
Returns a list of all currently selected items.

◆ selectionArea()

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

Definition at line 2383 of file qgraphicsscene.cpp.

2384 {
2385  Q_D(const QGraphicsScene);
2386  return d->selectionArea;
2387 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ selectionChanged

QGraphicsScene::selectionChanged ( )
signal

This signal is emitted by QGraphicsScene whenever the selection changes.

Since
4.3

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

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

Referenced by addItem(), clearSelection(), QGraphicsItem::mouseReleaseEvent(), QGraphicsItem::setSelected(), and setSelectionArea().

◆ sendEvent()

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

Sends event event to item item through possible event filters.

Since
4.6

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.

See also
QGraphicsItem::sceneEvent(), QGraphicsItem::sceneEventFilter()

Definition at line 5922 of file qgraphicsscene.cpp.

Referenced by QGraphicsScenePrivate::cancelGesturesForChildren(), QGraphicsScenePrivate::enterModal(), event(), QGraphicsScenePrivate::gestureEventHandler(), helpEvent(), QGraphicsScenePrivate::leaveModal(), QGraphicsItem::sceneEvent(), QDeclarativeFlickable::sendMouseEvent(), and QGraphicsScenePrivate::sendTouchBeginEvent().

5923 {
5925  if (!item) {
5926  qWarning("QGraphicsScene::sendEvent: cannot send event to a null item");
5927  return false;
5928  }
5929  if (item->scene() != this) {
5930  qWarning("QGraphicsScene::sendEvent: item %p's scene (%p)"
5931  " is different from this scene (%p)",
5932  item, item->scene(), this);
5933  return false;
5934  }
5935  return d->sendEvent(item, event);
5936 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.

◆ setActivePanel()

void QGraphicsScene::setActivePanel ( QGraphicsItem item)

Activates item, which must be an item in this scene.

Since
4.6 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).

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

Definition at line 5838 of file qgraphicsscene.cpp.

Referenced by addItem(), QGraphicsItem::setActive(), setActiveWindow(), and QGraphicsItemPrivate::setVisibleHelper().

5839 {
5841  d->setActivePanelHelper(item, false);
5842 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setActiveWindow()

void QGraphicsScene::setActiveWindow ( QGraphicsWidget widget)

Activates widget, which must be a widget in this scene.

Since
4.4 You can also pass 0 for widget, in which case QGraphicsScene will deactivate any currently active window.
See also
activeWindow(), QGraphicsWidget::isActiveWindow()

Definition at line 5874 of file qgraphicsscene.cpp.

5875 {
5876  if (widget && widget->scene() != this) {
5877  qWarning("QGraphicsScene::setActiveWindow: widget %p must be part of this scene",
5878  widget);
5879  return;
5880  }
5881 
5882  // Activate the widget's panel (all windows are panels).
5883  QGraphicsItem *panel = widget ? widget->panel() : 0;
5884  setActivePanel(panel);
5885 
5886  // Raise
5887  if (panel) {
5888  QList<QGraphicsItem *> siblingWindows;
5889  QGraphicsItem *parent = panel->parentItem();
5890  // Raise ### inefficient for toplevels
5891  foreach (QGraphicsItem *sibling, parent ? parent->children() : items()) {
5892  if (sibling != panel && sibling->isWindow())
5893  siblingWindows << sibling;
5894  }
5895 
5896  // Find the highest z value.
5897  qreal z = panel->zValue();
5898  for (int i = 0; i < siblingWindows.size(); ++i)
5899  z = qMax(z, siblingWindows.at(i)->zValue());
5900 
5901  // This will probably never overflow.
5902  const qreal litt = qreal(0.001);
5903  panel->setZValue(z + litt);
5904  }
5905 }
double qreal
Definition: qglobal.h:1193
bool isWindow() const
Returns true if the item is a QGraphicsWidget window, otherwise returns false.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QList< QGraphicsItem * > items() const
Returns a list of all items in the scene in descending stacking order.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qreal zValue() const
Returns the Z-value of the item.
void setZValue(qreal z)
Sets the Z-value of the item to z.
QGraphicsItem * panel() const
Returns the item&#39;s panel, or 0 if this item does not have a panel.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_CORE_EXPORT void qWarning(const char *,...)
void setActivePanel(QGraphicsItem *item)
Activates item, which must be an item in this scene.
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
QList< QGraphicsItem * > children() const
Use childItems() instead.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ setBackgroundBrush()

void QGraphicsScene::setBackgroundBrush ( const QBrush brush)

Definition at line 3272 of file qgraphicsscene.cpp.

3273 {
3275  d->backgroundBrush = brush;
3276  foreach (QGraphicsView *view, d->views) {
3277  view->resetCachedContent();
3278  view->viewport()->update();
3279  }
3280  update();
3281 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QWidget * viewport() const
Returns the viewport widget.
void resetCachedContent()
Resets any cached content.
void update(qreal x, qreal y, qreal w, qreal h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ setBspTreeDepth()

void QGraphicsScene::setBspTreeDepth ( int  depth)

Definition at line 1937 of file qgraphicsscene.cpp.

1938 {
1940  if (depth < 0) {
1941  qWarning("QGraphicsScene::setBspTreeDepth: invalid depth %d ignored; must be >= 0", depth);
1942  return;
1943  }
1944 
1946  if (!bspTree) {
1947  qWarning("QGraphicsScene::setBspTreeDepth: can not apply if indexing method is not BSP");
1948  return;
1949  }
1950  bspTree->setBspTreeDepth(depth);
1951 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
The QGraphicsSceneBspTreeIndex class provides an implementation of a BSP indexing algorithm for disco...
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setFocus()

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(), setFocusItem()

Definition at line 3160 of file qgraphicsscene.cpp.

Referenced by QGraphicsScenePrivate::sendTouchBeginEvent().

3161 {
3163  if (d->hasFocus || !isActive())
3164  return;
3165  QFocusEvent event(QEvent::FocusIn, focusReason);
3167 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
bool event(QEvent *event)
Processes the event event, and dispatches it to the respective event handlers.
bool isActive() const
Returns true if the scene is active (e.
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275

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

Definition at line 3128 of file qgraphicsscene.cpp.

Referenced by clearFocus(), QGraphicsItemPrivate::clearFocusHelper(), focusInEvent(), focusNextPrevChild(), focusOutEvent(), QGraphicsItemPrivate::setVisibleHelper(), and wheelEvent().

3129 {
3131  if (item)
3132  item->setFocus(focusReason);
3133  else
3134  d->setFocusItemHelper(item, focusReason);
3135 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482
void setFocus(Qt::FocusReason focusReason=Qt::OtherFocusReason)
Gives keyboard input focus to this item.

◆ setFont()

void QGraphicsScene::setFont ( const QFont font)

Definition at line 5743 of file qgraphicsscene.cpp.

5744 {
5746  QFont naturalFont = QApplication::font();
5747  naturalFont.resolve(0);
5748  QFont resolvedFont = font.resolve(naturalFont);
5749  d->setFont_helper(resolvedFont);
5750 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482
static QFont font()
Returns the default application font.
QFont resolve(const QFont &) const
Returns a new QFont that has attributes copied from other that have not been previously set on this f...
Definition: qfont.cpp:1983
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64

◆ setForegroundBrush()

void QGraphicsScene::setForegroundBrush ( const QBrush brush)

Definition at line 3311 of file qgraphicsscene.cpp.

3312 {
3314  d->foregroundBrush = brush;
3315  foreach (QGraphicsView *view, views())
3316  view->viewport()->update();
3317  update();
3318 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QWidget * viewport() const
Returns the viewport widget.
QList< QGraphicsView * > views() const
Returns a list of all the views that display this scene.
void update(qreal x, qreal y, qreal w, qreal h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ setItemIndexMethod()

void QGraphicsScene::setItemIndexMethod ( ItemIndexMethod  method)

Definition at line 1878 of file qgraphicsscene.cpp.

1879 {
1881  if (d->indexMethod == method)
1882  return;
1883 
1884  d->indexMethod = method;
1885 
1886  QList<QGraphicsItem *> oldItems = d->index->items(Qt::DescendingOrder);
1887  delete d->index;
1888  if (method == BspTreeIndex)
1889  d->index = new QGraphicsSceneBspTreeIndex(this);
1890  else
1891  d->index = new QGraphicsSceneLinearIndex(this);
1892  for (int i = oldItems.size() - 1; i >= 0; --i)
1893  d->index->addItem(oldItems.at(i));
1894 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
friend class QGraphicsSceneBspTreeIndex
The QGraphicsSceneLinearIndex class provides an implementation of a linear indexing algorithm for dis...
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ setPalette()

void QGraphicsScene::setPalette ( const QPalette palette)

Definition at line 5783 of file qgraphicsscene.cpp.

5784 {
5786  QPalette naturalPalette = QApplication::palette();
5787  naturalPalette.resolve(0);
5788  QPalette resolvedPalette = palette.resolve(naturalPalette);
5789  d->setPalette_helper(resolvedPalette);
5790 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
static QPalette palette()
Returns the application palette.
#define Q_D(Class)
Definition: qglobal.h:2482
QPalette resolve(const QPalette &) const
Returns a new QPalette that has attributes copied from other.
Definition: qpalette.cpp:1101
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61

◆ setSceneRect() [1/2]

void QGraphicsScene::setSceneRect ( const QRectF rect)

Definition at line 1729 of file qgraphicsscene.cpp.

Referenced by QGraphicsScene().

1730 {
1732  if (rect != d->sceneRect) {
1733  d->hasSceneRect = !rect.isNull();
1734  d->sceneRect = rect;
1735  emit sceneRectChanged(d->hasSceneRect ? rect : d->growingItemsBoundingRect);
1736  }
1737 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482
void sceneRectChanged(const QRectF &rect)
This signal is emitted by QGraphicsScene whenever the scene rect changes.
#define emit
Definition: qobjectdefs.h:76
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655

◆ setSceneRect() [2/2]

void QGraphicsScene::setSceneRect ( qreal  x,
qreal  y,
qreal  w,
qreal  h 
)
inline

Definition at line 137 of file qgraphicsscene.h.

138  { setSceneRect(QRectF(x, y, w, h)); }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void setSceneRect(const QRectF &rect)

◆ setSelectionArea() [1/4]

void QGraphicsScene::setSelectionArea ( const QPainterPath path)

Sets the selection area to path.

This function is deprecated and leads to incorrect results if the scene contains items that ignore transformations. Use the overload that takes a QTransform instead.

Definition at line 2425 of file qgraphicsscene.cpp.

Referenced by setSelectionArea().

2426 {
2428 }
void setSelectionArea(const QPainterPath &path)
Sets the selection area to path.
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ setSelectionArea() [2/4]

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

Sets the selection area to path.

Since
4.6

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

See also
clearSelection(), selectionArea()

Definition at line 2407 of file qgraphicsscene.cpp.

2408 {
2409  setSelectionArea(path, Qt::IntersectsItemShape, deviceTransform);
2410 }
void setSelectionArea(const QPainterPath &path)
Sets the selection area to path.

◆ setSelectionArea() [3/4]

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

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

Since
4.3
See also
clearSelection(), selectionArea()

Definition at line 2443 of file qgraphicsscene.cpp.

2444 {
2445  setSelectionArea(path, mode, QTransform());
2446 }
void setSelectionArea(const QPainterPath &path)
Sets the selection area to path.
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ setSelectionArea() [4/4]

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

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

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

Since
4.6

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

See also
clearSelection(), selectionArea()

Definition at line 2463 of file qgraphicsscene.cpp.

2465 {
2467 
2468  // Note: with boolean path operations, we can improve performance here
2469  // quite a lot by "growing" the old path instead of replacing it. That
2470  // allows us to only check the intersect area for changes, instead of
2471  // reevaluating the whole path over again.
2472  d->selectionArea = path;
2473 
2474  QSet<QGraphicsItem *> unselectItems = d->selectedItems;
2475 
2476  // Disable emitting selectionChanged() for individual items.
2477  ++d->selectionChanging;
2478  bool changed = false;
2479 
2480  // Set all items in path to selected.
2481  foreach (QGraphicsItem *item, items(path, mode, Qt::DescendingOrder, deviceTransform)) {
2482  if (item->flags() & QGraphicsItem::ItemIsSelectable) {
2483  if (!item->isSelected())
2484  changed = true;
2485  unselectItems.remove(item);
2486  item->setSelected(true);
2487  }
2488  }
2489 
2490  // Unselect all items outside path.
2491  foreach (QGraphicsItem *item, unselectItems) {
2492  item->setSelected(false);
2493  changed = true;
2494  }
2495 
2496  // Reenable emitting selectionChanged() for individual items.
2497  --d->selectionChanging;
2498 
2499  if (!d->selectionChanging && changed)
2501 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
void setSelected(bool selected)
If selected is true and this item is selectable, this item is selected; otherwise, it is unselected.
bool remove(const T &value)
Definition: qset.h:89
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QList< QGraphicsItem * > items() const
Returns a list of all items in the scene in descending stacking order.
bool isSelected() const
Returns true if this item is selected; otherwise, false is returned.
#define Q_D(Class)
Definition: qglobal.h:2482
#define emit
Definition: qobjectdefs.h:76
void changed(const QList< QRectF > &region)
This signal is emitted by QGraphicsScene when control reaches the event loop, if the scene content ch...
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
void selectionChanged()
This signal is emitted by QGraphicsScene whenever the selection changes.

◆ setSortCacheEnabled()

void QGraphicsScene::setSortCacheEnabled ( bool  enabled)

Definition at line 1969 of file qgraphicsscene.cpp.

1970 {
1972  if (d->sortCacheEnabled == enabled)
1973  return;
1974  d->sortCacheEnabled = enabled;
1975 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482
#define enabled

◆ setStickyFocus()

void QGraphicsScene::setStickyFocus ( bool  enabled)

Definition at line 3209 of file qgraphicsscene.cpp.

3210 {
3212  d->stickyFocus = enabled;
3213 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define Q_D(Class)
Definition: qglobal.h:2482
#define enabled

◆ setStyle()

void QGraphicsScene::setStyle ( QStyle style)

Sets or replaces the style of the scene to style, and reparents the style to this scene.

Since
4.4

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

See also
style()

Definition at line 5686 of file qgraphicsscene.cpp.

5687 {
5689  // ### This function, and the use of styles in general, is non-reentrant.
5690  if (style == d->style)
5691  return;
5692 
5693  // Delete the old style,
5694  delete d->style;
5695  if ((d->style = style))
5696  d->style->setParent(this);
5697 
5698  // Notify the scene.
5701 
5702  // Notify all widgets that don't have a style explicitly set.
5703  foreach (QGraphicsItem *item, items()) {
5704  if (item->isWidget()) {
5705  QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
5706  if (!widget->testAttribute(Qt::WA_SetStyle))
5707  QApplication::sendEvent(widget, &event);
5708  }
5709  }
5710 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
QPointer< QWidget > widget
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QList< QGraphicsItem * > items() const
Returns a list of all items in the scene in descending stacking order.
#define Q_D(Class)
Definition: qglobal.h:2482
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
bool event(QEvent *event)
Processes the event event, and dispatches it to the respective event handlers.
bool testAttribute(Qt::WidgetAttribute attribute) const
Returns true if attribute is enabled for this widget; otherwise, returns false.
bool isWidget() const
Returns true if this item is a widget (i.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ stickyFocus()

bool QGraphicsScene::stickyFocus ( ) const

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

Since
4.4
See also
setStyle()

Definition at line 5659 of file qgraphicsscene.cpp.

Referenced by QGraphicsWidget::style().

5660 {
5661  Q_D(const QGraphicsScene);
5662  // ### This function, and the use of styles in general, is non-reentrant.
5663  return d->style ? d->style : QApplication::style();
5664 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
static QStyle * style()
Returns the application&#39;s style object.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ update() [1/2]

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

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

Since
4.3

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

Definition at line 232 of file qgraphicsscene.h.

Referenced by event(), invalidate(), QDeclarativeView::paintEvent(), QGraphicsItem::prepareGeometryChange(), setBackgroundBrush(), and setForegroundBrush().

233  { update(QRectF(x, y, w, h)); }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void update(qreal x, qreal y, qreal w, qreal h)
This is an overloaded member function, provided for convenience. It differs from the above function o...

◆ update [2/2]

void QGraphicsScene::update ( const QRectF rect = QRectF())
slot

Schedules a redraw of the area rect on the scene.

See also
sceneRect(), changed()

Definition at line 3356 of file qgraphicsscene.cpp.

3357 {
3359  if (d->updateAll || (rect.isEmpty() && !rect.isNull()))
3360  return;
3361 
3362  // Check if anyone's connected; if not, we can send updates directly to
3363  // the views. Otherwise or if there are no views, use old behavior.
3364  bool directUpdates = !(d->isSignalConnected(d->changedSignalIndex)) && !d->views.isEmpty();
3365  if (rect.isNull()) {
3366  d->updateAll = true;
3367  d->updatedRects.clear();
3368  if (directUpdates) {
3369  // Update all views.
3370  for (int i = 0; i < d->views.size(); ++i)
3371  d->views.at(i)->d_func()->fullUpdatePending = true;
3372  }
3373  } else {
3374  if (directUpdates) {
3375  // Update all views.
3376  for (int i = 0; i < d->views.size(); ++i) {
3377  QGraphicsView *view = d->views.at(i);
3378  if (view->isTransformed())
3379  view->d_func()->updateRectF(view->viewportTransform().mapRect(rect));
3380  else
3381  view->d_func()->updateRectF(rect);
3382  }
3383  } else {
3384  d->updatedRects << rect;
3385  }
3386  }
3387 
3388  if (!d->calledEmitUpdated) {
3389  d->calledEmitUpdated = true;
3390  QMetaObject::invokeMethod(this, "_q_emitUpdated", Qt::QueuedConnection);
3391  }
3392 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
bool isTransformed() const
Returns true if the view is transformed (i.
#define Q_D(Class)
Definition: qglobal.h:2482
QTransform viewportTransform() const
Returns a matrix that maps viewport coordinates to scene coordinates.
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:658
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655

◆ views()

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

◆ wheelEvent()

void QGraphicsScene::wheelEvent ( QGraphicsSceneWheelEvent wheelEvent)
protectedvirtual

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

Definition at line 4304 of file qgraphicsscene.cpp.

Referenced by event().

4305 {
4307  QList<QGraphicsItem *> wheelCandidates = d->itemsAtPosition(wheelEvent->screenPos(),
4308  wheelEvent->scenePos(),
4309  wheelEvent->widget());
4310 
4311 #ifdef Q_WS_MAC
4312  // On Mac, ignore the event if the first item under the mouse is not the last opened
4313  // popup (or one of its descendant)
4314  if (!d->popupWidgets.isEmpty() && !wheelCandidates.isEmpty() && wheelCandidates.first() != d->popupWidgets.back() && !d->popupWidgets.back()->isAncestorOf(wheelCandidates.first())) {
4315  wheelEvent->accept();
4316  return;
4317  }
4318 #else
4319  // Find the first popup under the mouse (including the popup's descendants) starting from the last.
4320  // Remove all popups after the one found, or all or them if no popup is under the mouse.
4321  // Then continue with the event.
4322  QList<QGraphicsWidget *>::const_iterator iter = d->popupWidgets.end();
4323  while (--iter >= d->popupWidgets.begin() && !wheelCandidates.isEmpty()) {
4324  if (wheelCandidates.first() == *iter || (*iter)->isAncestorOf(wheelCandidates.first()))
4325  break;
4326  d->removePopup(*iter);
4327  }
4328 #endif
4329 
4330  bool hasSetFocus = false;
4331  foreach (QGraphicsItem *item, wheelCandidates) {
4332  if (!hasSetFocus && item->isEnabled()
4333  && ((item->flags() & QGraphicsItem::ItemIsFocusable) && item->d_ptr->mouseSetsFocus)) {
4334  if (item->isWidget() && static_cast<QGraphicsWidget *>(item)->focusPolicy() == Qt::WheelFocus) {
4335  hasSetFocus = true;
4336  if (item != focusItem())
4338  }
4339  }
4340 
4341  wheelEvent->setPos(item->d_ptr->genericMapFromScene(wheelEvent->scenePos(),
4342  wheelEvent->widget()));
4343  wheelEvent->accept();
4344  bool isPanel = item->isPanel();
4345  d->sendEvent(item, wheelEvent);
4346  if (isPanel || wheelEvent->isAccepted())
4347  break;
4348  }
4349 }
double d
Definition: qnumeric_p.h:62
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QPointF genericMapFromScene(const QPointF &pos, const QWidget *viewport) const
Maps the point pos from scene to item coordinates.
The QList::const_iterator class provides an STL-style const iterator for QList and QQueue...
Definition: qlist.h:228
QWidget * widget() const
Returns the widget where the event originated, or 0 if the event originates from another application...
bool isEnabled() const
Returns true if the item is enabled; otherwise, false is returned.
#define Q_D(Class)
Definition: qglobal.h:2482
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
bool isAccepted() const
Definition: qcoreevent.h:307
QGraphicsItem * focusItem() const
When the scene is active, this functions returns the scene&#39;s current focus item, or 0 if no item curr...
void setPos(const QPointF &pos)
QPoint screenPos() const
Returns the position of the cursor in screen coordinates when the wheel event occurred.
void setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReason=Qt::OtherFocusReason)
Sets the scene&#39;s focus item to item, with the focus reason focusReason, after removing focus from any...
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
QPointF scenePos() const
Returns the position of the cursor in scene coordinates when the wheel event occurred.
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
bool isWidget() const
Returns true if this item is a widget (i.
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ width()

qreal QGraphicsScene::width ( ) const
inline

This convenience function is equivalent to calling sceneRect().

width().

 \sa height()

Definition at line 134 of file qgraphicsscene.h.

134 { return sceneRect().width(); }
QRectF sceneRect() const
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707

Friends and Related Functions

◆ QGesture

friend class QGesture
friend

Definition at line 317 of file qgraphicsscene.h.

◆ QGraphicsEffect

friend class QGraphicsEffect
friend

Definition at line 310 of file qgraphicsscene.h.

◆ QGraphicsItem

friend class QGraphicsItem
friend

Definition at line 303 of file qgraphicsscene.h.

◆ QGraphicsItemEffectSourcePrivate

Definition at line 315 of file qgraphicsscene.h.

◆ QGraphicsItemPrivate

friend class QGraphicsItemPrivate
friend

Definition at line 304 of file qgraphicsscene.h.

◆ QGraphicsObject

friend class QGraphicsObject
friend

Definition at line 305 of file qgraphicsscene.h.

◆ QGraphicsSceneBspTreeIndex

Definition at line 313 of file qgraphicsscene.h.

Referenced by setItemIndexMethod().

◆ QGraphicsSceneBspTreeIndexPrivate

Definition at line 314 of file qgraphicsscene.h.

◆ QGraphicsSceneIndex

friend class QGraphicsSceneIndex
friend

Definition at line 311 of file qgraphicsscene.h.

◆ QGraphicsSceneIndexPrivate

Definition at line 312 of file qgraphicsscene.h.

◆ QGraphicsView

friend class QGraphicsView
friend

Definition at line 306 of file qgraphicsscene.h.

◆ QGraphicsViewPrivate

friend class QGraphicsViewPrivate
friend

Definition at line 307 of file qgraphicsscene.h.

◆ QGraphicsWidget

friend class QGraphicsWidget
friend

Definition at line 308 of file qgraphicsscene.h.

◆ QGraphicsWidgetPrivate

Definition at line 309 of file qgraphicsscene.h.

Properties

◆ backgroundBrush

QBrush QGraphicsScene::backgroundBrush
private

the background brush of the scene.

Set this property to changes the scene's background to a different color, gradient or texture. The default background brush is Qt::NoBrush. The background is drawn before (behind) the items.

Example:

QGraphicsView view(&scene);
view.show();
// a blue background
// a gradient background
QRadialGradient gradient(0, 0, 10);
gradient.setSpread(QGradient::RepeatSpread);
scene.setBackgroundBrush(gradient);

QGraphicsScene::render() calls drawBackground() to draw the scene background. For more detailed control over how the background is drawn, you can reimplement drawBackground() in a subclass of QGraphicsScene.

Definition at line 104 of file qgraphicsscene.h.

◆ bspTreeDepth

int QGraphicsScene::bspTreeDepth
private

the depth of QGraphicsScene's BSP index tree

Since
4.3

This property has no effect when NoIndex is used.

This value determines the depth of QGraphicsScene's BSP tree. The depth directly affects QGraphicsScene's performance and memory usage; the latter growing exponentially with the depth of the tree. With an optimal tree depth, QGraphicsScene can instantly determine the locality of items, even for scenes with thousands or millions of items. This also greatly improves rendering performance.

By default, the value is 0, in which case Qt will guess a reasonable default depth based on the size, location and number of items in the scene. If these parameters change frequently, however, you may experience slowdowns as QGraphicsScene retunes the depth internally. You can avoid potential slowdowns by fixating the tree depth through setting this property.

The depth of the tree and the size of the scene rectangle decide the granularity of the scene's partitioning. The size of each scene segment is determined by the following algorithm:

QSizeF segmentSize = sceneRect().size() / pow(2, depth - 1);

The BSP tree has an optimal size when each segment contains between 0 and 10 items.

See also
itemIndexMethod

Definition at line 108 of file qgraphicsscene.h.

◆ font

QFont QGraphicsScene::font
private

the scene's default font

Since
4.4

This property provides the scene's font. The scene font defaults to, and resolves all its entries from, QApplication::font.

If the scene's font changes, either directly through setFont() or indirectly when the application font changes, QGraphicsScene first sends itself a FontChange event, and it then sends FontChange events to all top-level widget items in the scene. These items respond by resolving their own fonts to the scene, and they then notify their children, who again notify their children, and so on, until all widget items have updated their fonts.

Changing the scene font, (directly or indirectly through QApplication::setFont(),) automatically schedules a redraw the entire scene.

See also
QWidget::font, QApplication::setFont(), palette, style()

Definition at line 110 of file qgraphicsscene.h.

Referenced by QGraphicsWidgetPrivate::naturalWidgetFont().

◆ foregroundBrush

QBrush QGraphicsScene::foregroundBrush
private

the foreground brush of the scene.

Change this property to set the scene's foreground to a different color, gradient or texture.

The foreground is drawn after (on top of) the items. The default foreground brush is Qt::NoBrush ( i.e. the foreground is not drawn).

Example:

QGraphicsView view(&scene);
view.show();
// a white semi-transparent foreground
scene.setForegroundBrush(QColor(255, 255, 255, 127));
// a grid foreground

QGraphicsScene::render() calls drawForeground() to draw the scene foreground. For more detailed control over how the foreground is drawn, you can reimplement the drawForeground() function in a QGraphicsScene subclass.

Definition at line 105 of file qgraphicsscene.h.

◆ itemIndexMethod

QGraphicsScene::ItemIndexMethod QGraphicsScene::itemIndexMethod
private

the item indexing method.

QGraphicsScene applies an indexing algorithm to the scene, to speed up item discovery functions like items() and itemAt(). Indexing is most efficient for static scenes (i.e., where items don't move around). For dynamic scenes, or scenes with many animated items, the index bookkeeping can outweight the fast lookup speeds.

For the common case, the default index method BspTreeIndex works fine. If your scene uses many animations and you are experiencing slowness, you can disable indexing by calling setItemIndexMethod(NoIndex).

See also
bspTreeDepth

Definition at line 106 of file qgraphicsscene.h.

◆ palette

QPalette QGraphicsScene::palette
private

the scene's default palette

Since
4.4

This property provides the scene's palette. The scene palette defaults to, and resolves all its entries from, QApplication::palette.

If the scene's palette changes, either directly through setPalette() or indirectly when the application palette changes, QGraphicsScene first sends itself a PaletteChange event, and it then sends PaletteChange events to all top-level widget items in the scene. These items respond by resolving their own palettes to the scene, and they then notify their children, who again notify their children, and so on, until all widget items have updated their palettes.

Changing the scene palette, (directly or indirectly through QApplication::setPalette(),) automatically schedules a redraw the entire scene.

See also
QWidget::palette, QApplication::setPalette(), font, style()

Definition at line 109 of file qgraphicsscene.h.

Referenced by QGraphicsWidgetPrivate::naturalWidgetPalette().

◆ sceneRect

QRectF QGraphicsScene::sceneRect
private

the scene rectangle; the bounding rectangle of the scene

The scene rectangle defines the extent of the scene. It is primarily used by QGraphicsView to determine the view's default scrollable area, and by QGraphicsScene to manage item indexing.

If unset, or if set to a null QRectF, sceneRect() will return the largest bounding rect of all items on the scene since the scene was created (i.e., a rectangle that grows when items are added to or moved in the scene, but never shrinks).

See also
width(), height(), QGraphicsView::sceneRect

Definition at line 107 of file qgraphicsscene.h.

Referenced by QGraphicsViewPrivate::findItems(), and QWidgetPrivate::screenGeometry().

◆ sortCacheEnabled

QGraphicsScene::sortCacheEnabled
private

whether sort caching is enabled

Since
4.5

Since Qt 4.6, this property has no effect.

Definition at line 111 of file qgraphicsscene.h.

◆ stickyFocus

bool QGraphicsScene::stickyFocus
private

whether clicking into the scene background will clear focus

Since
4.6

In a QGraphicsScene with stickyFocus set to true, focus will remain unchanged when the user clicks into the scene background or on an item that does not accept focus. Otherwise, focus will be cleared.

By default, this property is false.

Focus changes in response to a mouse press. You can reimplement mousePressEvent() in a subclass of QGraphicsScene to toggle this property based on where the user has clicked.

See also
clearFocus(), setFocusItem()

Definition at line 112 of file qgraphicsscene.h.


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