QtBase  v6.3.1
qgraphicsscene.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWidgets module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QGRAPHICSSCENE_H
41 #define QGRAPHICSSCENE_H
42 
43 #include <QtWidgets/qtwidgetsglobal.h>
44 #include <QtCore/qobject.h>
45 #include <QtCore/qpoint.h>
46 #include <QtCore/qrect.h>
47 #include <QtGui/qbrush.h>
48 #include <QtGui/qfont.h>
49 #include <QtGui/qtransform.h>
50 #include <QtGui/qpen.h>
51 
52 QT_REQUIRE_CONFIG(graphicsview);
53 
55 
56 class QFocusEvent;
57 class QFont;
58 class QFontMetrics;
60 class QGraphicsItem;
61 class QGraphicsItemGroup;
62 class QGraphicsLineItem;
63 class QGraphicsPathItem;
67 class QGraphicsRectItem;
76 class QGraphicsTextItem;
77 class QGraphicsView;
78 class QGraphicsWidget;
80 class QHelpEvent;
81 class QInputMethodEvent;
82 class QKeyEvent;
83 class QLineF;
84 class QPainterPath;
85 class QPixmap;
86 class QPointF;
87 class QPolygonF;
88 class QRectF;
89 class QSizeF;
90 class QStyle;
92 
94 class Q_WIDGETS_EXPORT QGraphicsScene : public QObject
95 {
96  Q_OBJECT
97  Q_PROPERTY(QBrush backgroundBrush READ backgroundBrush WRITE setBackgroundBrush)
98  Q_PROPERTY(QBrush foregroundBrush READ foregroundBrush WRITE setForegroundBrush)
99  Q_PROPERTY(ItemIndexMethod itemIndexMethod READ itemIndexMethod WRITE setItemIndexMethod)
100  Q_PROPERTY(QRectF sceneRect READ sceneRect WRITE setSceneRect)
101  Q_PROPERTY(int bspTreeDepth READ bspTreeDepth WRITE setBspTreeDepth)
102  Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
103  Q_PROPERTY(QFont font READ font WRITE setFont)
104  Q_PROPERTY(bool stickyFocus READ stickyFocus WRITE setStickyFocus)
105  Q_PROPERTY(qreal minimumRenderSize READ minimumRenderSize WRITE setMinimumRenderSize)
106  Q_PROPERTY(bool focusOnTouch READ focusOnTouch WRITE setFocusOnTouch)
107 
108 public:
111  NoIndex = -1
112  };
113  Q_ENUM(ItemIndexMethod)
114  enum SceneLayer {
115  ItemLayer = 0x1,
116  BackgroundLayer = 0x2,
117  ForegroundLayer = 0x4,
118  AllLayers = 0xffff
119  };
120  Q_DECLARE_FLAGS(SceneLayers, SceneLayer)
121 
122  QGraphicsScene(QObject *parent = nullptr);
123  QGraphicsScene(const QRectF &sceneRect, QObject *parent = nullptr);
125  virtual ~QGraphicsScene();
126 
127  QRectF sceneRect() const;
128  inline qreal width() const { return sceneRect().width(); }
129  inline qreal height() const { return sceneRect().height(); }
130  void setSceneRect(const QRectF &rect);
131  inline void setSceneRect(qreal x, qreal y, qreal w, qreal h)
132  { setSceneRect(QRectF(x, y, w, h)); }
133 
134  void render(QPainter *painter,
135  const QRectF &target = QRectF(), const QRectF &source = QRectF(),
136  Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio);
137 
138  ItemIndexMethod itemIndexMethod() const;
139  void setItemIndexMethod(ItemIndexMethod method);
140 
141  int bspTreeDepth() const;
142  void setBspTreeDepth(int depth);
143 
144  QRectF itemsBoundingRect() const;
145 
147 
153  const QTransform &deviceTransform = QTransform()) const
154  { return items(QRectF(x, y, w, h), mode, order, deviceTransform); }
155 
157  QGraphicsItem *itemAt(const QPointF &pos, const QTransform &deviceTransform) const;
159  { return itemAt(QPointF(x, y), deviceTransform); }
160 
161  QList<QGraphicsItem *> selectedItems() const;
162  QPainterPath selectionArea() const;
163  void setSelectionArea(const QPainterPath &path, const QTransform &deviceTransform);
165 
166  QGraphicsItemGroup *createItemGroup(const QList<QGraphicsItem *> &items);
168 
169  void addItem(QGraphicsItem *item);
170  QGraphicsEllipseItem *addEllipse(const QRectF &rect, const QPen &pen = QPen(), const QBrush &brush = QBrush());
171  QGraphicsLineItem *addLine(const QLineF &line, const QPen &pen = QPen());
172  QGraphicsPathItem *addPath(const QPainterPath &path, const QPen &pen = QPen(), const QBrush &brush = QBrush());
173  QGraphicsPixmapItem *addPixmap(const QPixmap &pixmap);
174  QGraphicsPolygonItem *addPolygon(const QPolygonF &polygon, const QPen &pen = QPen(), const QBrush &brush = QBrush());
175  QGraphicsRectItem *addRect(const QRectF &rect, const QPen &pen = QPen(), const QBrush &brush = QBrush());
176  QGraphicsTextItem *addText(const QString &text, const QFont &font = QFont());
177  QGraphicsSimpleTextItem *addSimpleText(const QString &text, const QFont &font = QFont());
178  QGraphicsProxyWidget *addWidget(QWidget *widget, Qt::WindowFlags wFlags = Qt::WindowFlags());
179  inline QGraphicsEllipseItem *addEllipse(qreal x, qreal y, qreal w, qreal h, const QPen &pen = QPen(), const QBrush &brush = QBrush())
180  { return addEllipse(QRectF(x, y, w, h), pen, brush); }
182  { return addLine(QLineF(x1, y1, x2, y2), pen); }
183  inline QGraphicsRectItem *addRect(qreal x, qreal y, qreal w, qreal h, const QPen &pen = QPen(), const QBrush &brush = QBrush())
184  { return addRect(QRectF(x, y, w, h), pen, brush); }
185  void removeItem(QGraphicsItem *item);
186 
187  QGraphicsItem *focusItem() const;
188  void setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReason = Qt::OtherFocusReason);
189  bool hasFocus() const;
190  void setFocus(Qt::FocusReason focusReason = Qt::OtherFocusReason);
191  void clearFocus();
192 
193  void setStickyFocus(bool enabled);
194  bool stickyFocus() const;
195 
196  QGraphicsItem *mouseGrabberItem() const;
197 
198  QBrush backgroundBrush() const;
199  void setBackgroundBrush(const QBrush &brush);
200 
201  QBrush foregroundBrush() const;
202  void setForegroundBrush(const QBrush &brush);
203 
204  virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
205 
206  QList <QGraphicsView *> views() const;
207 
208  inline void update(qreal x, qreal y, qreal w, qreal h)
209  { update(QRectF(x, y, w, h)); }
210  inline void invalidate(qreal x, qreal y, qreal w, qreal h, SceneLayers layers = AllLayers)
211  { invalidate(QRectF(x, y, w, h), layers); }
212 
213  QStyle *style() const;
214  void setStyle(QStyle *style);
215 
216  QFont font() const;
217  void setFont(const QFont &font);
218 
219  QPalette palette() const;
220  void setPalette(const QPalette &palette);
221 
222  bool isActive() const;
223  QGraphicsItem *activePanel() const;
224  void setActivePanel(QGraphicsItem *item);
225  QGraphicsWidget *activeWindow() const;
226  void setActiveWindow(QGraphicsWidget *widget);
227 
228  bool sendEvent(QGraphicsItem *item, QEvent *event);
229 
230  qreal minimumRenderSize() const;
231  void setMinimumRenderSize(qreal minSize);
232 
233  bool focusOnTouch() const;
234  void setFocusOnTouch(bool enabled);
235 
236 public Q_SLOTS:
237  void update(const QRectF &rect = QRectF());
238  void invalidate(const QRectF &rect = QRectF(), SceneLayers layers = AllLayers);
239  void advance();
240  void clearSelection();
241  void clear();
242 
243 protected:
244  bool event(QEvent *event) override;
245  bool eventFilter(QObject *watched, QEvent *event) override;
246  virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
247  virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
248  virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
249  virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
250  virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
251  virtual void focusInEvent(QFocusEvent *event);
252  virtual void focusOutEvent(QFocusEvent *event);
253  virtual void helpEvent(QGraphicsSceneHelpEvent *event);
254  virtual void keyPressEvent(QKeyEvent *event);
255  virtual void keyReleaseEvent(QKeyEvent *event);
256  virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
257  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
258  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
259  virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
260  virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
261  virtual void inputMethodEvent(QInputMethodEvent *event);
262 
263  virtual void drawBackground(QPainter *painter, const QRectF &rect);
264  virtual void drawForeground(QPainter *painter, const QRectF &rect);
265  virtual void drawItems(QPainter *painter, int numItems,
266  QGraphicsItem *items[],
267  const QStyleOptionGraphicsItem options[],
268  QWidget *widget = nullptr);
269 
270 protected Q_SLOTS:
271  virtual bool focusNextPrevChild(bool next);
272 
273 Q_SIGNALS:
274  void changed(const QList<QRectF> &region);
277  void focusItemChanged(QGraphicsItem *newFocus, QGraphicsItem *oldFocus, Qt::FocusReason reason);
278 
279 private:
280  Q_DECLARE_PRIVATE(QGraphicsScene)
282  Q_PRIVATE_SLOT(d_func(), void _q_emitUpdated())
283  Q_PRIVATE_SLOT(d_func(), void _q_polishItems())
284  Q_PRIVATE_SLOT(d_func(), void _q_processDirtyItems())
285  Q_PRIVATE_SLOT(d_func(), void _q_updateScenePosDescendants())
286  friend class QGraphicsItem;
287  friend class QGraphicsItemPrivate;
288  friend class QGraphicsObject;
289  friend class QGraphicsView;
290  friend class QGraphicsViewPrivate;
291  friend class QGraphicsWidget;
293  friend class QGraphicsEffect;
294  friend class QGraphicsSceneIndex;
298  friend class QGraphicsItemEffectSourcePrivate;
299 #ifndef QT_NO_GESTURES
300  friend class QGesture;
301 #endif
302 };
303 
304 Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsScene::SceneLayers)
305 
307 
308 #endif
Arabic default style
Definition: afstyles.h:94
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:66
The QEvent class is the base class of all event classes. Event objects contain event parameters.
Definition: qcoreevent.h:58
The QFocusEvent class contains event parameters for widget focus events. \inmodule QtGui.
Definition: qevent.h:520
The QFont class specifies a query for a font used for drawing text.
Definition: qfont.h:56
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:56
The QGesture class represents a gesture, containing properties that describe the corresponding user i...
Definition: qgesture.h:62
The QGraphicsEffect class is the base class for all graphics effects.
The QGraphicsEllipseItem class provides an ellipse item that you can add to a QGraphicsScene.
The QGraphicsItemGroup class provides a container that treats a group of items as a single item.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:83
The QGraphicsLineItem class provides a line item that you can add to a QGraphicsScene.
The QGraphicsObject class provides a base class for all graphics items that require signals,...
The QGraphicsPixmapItem class provides a pixmap item that you can add to a QGraphicsScene.
The QGraphicsPolygonItem class provides a polygon item that you can add to a QGraphicsScene.
The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene.
The QGraphicsRectItem class provides a rectangle item that you can add to a QGraphicsScene.
The QGraphicsSceneBspTreeIndex class provides an implementation of a BSP indexing algorithm for disco...
The QGraphicsSceneContextMenuEvent class provides context menu events in the graphics view framework.
The QGraphicsSceneDragDropEvent class provides events for drag and drop in the graphics view framewor...
The QGraphicsSceneEvent class provides a base class for all graphics view related events.
The QGraphicsSceneHelpEvent class provides events when a tooltip is requested.
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
QGraphicsEllipseItem * addEllipse(qreal x, qreal y, qreal w, qreal h, const QPen &pen=QPen(), const QBrush &brush=QBrush())
void changed(const QList< QRectF > &region)
qreal height() const
void setSceneRect(qreal x, qreal y, qreal w, qreal h)
qreal width() 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 ...
void invalidate(qreal x, qreal y, qreal w, qreal h, SceneLayers layers=AllLayers)
void update(qreal x, qreal y, qreal w, qreal h)
void selectionChanged()
void sceneRectChanged(const QRectF &rect)
void focusItemChanged(QGraphicsItem *newFocus, QGraphicsItem *oldFocus, Qt::FocusReason reason)
QGraphicsItem * itemAt(qreal x, qreal y, const QTransform &deviceTransform) const
QGraphicsRectItem * addRect(qreal x, qreal y, qreal w, qreal h, const QPen &pen=QPen(), const QBrush &brush=QBrush())
QGraphicsLineItem * addLine(qreal x1, qreal y1, qreal x2, qreal y2, const QPen &pen=QPen())
The QGraphicsSceneIndex class provides a base class to implement a custom indexing algorithm for disc...
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
The QGraphicsSceneWheelEvent class provides wheel events in the graphics view framework.
The QGraphicsSimpleTextItem class provides a simple text path item that you can add to a QGraphicsSce...
The QGraphicsTextItem class provides a text item that you can add to a QGraphicsScene to display form...
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:60
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition: qevent.h:873
The QInputMethodEvent class provides parameters for input method events. \inmodule QtGui.
Definition: qevent.h:696
The QKeyEvent class describes a key event.
Definition: qevent.h:471
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:215
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
virtual bool event(QEvent *event)
Definition: qobject.cpp:1329
virtual bool eventFilter(QObject *watched, QEvent *event)
Definition: qobject.cpp:1484
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:82
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:65
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:55
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:61
The QPixmap class is an off-screen image representation that can be used as a paint device.
Definition: qpixmap.h:63
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
The QPolygonF class provides a list of points using floating point precision. \inmodule QtGui.
Definition: qpolygon.h:128
The QRectF class defines a finite rectangle in the plane using floating point precision.
Definition: qrect.h:511
The QSizeF class defines the size of a two-dimensional object using floating point precision.
Definition: qsize.h:235
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition: qstyle.h:65
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem.
Definition: qstyleoption.h:684
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:56
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:95
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
QOpenGLWidget * widget
[1]
b clear()
rect
[4]
palette
short next
Definition: keywords.cpp:454
InputMethodQuery
Definition: qnamespace.h:1380
AspectRatioMode
Definition: qnamespace.h:1211
@ KeepAspectRatio
Definition: qnamespace.h:1213
ItemSelectionOperation
Definition: qnamespace.h:1344
@ ReplaceSelection
Definition: qnamespace.h:1345
SortOrder
Definition: qnamespace.h:146
@ DescendingOrder
Definition: qnamespace.h:148
ItemSelectionMode
Definition: qnamespace.h:1337
@ IntersectsItemShape
Definition: qnamespace.h:1339
FocusReason
Definition: qnamespace.h:1360
@ OtherFocusReason
Definition: qnamespace.h:1368
Definition: brush.cpp:52
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char * method
const EGLAttrib EGLOutputLayerEXT * layers
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition: qflags.h:210
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition: qflags.h:227
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
#define Q_DISABLE_COPY(Class)
Definition: qglobal.h:515
QT_REQUIRE_CONFIG(graphicsview)
@ text
GLint GLint GLint GLint GLint x
[0]
GLint GLenum GLsizei GLsizei GLsizei depth
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLuint GLfloat GLfloat GLfloat GLfloat y1
GLuint GLfloat GLfloat GLfloat x1
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLint GLsizei width
GLboolean GLuint group
GLenum target
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLsizei GLchar * source
struct _cl_event * event
Definition: qopenglext.h:2998
GLenum query
Definition: qopenglext.h:2738
GLfixed GLfixed GLfixed y2
Definition: qopenglext.h:5231
GLfixed GLfixed x2
Definition: qopenglext.h:5231
GLsizei const GLchar *const * path
Definition: qopenglext.h:4283
GLfixed GLfixed GLint GLint order
Definition: qopenglext.h:5206
#define Q_ENUM(x)
Definition: qtmetamacros.h:104
#define Q_PROPERTY(...)
Definition: qtmetamacros.h:92
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define Q_SLOTS
Definition: qtmetamacros.h:80
#define Q_PRIVATE_SLOT(d, signature)
Definition: qtmetamacros.h:82
#define Q_SIGNALS
Definition: qtmetamacros.h:81
layout addItem(textEdit, 0, 0)
QGraphicsItem * item
scene destroyItemGroup(group)
rect deviceTransform(view->viewportTransform()).map(QPointF(0
scene addText("Hello, world!")
view setBackgroundBrush(QImage(":/images/backgroundtile.png"))
scene addRect(QRectF(-10, -10, 20, 20))
QList< QTreeWidgetItem * > items
gridLayout addWidget(nameLabel, 0, 0)
widget render & pixmap
QPainter painter(this)
[7]
setFont(font)
myWidget render(this)
widget setStyle(proxy)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent