27 Q_PROPERTY(QBrush backgroundBrush READ backgroundBrush WRITE setBackgroundBrush)
28 Q_PROPERTY(QBrush foregroundBrush READ foregroundBrush WRITE setForegroundBrush)
29 Q_PROPERTY(
bool interactive READ isInteractive WRITE setInteractive)
30 Q_PROPERTY(QRectF sceneRect READ sceneRect WRITE setSceneRect)
31 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
32 Q_PROPERTY(QPainter::RenderHints renderHints READ renderHints WRITE setRenderHints)
33 Q_PROPERTY(DragMode dragMode READ dragMode WRITE setDragMode)
34 Q_PROPERTY(CacheMode cacheMode READ cacheMode WRITE setCacheMode)
35 Q_PROPERTY(ViewportAnchor transformationAnchor READ transformationAnchor
36 WRITE setTransformationAnchor)
37 Q_PROPERTY(ViewportAnchor resizeAnchor READ resizeAnchor WRITE setResizeAnchor)
38 Q_PROPERTY(ViewportUpdateMode viewportUpdateMode READ viewportUpdateMode
39 WRITE setViewportUpdateMode)
40#if QT_CONFIG(rubberband)
41 Q_PROPERTY(Qt::ItemSelectionMode rubberBandSelectionMode READ rubberBandSelectionMode
42 WRITE setRubberBandSelectionMode)
44 Q_PROPERTY(OptimizationFlags optimizationFlags READ optimizationFlags
45 WRITE setOptimizationFlags)
53 Q_ENUM(ViewportAnchor)
59 Q_DECLARE_FLAGS(CacheMode, CacheModeFlag)
69 enum ViewportUpdateMode {
71 MinimalViewportUpdate,
74 BoundingRectViewportUpdate
76 Q_ENUM(ViewportUpdateMode)
78 enum OptimizationFlag {
79 DontSavePainterState = 0x1,
80 DontAdjustForAntialiasing = 0x2,
81 IndirectPainting = 0x4
83 Q_DECLARE_FLAGS(OptimizationFlags, OptimizationFlag)
84 Q_FLAG(OptimizationFlags)
86 QGraphicsView(QWidget *parent =
nullptr);
87 QGraphicsView(QGraphicsScene *scene, QWidget *parent =
nullptr);
90 QSize sizeHint()
const override;
92 QPainter::RenderHints renderHints()
const;
93 void setRenderHint(QPainter::RenderHint hint,
bool enabled =
true);
94 void setRenderHints(QPainter::RenderHints hints);
96 Qt::Alignment alignment()
const;
97 void setAlignment(Qt::Alignment alignment);
99 ViewportAnchor transformationAnchor()
const;
100 void setTransformationAnchor(ViewportAnchor anchor);
102 ViewportAnchor resizeAnchor()
const;
103 void setResizeAnchor(ViewportAnchor anchor);
105 ViewportUpdateMode viewportUpdateMode()
const;
106 void setViewportUpdateMode(ViewportUpdateMode mode);
108 OptimizationFlags optimizationFlags()
const;
109 void setOptimizationFlag(OptimizationFlag flag,
bool enabled =
true);
110 void setOptimizationFlags(OptimizationFlags flags);
112 DragMode dragMode()
const;
113 void setDragMode(DragMode mode);
115#if QT_CONFIG(rubberband)
116 Qt::ItemSelectionMode rubberBandSelectionMode()
const;
117 void setRubberBandSelectionMode(Qt::ItemSelectionMode mode);
118 QRect rubberBandRect()
const;
121 CacheMode cacheMode()
const;
122 void setCacheMode(CacheMode mode);
123 void resetCachedContent();
125 bool isInteractive()
const;
126 void setInteractive(
bool allowed);
128 QGraphicsScene *scene()
const;
129 void setScene(QGraphicsScene *scene);
131 QRectF sceneRect()
const;
132 void setSceneRect(
const QRectF &rect);
133 inline void setSceneRect(qreal x, qreal y, qreal w, qreal h);
135 QTransform transform()
const;
136 QTransform viewportTransform()
const;
137 bool isTransformed()
const;
138 void setTransform(
const QTransform &matrix,
bool combine =
false);
139 void resetTransform();
140 void rotate(qreal angle);
141 void scale(qreal sx, qreal sy);
142 void shear(qreal sh, qreal sv);
143 void translate(qreal dx, qreal dy);
145 void centerOn(
const QPointF &pos);
146 inline void centerOn(qreal x, qreal y);
147 void centerOn(
const QGraphicsItem *item);
148 void ensureVisible(
const QRectF &rect,
int xmargin = 50,
int ymargin = 50);
149 inline void ensureVisible(qreal x, qreal y, qreal w, qreal h,
int xmargin = 50,
int ymargin = 50);
150 void ensureVisible(
const QGraphicsItem *item,
int xmargin = 50,
int ymargin = 50);
151 void fitInView(
const QRectF &rect, Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
152 inline void fitInView(qreal x, qreal y, qreal w, qreal h,
153 Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
154 void fitInView(
const QGraphicsItem *item,
155 Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
157 void render(QPainter *painter,
const QRectF &target = QRectF(),
const QRect &source = QRect(),
158 Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio);
160 QList<QGraphicsItem *> items()
const;
161 QList<QGraphicsItem *> items(
const QPoint &pos)
const;
162 inline QList<QGraphicsItem *> items(
int x,
int y)
const;
163 QList<QGraphicsItem *> items(
const QRect &rect, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape)
const;
164 inline QList<QGraphicsItem *> items(
int x,
int y,
int w,
int h, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape)
const;
165 QList<QGraphicsItem *> items(
const QPolygon &polygon, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape)
const;
166 QList<QGraphicsItem *> items(
const QPainterPath &path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape)
const;
167 QGraphicsItem *itemAt(
const QPoint &pos)
const;
168 inline QGraphicsItem *itemAt(
int x,
int y)
const;
170 QPointF mapToScene(
const QPoint &point)
const;
171 QPolygonF mapToScene(
const QRect &rect)
const;
172 QPolygonF mapToScene(
const QPolygon &polygon)
const;
173 QPainterPath mapToScene(
const QPainterPath &path)
const;
174 QPoint mapFromScene(
const QPointF &point)
const;
175 QPolygon mapFromScene(
const QRectF &rect)
const;
176 QPolygon mapFromScene(
const QPolygonF &polygon)
const;
177 QPainterPath mapFromScene(
const QPainterPath &path)
const;
178 inline QPointF mapToScene(
int x,
int y)
const;
179 inline QPolygonF mapToScene(
int x,
int y,
int w,
int h)
const;
180 inline QPoint mapFromScene(qreal x, qreal y)
const;
181 inline QPolygon mapFromScene(qreal x, qreal y, qreal w, qreal h)
const;
183 QVariant inputMethodQuery(Qt::InputMethodQuery query)
const override;
185 QBrush backgroundBrush()
const;
186 void setBackgroundBrush(
const QBrush &brush);
188 QBrush foregroundBrush()
const;
189 void setForegroundBrush(
const QBrush &brush);
192 void updateScene(
const QList<QRectF> &rects);
193 void invalidateScene(
const QRectF &rect = QRectF(), QGraphicsScene::SceneLayers layers = QGraphicsScene::AllLayers);
194 void updateSceneRect(
const QRectF &rect);
196#if QT_CONFIG(rubberband)
198 void rubberBandChanged(QRect viewportRect, QPointF fromScenePoint, QPointF toScenePoint);
202 void setupViewport(QWidget *widget) override;
205 QGraphicsView(QGraphicsViewPrivate &, QWidget *parent =
nullptr);
206 bool event(QEvent *event) override;
207 bool viewportEvent(QEvent *event) override;
209#ifndef QT_NO_CONTEXTMENU
210 void contextMenuEvent(QContextMenuEvent *event) override;
212#if QT_CONFIG(draganddrop)
213 void dragEnterEvent(QDragEnterEvent *event) override;
214 void dragLeaveEvent(QDragLeaveEvent *event) override;
215 void dragMoveEvent(QDragMoveEvent *event) override;
216 void dropEvent(QDropEvent *event) override;
218 void focusInEvent(QFocusEvent *event) override;
219 bool focusNextPrevChild(
bool next) override;
220 void focusOutEvent(QFocusEvent *event) override;
221 void keyPressEvent(QKeyEvent *event) override;
222 void keyReleaseEvent(QKeyEvent *event) override;
223 void mouseDoubleClickEvent(QMouseEvent *event) override;
224 void mousePressEvent(QMouseEvent *event) override;
225 void mouseMoveEvent(QMouseEvent *event) override;
226 void mouseReleaseEvent(QMouseEvent *event) override;
227#if QT_CONFIG(wheelevent)
228 void wheelEvent(QWheelEvent *event) override;
230 void paintEvent(QPaintEvent *event) override;
231 void resizeEvent(QResizeEvent *event) override;
232 void scrollContentsBy(
int dx,
int dy) override;
233 void showEvent(QShowEvent *event) override;
234 void inputMethodEvent(QInputMethodEvent *event) override;
236 virtual void drawBackground(QPainter *painter,
const QRectF &rect);
237 virtual void drawForeground(QPainter *painter,
const QRectF &rect);
238 virtual void drawItems(QPainter *painter,
int numItems,
239 QGraphicsItem *items[],
240 const QStyleOptionGraphicsItem options[]);
243 Q_DECLARE_PRIVATE(QGraphicsView)
244 Q_DISABLE_COPY(QGraphicsView)
246 Q_PRIVATE_SLOT(d_func(),
void _q_setViewportCursor(
const QCursor &))
247 Q_PRIVATE_SLOT(d_func(),
void _q_unsetViewportCursor())
249 friend class QGraphicsSceneWidget;
250 friend class QGraphicsScene;
251 friend class QGraphicsScenePrivate;
252 friend class QGraphicsItemPrivate;