CopperSpice API  1.9.1
QGraphicsView Class Reference

The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene. More...

Inheritance diagram for QGraphicsView:
QAbstractScrollArea QFrame QWidget QObject QPaintDevice

Public Typedefs

using CacheMode = QFlags< CacheModeFlag >
 
using OptimizationFlags = QFlags< OptimizationFlag >
 
- Public Typedefs inherited from QWidget
using RenderFlags = QFlags< RenderFlag >
 

Public Types

enum  CacheModeFlag
 
enum  DragMode
 
enum  OptimizationFlag
 
enum  ViewportAnchor
 
enum  ViewportUpdateMode
 
- Public Types inherited from QFrame
enum  Shadow
 
enum  Shape
 
enum  StyleMask
 
- Public Types inherited from QWidget
enum  RenderFlag
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric
 

Public Signals

void rubberBandChanged (QRect viewportRect, QPointF fromScenePoint, QPointF toScenePoint)
 
- Public Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 
void windowIconChanged (const QIcon &icon)
 
void windowIconTextChanged (const QString &iconText)
 
void windowTitleChanged (const QString &title)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Slots

void invalidateScene (const QRectF &rect=QRectF (), QGraphicsScene::SceneLayers layers=QGraphicsScene::AllLayers)
 
void updateScene (const QList< QRectF > &rects)
 
void updateSceneRect (const QRectF &rect)
 
- Public Slots inherited from QWidget
bool close ()
 
void hide ()
 
void lower ()
 
void raise ()
 
void repaint ()
 
void setDisabled (bool disable)
 
void setEnabled (bool enable)
 
void setFocus ()
 
void setHidden (bool hidden)
 
void setStyleSheet (const QString &styleSheet)
 
virtual void setVisible (bool visible)
 
void setWindowModified (bool modified)
 
void setWindowTitle (const QString &title)
 
void show ()
 
void showFullScreen ()
 
void showMaximized ()
 
void showMinimized ()
 
void showNormal ()
 
void update ()
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QGraphicsView (QGraphicsScene *scene, QWidget *parent=nullptr)
 
 QGraphicsView (QWidget *parent=nullptr)
 
 ~QGraphicsView ()
 
Qt::Alignment alignment () const
 
QBrush backgroundBrush () const
 
CacheMode cacheMode () const
 
void centerOn (const QGraphicsItem *item)
 
void centerOn (const QPointF &pos)
 
void centerOn (qreal x, qreal y)
 
DragMode dragMode () const
 
void ensureVisible (const QGraphicsItem *item, int xmargin=50, int ymargin=50)
 
void ensureVisible (const QRectF &rect, int xmargin=50, int ymargin=50)
 
void ensureVisible (qreal x, qreal y, qreal width, qreal height, int xmargin=50, int ymargin=50)
 
void fitInView (const QGraphicsItem *item, Qt::AspectRatioMode mode=Qt::IgnoreAspectRatio)
 
void fitInView (const QRectF &rect, Qt::AspectRatioMode mode=Qt::IgnoreAspectRatio)
 
void fitInView (qreal x, qreal y, qreal width, qreal height, Qt::AspectRatioMode mode=Qt::IgnoreAspectRatio)
 
QBrush foregroundBrush () const
 
QVariant inputMethodQuery (Qt::InputMethodQuery query) const override
 
bool isInteractive () const
 
bool isTransformed () const
 
QGraphicsItemitemAt (const QPoint &pos) const
 
QGraphicsItemitemAt (int x, int y) const
 
QList< QGraphicsItem * > items () const
 
QList< QGraphicsItem * > items (const QPainterPath &path, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 
QList< QGraphicsItem * > items (const QPoint &pos) const
 
QList< QGraphicsItem * > items (const QPolygon &polygon, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 
QList< QGraphicsItem * > items (const QRect &rect, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 
QList< QGraphicsItem * > items (int x, int y) const
 
QList< QGraphicsItem * > items (int x, int y, int width, int height, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 
QPainterPath mapFromScene (const QPainterPath &path) const
 
QPoint mapFromScene (const QPointF &point) const
 
QPolygon mapFromScene (const QPolygonF &polygon) const
 
QPolygon mapFromScene (const QRectF &rect) const
 
QPoint mapFromScene (qreal x, qreal y) const
 
QPolygon mapFromScene (qreal x, qreal y, qreal width, qreal height) const
 
QPainterPath mapToScene (const QPainterPath &path) const
 
QPointF mapToScene (const QPoint &point) const
 
QPolygonF mapToScene (const QPolygon &polygon) const
 
QPolygonF mapToScene (const QRect &rect) const
 
QPointF mapToScene (int x, int y) const
 
QPolygonF mapToScene (int x, int y, int width, int height) const
 
QMatrix matrix () const
 
OptimizationFlags optimizationFlags () const
 
void render (QPainter *painter, const QRectF &target=QRectF (), const QRect &source=QRect (), Qt::AspectRatioMode mode=Qt::KeepAspectRatio)
 
QPainter::RenderHints renderHints () const
 
void resetCachedContent ()
 
void resetMatrix ()
 
void resetTransform ()
 
ViewportAnchor resizeAnchor () const
 
void rotate (qreal angle)
 
QRect rubberBandRect () const
 
Qt::ItemSelectionMode rubberBandSelectionMode () const
 
void scale (qreal sx, qreal sy)
 
QGraphicsScenescene () const
 
QRectF sceneRect () const
 
void setAlignment (Qt::Alignment alignment)
 
void setBackgroundBrush (const QBrush &brush)
 
void setCacheMode (CacheMode mode)
 
void setDragMode (DragMode mode)
 
void setForegroundBrush (const QBrush &brush)
 
void setInteractive (bool allowed)
 
void setMatrix (const QMatrix &matrix, bool combine=false)
 
void setOptimizationFlag (OptimizationFlag flag, bool enabled=true)
 
void setOptimizationFlags (OptimizationFlags flags)
 
void setRenderHint (QPainter::RenderHint hint, bool enabled=true)
 
void setRenderHints (QPainter::RenderHints hints)
 
void setResizeAnchor (ViewportAnchor anchor)
 
void setRubberBandSelectionMode (Qt::ItemSelectionMode mode)
 
void setScene (QGraphicsScene *scene)
 
void setSceneRect (const QRectF &rect)
 
void setSceneRect (qreal x, qreal y, qreal width, qreal height)
 
void setTransform (const QTransform &matrix, bool combine=false)
 
void setTransformationAnchor (ViewportAnchor anchor)
 
void setViewportUpdateMode (ViewportUpdateMode mode)
 
void shear (qreal sh, qreal sv)
 
QSize sizeHint () const override
 
QTransform transform () const
 
ViewportAnchor transformationAnchor () const
 
void translate (qreal dx, qreal dy)
 
QTransform viewportTransform () const
 
ViewportUpdateMode viewportUpdateMode () const
 
- Public Methods inherited from QAbstractScrollArea
 QAbstractScrollArea (QWidget *parent=nullptr)
 
 ~QAbstractScrollArea ()
 
void addScrollBarWidget (QWidget *widget, Qt::Alignment alignment)
 
QWidgetcornerWidget () const
 
QScrollBarhorizontalScrollBar () const
 
Qt::ScrollBarPolicy horizontalScrollBarPolicy () const
 
QSize maximumViewportSize () const
 
QSize minimumSizeHint () const override
 
QWidgetList scrollBarWidgets (Qt::Alignment alignment)
 
void setCornerWidget (QWidget *widget)
 
void setHorizontalScrollBar (QScrollBar *scrollBar)
 
void setHorizontalScrollBarPolicy (Qt::ScrollBarPolicy policy)
 
void setSizeAdjustPolicy (SizeAdjustPolicy policy)
 
virtual void setupViewport (QWidget *viewport)
 
void setVerticalScrollBar (QScrollBar *scrollBar)
 
void setVerticalScrollBarPolicy (Qt::ScrollBarPolicy policy)
 
void setViewport (QWidget *widget)
 
SizeAdjustPolicy sizeAdjustPolicy () const
 
QSize sizeHint () const override
 
QScrollBarverticalScrollBar () const
 
Qt::ScrollBarPolicy verticalScrollBarPolicy () const
 
QWidgetviewport () const
 
- Public Methods inherited from QFrame
 QFrame (QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
 ~QFrame ()
 
QRect frameRect () const
 
Shadow frameShadow () const
 
Shape frameShape () const
 
int frameStyle () const
 
int frameWidth () const
 
int lineWidth () const
 
int midLineWidth () const
 
void setFrameRect (const QRect &rect)
 
void setFrameShadow (Shadow value)
 
void setFrameShape (Shape value)
 
void setFrameStyle (int style)
 
void setLineWidth (int width)
 
void setMidLineWidth (int width)
 
QSize sizeHint () const override
 
- Public Methods inherited from QWidget
 QWidget (QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
 ~QWidget ()
 
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 
void activateWindow ()
 
void addAction (QAction *action)
 
void addActions (const QList< QAction * > &actions)
 
void adjustSize ()
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 
QBackingStorebackingStore () const
 
QSize baseSize () const
 
QWidget * childAt (const QPoint &position) const
 
QWidget * childAt (int x, int y) const
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 
void clearMask ()
 
QMargins contentsMargins () const
 
QRect contentsRect () const
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
QCursor cursor () const
 
WId effectiveWinId () const
 
void ensurePolished () const
 
Qt::FocusPolicy focusPolicy () const
 
QWidget * focusProxy () const
 
QWidget * focusWidget () const
 
const QFontfont () const
 
QFontInfo fontInfo () const
 
QFontMetrics fontMetrics () const
 
QPalette::ColorRole foregroundRole () const
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 
QPixmap grab (const QRect &rectangle=QRect (QPoint (0, 0), QSize (-1,-1)))
 
void grabGesture (Qt::GestureType gestureType, Qt::GestureFlags flags=Qt::GestureFlags ())
 
void grabKeyboard ()
 
void grabMouse ()
 
void grabMouse (const QCursor &cursor)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 
QGraphicsEffectgraphicsEffect () const
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 
bool hasEditFocus () const
 
bool hasFocus () const
 
virtual bool hasHeightForWidth () const
 
bool hasMouseTracking () const
 
int height () const
 
virtual int heightForWidth (int width) const
 
Qt::InputMethodHints inputMethodHints () const
 
void insertAction (QAction *before, QAction *action)
 
void insertActions (QAction *before, QList< QAction * > actions)
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 
bool isEnabled () const
 
bool isEnabledTo (const QWidget *parent) const
 
bool isEnabledToTLW () const
 
bool isFullScreen () const
 
bool isHidden () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isTopLevel () const
 
bool isVisible () const
 
bool isVisibleTo (const QWidget *parent) const
 
bool isWindow () const
 
bool isWindowModified () const
 
QLayoutlayout () const
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
QPoint mapFrom (const QWidget *parent, const QPoint &pos) const
 
QPoint mapFromGlobal (const QPoint &pos) const
 
QPoint mapFromParent (const QPoint &pos) const
 
QPoint mapTo (const QWidget *parent, const QPoint &pos) const
 
QPoint mapToGlobal (const QPoint &pos) const
 
QPoint mapToParent (const QPoint &pos) const
 
QRegion mask () const
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
int minimumWidth () const
 
void move (const QPoint &point)
 
void move (int x, int y)
 
QWidget * nativeParentWidget () const
 
QWidget * nextInFocusChain () const
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags flags)
 
QPaintEnginepaintEngine () const override
 
const QPalettepalette () const
 
QWidget * parentWidget () const
 
QPoint pos () const
 
QWidget * previousInFocusChain () const
 
QRect rect () const
 
void releaseKeyboard ()
 
void releaseMouse ()
 
void releaseShortcut (int id)
 
void removeAction (QAction *action)
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void repaint (const QRect &rect)
 
void repaint (const QRegion &region)
 
void repaint (int x, int y, int w, int h)
 
void resize (const QSize &size)
 
void resize (int w, int h)
 
bool restoreGeometry (const QByteArray &geometry)
 
QByteArray saveGeometry () const
 
void scroll (int dx, int dy)
 
void scroll (int dx, int dy, const QRect &rect)
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute attribute, bool enable=true)
 
void setAutoFillBackground (bool enable)
 
void setBackgroundRole (QPalette::ColorRole role)
 
void setBaseSize (const QSize &size)
 
void setBaseSize (int basew, int baseh)
 
void setContentsMargins (const QMargins &margins)
 
void setContentsMargins (int left, int top, int right, int bottom)
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &cursor)
 
void setEditFocus (bool enable)
 
void setFixedHeight (int h)
 
void setFixedSize (const QSize &size)
 
void setFixedSize (int w, int h)
 
void setFixedWidth (int w)
 
void setFocus (Qt::FocusReason reason)
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *widget)
 
void setFont (const QFont &font)
 
void setForegroundRole (QPalette::ColorRole role)
 
void setGeometry (const QRect &rect)
 
void setGeometry (int x, int y, int w, int h)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *layout)
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &bitmap)
 
void setMask (const QRegion &region)
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &size)
 
void setMaximumSize (int maxw, int maxh)
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &size)
 
void setMinimumSize (int minw, int minh)
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &palette)
 
void setParent (QWidget *parent)
 
void setParent (QWidget *parent, Qt::WindowFlags flags)
 
void setShortcutAutoRepeat (int id, bool enable=true)
 
void setShortcutEnabled (int id, bool enable=true)
 
void setSizeIncrement (const QSize &size)
 
void setSizeIncrement (int w, int h)
 
void setSizePolicy (QSizePolicy policy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 
void setStatusTip (const QString &data)
 
void setStyle (QStyle *style)
 
void setToolTip (const QString &data)
 
void setToolTipDuration (int msec)
 
void setUpdatesEnabled (bool enable)
 
void setWhatsThis (const QString &str)
 
void setWindowFilePath (const QString &filePath)
 
void setWindowFlags (Qt::WindowFlags flags)
 
void setWindowIcon (const QIcon &icon)
 
void setWindowModality (Qt::WindowModality windowModality)
 
void setWindowOpacity (qreal level)
 
void setWindowRole (const QString &role)
 
void setWindowState (Qt::WindowStates windowState)
 
QSize size () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *widget)
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute attribute) const
 
QString toolTip () const
 
int toolTipDuration () const
 
QWidget * topLevelWidget () const
 
bool underMouse () const
 
void ungrabGesture (Qt::GestureType gestureType)
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (const QRect &rect)
 
void update (const QRegion &region)
 
void update (int x, int y, int w, int h)
 
void updateGeometry ()
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 
QString whatsThis () const
 
int width () const
 
QWidget * window () const
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 
QWindowwindowHandle () const
 
QIcon windowIcon () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 
Qt::WindowStates windowState () const
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 
WId winId () const
 
int x () const
 
int y () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 
- Public Methods inherited from QPaintDevice
virtual ~QPaintDevice ()
 
int colorCount () const
 
int depth () const
 
int devicePixelRatio () const
 
qreal devicePixelRatioF () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 

Protected Slots

void setupViewport (QWidget *widget)
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 

Protected Methods

void contextMenuEvent (QContextMenuEvent *event) override
 
void dragEnterEvent (QDragEnterEvent *event) override
 
void dragLeaveEvent (QDragLeaveEvent *event) override
 
void dragMoveEvent (QDragMoveEvent *event) override
 
virtual void drawBackground (QPainter *painter, const QRectF &rect)
 
virtual void drawForeground (QPainter *painter, const QRectF &rect)
 
virtual void drawItems (QPainter *painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem options[])
 
void dropEvent (QDropEvent *event) override
 
bool event (QEvent *event) override
 
void focusInEvent (QFocusEvent *event) override
 
bool focusNextPrevChild (bool next) override
 
void focusOutEvent (QFocusEvent *event) override
 
void inputMethodEvent (QInputMethodEvent *event) override
 
void keyPressEvent (QKeyEvent *event) override
 
void keyReleaseEvent (QKeyEvent *event) override
 
void mouseDoubleClickEvent (QMouseEvent *event) override
 
void mouseMoveEvent (QMouseEvent *event) override
 
void mousePressEvent (QMouseEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 
void paintEvent (QPaintEvent *event) override
 
void resizeEvent (QResizeEvent *event) override
 
void scrollContentsBy (int dx, int dy) override
 
void showEvent (QShowEvent *event) override
 
bool viewportEvent (QEvent *event) override
 
void wheelEvent (QWheelEvent *event) override
 
- Protected Methods inherited from QAbstractScrollArea
void contextMenuEvent (QContextMenuEvent *event) override
 
void dragEnterEvent (QDragEnterEvent *event) override
 
void dragLeaveEvent (QDragLeaveEvent *event) override
 
void dragMoveEvent (QDragMoveEvent *event) override
 
void dropEvent (QDropEvent *event) override
 
bool event (QEvent *event) override
 
void keyPressEvent (QKeyEvent *event) override
 
void mouseDoubleClickEvent (QMouseEvent *event) override
 
void mouseMoveEvent (QMouseEvent *event) override
 
void mousePressEvent (QMouseEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 
void paintEvent (QPaintEvent *event) override
 
void resizeEvent (QResizeEvent *event) override
 
void setViewportMargins (const QMargins &margins)
 
void setViewportMargins (int left, int top, int right, int bottom)
 
QMargins viewportMargins () const
 
virtual QSize viewportSizeHint () const
 
void wheelEvent (QWheelEvent *event) override
 
- Protected Methods inherited from QFrame
void changeEvent (QEvent *event) override
 
void drawFrame (QPainter *painter)
 
bool event (QEvent *event) override
 
void initStyleOption (QStyleOptionFrame *option) const
 
void paintEvent (QPaintEvent *event) override
 
- Protected Methods inherited from QWidget
virtual void actionEvent (QActionEvent *event)
 
virtual void closeEvent (QCloseEvent *event)
 
void create (WId window=0, bool initializeWindow=true, bool destroyOldWindow=true)
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 
virtual void enterEvent (QEvent *event)
 
bool event (QEvent *event) override
 
bool focusNextChild ()
 
bool focusPreviousChild ()
 
virtual void hideEvent (QHideEvent *event)
 
void initPainter (QPainter *painter) const override
 
virtual void leaveEvent (QEvent *event)
 
int metric (PaintDeviceMetric metric) const override
 
virtual void moveEvent (QMoveEvent *event)
 
virtual bool nativeEvent (const QByteArray &eventType, void *message, long *result)
 
virtual void tabletEvent (QTabletEvent *event)
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Protected Methods inherited from QPaintDevice
 QPaintDevice ()
 

Properties

 alignment
 
 backgroundBrush
 
 cacheMode
 
 dragMode
 
 foregroundBrush
 
 interactive
 
 optimizationFlags
 
 renderHints
 
 resizeAnchor
 
 rubberBandSelectionMode
 
 sceneRect
 
 transformationAnchor
 
 viewportUpdateMode
 
- Properties inherited from QAbstractScrollArea
 horizontalScrollBarPolicy
 
 verticalScrollBarPolicy
 
- Properties inherited from QFrame
 frameRect
 
 frameShadow
 
 frameShape
 
 frameWidth
 
 lineWidth
 
 midLineWidth
 
- Properties inherited from QWidget
 acceptDrops
 
 accessibleDescription
 
 accessibleName
 
 autoFillBackground
 
 baseSize
 
 childrenRect
 
 childrenRegion
 
 contextMenuPolicy
 
 cursor
 
 enabled
 
 focus
 
 focusPolicy
 
 font
 
 frameGeometry
 
 frameSize
 
 fullScreen
 
 geometry
 
 height
 
 inputMethodHints
 
 isActiveWindow
 
 layoutDirection
 
 locale
 
 maximized
 
 maximumHeight
 
 maximumSize
 
 maximumWidth
 
 minimized
 
 minimumHeight
 
 minimumSize
 
 minimumSizeHint
 
 minimumWidth
 
 modal
 
 mouseTracking
 
 normalGeometry
 
 palette
 
 pos
 
 rect
 
 size
 
 sizeHint
 
 sizeIncrement
 
 sizePolicy
 
 statusTip
 
 styleSheet
 
 toolTip
 
 updatesEnabled
 
 visible
 
 whatsThis
 
 width
 
 windowFilePath
 
 windowFlags
 
 windowIcon
 
 windowIconText
 
 windowModality
 
 windowModified
 
 windowOpacity
 
 windowTitle
 
 x
 
 y
 
- Properties inherited from QObject
 objectName
 

Friends

class QGraphicsScene
 

Additional Inherited Members

- Static Public Methods inherited from QWidget
static QWidget * createWindowContainer (QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
static QWidget * find (WId id)
 
static QWidget * keyboardGrabber ()
 
static QWidget * mouseGrabber ()
 
static void setTabOrder (QWidget *firstWidget, QWidget *secondWidget)
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 

Detailed Description

The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene in a scrollable viewport. Refer to the detailed documentation for the QGraphicsScene class which explains how to create a scene with a QGraphicsView.

Navigation

QGraphicsView can be used to display an entire scene or only a portion of it. The displayed area is automatically detected when the view is displayed the first time based on QGraphicsScene::itemsBoundingRect()). To set the displayed area manually call setSceneRect() which will adjust the range of the scroll bars. Although scenes support a virtually unlimited size the range of the scroll bars will never exceed the range of an integer.

The user can scroll to any position on the scene by using the scroll bars. The application can scroll by calling centerOn(). By passing a point to centerOn() QGraphicsView will scroll its viewport to ensure the point is centered in the view. The centerOn() method can also be used to scroll to a specific QGraphicsItem in which case the center of the item will be centered in the view. To ensure a particular area of the scene is visible call ensureVisible().

Rendering

QGraphicsView displays the scene by calling the method render(). By default the items are drawn onto the viewport using a QPainter and default render hints. To change the render hints which QGraphicsView passes to QPainter when painting items, call setRenderHints().

QGraphicsView creates a QWidget for the viewport widget. You can access this widget by calling viewport() or replace it by calling setViewport(). To render using OpenGL call setViewport(new QGLWidget). QGraphicsView will take ownership of the viewport widget.

QGraphicsView supports affine transformations using QTransform. You can either pass a matrix to setTransform() or call the methods rotate(), scale(), translate(), or shear(). QGraphicsView keeps the center of the view fixed during a transformation. Because of the scene alignment translating the view will have no visual effect.

Event Handling

Users can interact with the items in the scene using the mouse and keyboard. QGraphicsView translates the mouse and key events into scene events and forwards them to items in the scene. For example, if the user clicks on a selectable item it can inform the scene the current item has been selected. When this occurs the item can redraw itself to display a selection rectangle.

When dragging the mouse on a movable item the item must handle the mouse moves and moves itself. Item interaction is enabled by default and you can toggle it by calling setInteractive().

An application can provide custom scene interaction by inheriting from QGraphicsView and reimplementing the mouse and key event handlers. To convert between scene coordinates and view coordinates call the mapping methods mapToScene() and mapFromScene().

See also
QGraphicsScene, QGraphicsItem, QGraphicsSceneEvent

Member Typedef Documentation

Member Enumeration Documentation

This enum describes the flags that you can set for a QGraphicsView's cache mode.

ConstantValueDescription
QGraphicsView::CacheNone 0x0 All painting is done directly onto the viewport.
QGraphicsView::CacheBackground 0x1 The background is cached. This affects both custom backgrounds, and backgrounds based on the backgroundBrush property. When this flag is enabled, QGraphicsView will allocate one pixmap with the full size of the viewport.
See also
cacheMode

This enum describes the default action for the view when pressing and dragging the mouse over the viewport.

ConstantValueDescription
QGraphicsView::NoDrag0Nothing happens the mouse event is ignored.
QGraphicsView::ScrollHandDrag1 The cursor changes into a pointing hand, and dragging the mouse around will scroll the scrollbars. This mode works both in interactive and non-interactive mode.
QGraphicsView::RubberBandDrag2 A rubber band will appear. Dragging the mouse will set the rubber band geometry, and all items covered by the rubber band are selected. This mode is disabled for non-interactive views.
See also
dragMode, QGraphicsScene::setSelectionArea()

This enum describes flags which can enabled to improve rendering performance. By default none of these flags are set. Setting a flag usually imposes a side effect which can vary between paint devices and platforms.

ConstantValueDescription
GraphicsView::DontSavePainterState 0x2 When rendering QGraphicsView protects the painter state when rendering the background or foreground and each item. This allows the application to leave the painter in an altered state. If the items always restore the state you should enable this flag to prevent QGraphicsView from doing the same.
QGraphicsView::DontAdjustForAntialiasing 0x4 Disables QGraphicsView's antialiasing auto-adjustment of exposed areas. Items which render antialiased lines on the boundaries of their QGraphicsItem::boundingRect() can end up rendering parts of the line outside the bounding rectangle. To prevent artifacts QGraphicsView expands regions by 2 pixels. This flag will turn off the 2 pixel border to improves performance. Items drawn with antialiasing may leave painting traces as they are moved within the scene.
QGraphicsView::IndirectPainting 0x8 Restores the old painting algorithm which calls QGraphicsView::drawItems() and QGraphicsScene::drawItems(). Only use this flag for compatibility with old application code.

This enums describe the possible anchors that QGraphicsView can use when the user resizes the view or when the view is transformed.

ConstantValueDescription
QGraphicsView::NoAnchor0 No anchor, i.e. the view leaves the scene's position unchanged.
QGraphicsView::AnchorViewCenter1 The scene point at the center of the view is used as the anchor.
QGraphicsView::AnchorUnderMouse2 The point under the mouse is used as the anchor.
See also
resizeAnchor, transformationAnchor

This enum describes how QGraphicsView updates its viewport when the scene contents change or are exposed.

ConstantValueDescription
QGraphicsView::FullViewportUpdate 0 When any visible part of the scene changes or is reexposed, QGraphicsView will update the entire viewport. This approach is fastest when QGraphicsView spends more time figuring out what to draw than it would spend drawing (e.g., when very many small items are repeatedly updated). This is the preferred update mode for viewports that do not support partial updates, such as QGLWidget, and for viewports that need to disable scroll optimization.
QGraphicsView::MinimalViewportUpdate 1 QGraphicsView will determine the minimal viewport region that requires a redraw, minimizing the time spent drawing by avoiding a redraw of areas that have not changed. This is QGraphicsView's default mode. Although this approach provides the best performance in general, if there are many small visible changes on the scene, QGraphicsView might end up spending more time finding the minimal approach than it will spend drawing.
QGraphicsView::SmartViewportUpdate2 QGraphicsView will attempt to find an optimal update mode by analyzing the areas that require a redraw.
QGraphicsView::BoundingRectViewportUpdate4 The bounding rectangle of all changes in the viewport will be redrawn. This mode has the advantage that QGraphicsView searches only one region for changes, minimizing time spent determining what needs redrawing. The disadvantage is that areas that have not changed also need to be redrawn.
QGraphicsView::NoViewportUpdate3 QGraphicsView will never update its viewport when the scene changes; the user is expected to control all updates. This mode disables all (potentially slow) item visibility testing in QGraphicsView, and is suitable for scenes that either require a fixed frame rate, or where the viewport is otherwise updated externally.
See also
viewportUpdateMode

Constructor & Destructor Documentation

QGraphicsView::QGraphicsView ( QWidget parent = nullptr)

Constructs a QGraphicsView. The parent is passed to the QWidget constructor.

QGraphicsView::QGraphicsView ( QGraphicsScene scene,
QWidget parent = nullptr 
)

Constructs a QGraphicsView and sets the visualized scene to scene. The parent is passed to the QWidget constructor.

QGraphicsView::~QGraphicsView ( )

Destroys the QGraphicsView object.

Method Documentation

Qt::Alignment QGraphicsView::alignment ( ) const

Returns the value of the QGraphicsView::alignment property.

QBrush QGraphicsView::backgroundBrush ( ) const

Returns the value of the backgroundBrush property.

CacheMode QGraphicsView::cacheMode ( ) const

Returns the value of the cacheMode property.

void QGraphicsView::centerOn ( const QGraphicsItem item)

Scrolls the contents of the viewport to ensure that item is centered in the view.

See also
ensureVisible()
void QGraphicsView::centerOn ( const QPointF pos)

Scrolls the contents of the viewport to ensure the scene coordinate pos is centered in the view. Because pos is a floating point coordinate and the scroll bars operate on integer coordinates, the centering is only an approximation.

If the item is close to or outside the border it will be visible in the view but not centered.

See also
ensureVisible()
void QGraphicsView::centerOn ( qreal  x,
qreal  y 
)
inline

Equivalent to calling centerOn(QPointF(x, y)).

void QGraphicsView::contextMenuEvent ( QContextMenuEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::contextMenuEvent()

void QGraphicsView::dragEnterEvent ( QDragEnterEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::dragEnterEvent()

void QGraphicsView::dragLeaveEvent ( QDragLeaveEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::dragLeaveEvent()

DragMode QGraphicsView::dragMode ( ) const

Returns the value of the dragMode property.

void QGraphicsView::dragMoveEvent ( QDragMoveEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::dragMoveEvent()

void QGraphicsView::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 method to provide a custom background for this view. If all you want is to define a color, texture or gradient for the background call setBackgroundBrush().

All painting is done in scene coordinates. The value for rect is the exposed rectangle. The default implementation fills rect using the view's backgroundBrush. If no brush is defined the drawBackground() method for the scene is called.

See also
drawForeground(), QGraphicsScene::drawBackground()
void QGraphicsView::drawForeground ( QPainter painter,
const QRectF rect 
)
protectedvirtual

Draws the foreground of the scene using painter, after the background and all items are drawn. Reimplement this method to provide a custom foreground for this view. If all you want is to define a color, texture or gradient for the foreground call setForegroundBrush().

All painting is done in scene coordinates. The value for rect is the exposed rectangle. The default implementation fills rect using the view's foregroundBrush. If no brush is defined drawForeground() method for the scene is called.

See also
drawBackground(), QGraphicsScene::drawForeground()
void QGraphicsView::drawItems ( QPainter painter,
int  numItems,
QGraphicsItem items[],
const QStyleOptionGraphicsItem  options[] 
)
deprecatedprotectedvirtual
Deprecated:
Not recommend for application code.

Draws the items in the scene using painter after the background and before the foreground are drawn. The numItems is the number of items in the given items and options. The value for options is a list of styleoptions with one for each item.

Reimplement this method to provide custom item drawing for this view. The default implementation calls the scene's drawItems() method. This method is not called unless the QGraphicsView::IndirectPainting flag is given as an Optimization flag.

See also
drawForeground(), drawBackground(), QGraphicsScene::drawItems()
void QGraphicsView::dropEvent ( QDropEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::dropEvent()

void QGraphicsView::ensureVisible ( const QGraphicsItem item,
int  xmargin = 50,
int  ymargin = 50 
)

Scrolls the contents of the viewport so the center of item is visible, with margins specified in pixels by xmargin and ymargin. If the specified point can not be reached, the contents are scrolled to the nearest valid position. The default value for both margins is 50 pixels.

See also
centerOn()
void QGraphicsView::ensureVisible ( const QRectF rect,
int  xmargin = 50,
int  ymargin = 50 
)

Scrolls the contents of the viewport so the scene rectangle rect is visible, with margins specified in pixels by xmargin and ymargin. If the specified rect can not be reached the contents are scrolled to the nearest valid position. The default value for both margins is 50 pixels.

See also
centerOn()
void QGraphicsView::ensureVisible ( qreal  x,
qreal  y,
qreal  width,
qreal  height,
int  xmargin = 50,
int  ymargin = 50 
)
inline

Equivalent to calling ensureVisible(QRectF(x, y, width, height), xmargin, ymargin).

bool QGraphicsView::event ( QEvent event)
overrideprotected

Reimplemented from QAbstractScollArea::event()

void QGraphicsView::fitInView ( const QGraphicsItem item,
Qt::AspectRatioMode  mode = Qt::IgnoreAspectRatio 
)

Ensures item fits exactly inside the view by scaling the view according to mode.

See also
ensureVisible(), centerOn()
void QGraphicsView::fitInView ( const QRectF rect,
Qt::AspectRatioMode  mode = Qt::IgnoreAspectRatio 
)

Scales the view matrix and scrolls the scroll bars to ensure that the scene rect fits inside the viewport. The given rect must be inside the scene rectangle otherwise this method can not guarantee the entire rectangle will be visible. This method does not change the current rotation, translation, or shear. The view is scaled according to mode. The rect will be centered in the view if it does not fit exactly. If rect is empty or if the viewport is too small this method will do nothing.

It is common to call this method from inside a reimplementation of resizeEvent() to ensure the entire scene or parts of the scene is scaled to fit the new size. However, this can lead to infinite resize recursion when the transformation toggles the state of the scrollbars. You can set the scrollbar policies to always on or always off to prevent this from happening.

See also
setTransform(), ensureVisible(), centerOn(), horizontalScrollBarPolicy(), verticalScrollBarPolicy()
void QGraphicsView::fitInView ( qreal  x,
qreal  y,
qreal  width,
qreal  height,
Qt::AspectRatioMode  mode = Qt::IgnoreAspectRatio 
)
inline

Equivalent to calling fitInView(QRectF(x, y, width,height), mode).

See also
ensureVisible(), centerOn()
void QGraphicsView::focusInEvent ( QFocusEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::focusInEvent()

bool QGraphicsView::focusNextPrevChild ( bool  next)
overrideprotectedvirtual

Reimplemented from QWidget::focusNextPrevChild()

void QGraphicsView::focusOutEvent ( QFocusEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::focusOutEvent()

QBrush QGraphicsView::foregroundBrush ( ) const

Returns the value of the foregroundBrush property.

void QGraphicsView::inputMethodEvent ( QInputMethodEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::inputMethodEvent()

QVariant QGraphicsView::inputMethodQuery ( Qt::InputMethodQuery  query) const
overridevirtual

Reimplemented from QWidget::inputMethodQuery()

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

Invalidates and schedules a redraw of layers inside rect. The given rect is in scene coordinates. Call this method to notify QGraphicsView of changes to the background or the foreground of the scene.

QGraphicsView only supports caching the background layer. This method is equivalent to calling update() if any layer other than QGraphicsScene::BackgroundLayer is passed.

See also
QGraphicsScene::invalidate(), update(), QGraphicsView::CacheModeFlag
bool QGraphicsView::isInteractive ( ) const

Returns the value of the QGraphicsView::interactive property.

bool QGraphicsView::isTransformed ( ) const

Returns true if the view is transformed which occurs when a transform has been assigned or the scrollbars are adjusted.

See also
setTransform(), horizontalScrollBar(), verticalScrollBar()
QGraphicsItem * QGraphicsView::itemAt ( const QPoint pos) const

Returns the item located at pos. The position is in viewport coordinates. If there are several items at this position this method returns the item in front.

void CustomView::mousePressEvent(QMouseEvent *event)
{
if (QGraphicsItem *item = itemAt(event->pos())) {
qDebug() << "You clicked on item" << item;
} else {
qDebug() << "You did not click on an item.";
}
}
See also
items(), Sorting
QGraphicsItem * QGraphicsView::itemAt ( int  x,
int  y 
) const
inline

Equivalent to calling itemAt(QPoint(x, y)).

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

Returns a sorted list of all the items in the current scene. The first element is the front item.

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

Returns a sorted list of all the items matching the given path and mode. The value for path is in viewport coordinates. The first element is the front item. The default value for mode is Qt::IntersectsItemShape where all items whose exact shape intersects with or is contained by path are returned.

See also
itemAt(), items(), mapToScene(), Sorting
QList< QGraphicsItem * > QGraphicsView::items ( const QPoint pos) const

Returns a sorted list of items at pos. The position is in viewport coordinates. The first element is the front item.

void CustomView::mousePressEvent(QMouseEvent *event)
{
qDebug() << "There are" << items(event->pos()).size()
<< "items at position" << mapToScene(event->pos());
}
See also
QGraphicsScene::items(), Sorting
QList< QGraphicsItem * > QGraphicsView::items ( const QPolygon polygon,
Qt::ItemSelectionMode  mode = Qt::IntersectsItemShape 
) const

Returns a sorted list of all the items matching the given polygon and mode. The value for polygon is in viewport coordinates. The first element is the front item. The default value for mode is Qt::IntersectsItemShape where all items whose exact shape intersects with or is contained by polygon are returned.

See also
itemAt(), items(), mapToScene(), Sorting
QList< QGraphicsItem * > QGraphicsView::items ( const QRect rect,
Qt::ItemSelectionMode  mode = Qt::IntersectsItemShape 
) const

Returns a sorted list of all the items matching the given rect and mode. The value for rect is in viewport coordinates. The first element is the front item. The default value for mode is Qt::IntersectsItemShape where all items whose exact shape intersects with or is contained by rect are returned.

See also
itemAt(), items(), mapToScene(), Sorting
QList< QGraphicsItem * > QGraphicsView::items ( int  x,
int  y 
) const
inline

Equivalent to calling items(QPoint(x, y)).

QList< QGraphicsItem * > QGraphicsView::items ( int  x,
int  y,
int  width,
int  height,
Qt::ItemSelectionMode  mode = Qt::IntersectsItemShape 
) const
inline

Equivalent to calling items(QRectF(x, y, width, height), mode).

void QGraphicsView::keyPressEvent ( QKeyEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::keyPressEvent()

void QGraphicsView::keyReleaseEvent ( QKeyEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::keyReleaseEvent()

QPainterPath QGraphicsView::mapFromScene ( const QPainterPath path) const

Converts the given path from scene coordinates to viewport coordinates.

See also
mapToScene()
QPoint QGraphicsView::mapFromScene ( const QPointF point) const

Converts the given point from scene coordinates to viewport coordinates.

See also
mapToScene()
QPolygon QGraphicsView::mapFromScene ( const QPolygonF polygon) const

Converts the given polygon from scene coordinates to viewport coordinates.

See also
mapToScene()
QPolygon QGraphicsView::mapFromScene ( const QRectF rect) const

Converts the given rect from scene coordinates to viewport coordinates.

See also
mapToScene()
QPoint QGraphicsView::mapFromScene ( qreal  x,
qreal  y 
) const
inline

Equivalent to calling mapFromScene(QPointF(x, y)).

QPolygon QGraphicsView::mapFromScene ( qreal  x,
qreal  y,
qreal  width,
qreal  height 
) const
inline

Equivalent to calling mapFromScene(QRectF(x, y, width, height)).

QPainterPath QGraphicsView::mapToScene ( const QPainterPath path) const

Converts the given path from viewport coordinates to scene coordinates.

See also
mapFromScene()
QPointF QGraphicsView::mapToScene ( const QPoint point) const

Converts the given point from viewport coordinates to scene coordinates.

It can be useful to map the entire rectangle covered by the pixel at the given point instead of the point itself. To do this call mapToScene(QRect(point, QSize(2, 2))).

See also
mapFromScene()
QPolygonF QGraphicsView::mapToScene ( const QPolygon polygon) const

Converts the given polygon from viewport coordinates to scene coordinates.

See also
mapFromScene()
QPolygonF QGraphicsView::mapToScene ( const QRect rect) const

Converts the given rect from viewport coordinates to scene coordinates.

See also
mapFromScene()
QPointF QGraphicsView::mapToScene ( int  x,
int  y 
) const
inline

Equivalent to calling mapToScene(QPoint(x, y)).

QPolygonF QGraphicsView::mapToScene ( int  x,
int  y,
int  width,
int  height 
) const
inline

Equivalent to calling mapToScene(QRect(x, y, width, height).

QMatrix QGraphicsView::matrix ( ) const

Returns the current transformation matrix for the view. If no current transformation is set the identity matrix is returned.

See also
setMatrix(), transform(), rotate(), scale(), shear(), translate()
void QGraphicsView::mouseDoubleClickEvent ( QMouseEvent event)
overrideprotectedvirtual
void QGraphicsView::mouseMoveEvent ( QMouseEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::mouseMoveEvent()

void QGraphicsView::mousePressEvent ( QMouseEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::mousePressEvent()

void QGraphicsView::mouseReleaseEvent ( QMouseEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::mouseReleaseEvent()

OptimizationFlags QGraphicsView::optimizationFlags ( ) const

Returns the value of the optimizationFlags property.

void QGraphicsView::paintEvent ( QPaintEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::paintEvent()

void QGraphicsView::render ( QPainter painter,
const QRectF target = QRectF(),
const QRect source = QRect(),
Qt::AspectRatioMode  mode = Qt::KeepAspectRatio 
)

Renders the source rectangle which is in view coordinates into the target rectangle, which is in paint device coordinates, using painter. This method is useful for rendering the contents of the view onto a paint device, such as a QImage or for printing to a QPrinter.

If source is a null rectangle this method will call rect() to determine what to render. If the target is a null rectangle the full dimensions of the QPainter device will be used. The source rectangle contents will be transformed according to mode to fit into the target rectangle. By default, the aspect ratio is kept and source is scaled to fit in target.

// add elements to the scene
view.show();
// do something
QPrinter printer(QPrinter::HighResolution);
printer.setPageSize(QPrinter::A4);
QPainter painter(&printer);
// print, fitting the viewport contents into a full page
view.render(&painter);
// print the upper half of the viewport into the lower half of the page
QRect viewport = view.viewport()->rect();
view.render(&painter, QRectF(0, printer.height() / 2, printer.width(), printer.height() / 2),
viewport.adjusted(0, 0, 0, -viewport.height() / 2));
See also
QGraphicsScene::render()
QPainter::RenderHints QGraphicsView::renderHints ( ) const

Returns the value of the renderHints property.

void QGraphicsView::resetCachedContent ( )

Clears all cached content. If the current cache mode is CacheNone then this method does nothing. This method is called automatically when the backgroundBrush or QGraphicsScene::backgroundBrush properties change. Only call this method if you have reimplemented QGraphicsScene::drawBackground() or QGraphicsView::drawBackground() to draw a custom background and need to trigger a full redraw.

See also
cacheMode()
void QGraphicsView::resetMatrix ( )

Resets the view transformation matrix to the identity matrix.

See also
resetTransform()
void QGraphicsView::resetTransform ( )

Resets the view transformation matrix to the identity matrix.

See also
transform(), setTransform()
ViewportAnchor QGraphicsView::resizeAnchor ( ) const

Returns the value of the resizeAnchor property.

void QGraphicsView::resizeEvent ( QResizeEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::resizeEvent()

void QGraphicsView::rotate ( qreal  angle)

Rotates the current view transformation angle degrees clockwise.

See also
setTransform(), transform(), scale(), shear(), translate()
void QGraphicsView::rubberBandChanged ( QRect  viewportRect,
QPointF  fromScenePoint,
QPointF  toScenePoint 
)
signal

This signal is emitted when the rubber band rectangle is changed. The viewport is specified by viewportRect. The drag start position and drag end position are provided in scene coordinates with fromScenePoint and toScenePoint.

When a rubber band selection ends this signal will be emitted and all of the values will be null.

See also
rubberBandRect()
QRect QGraphicsView::rubberBandRect ( ) const

This method returns the current rubber band area in viewport coordinates if the user is currently doing an item selection with the rubber band. When the user is not using the rubber band this method returns a null QRectF. Part of this QRect can be outside the visual viewport or contain negative values.

See also
rubberBandSelectionMode, rubberBandChanged()
Qt::ItemSelectionMode QGraphicsView::rubberBandSelectionMode ( ) const

Returns the value of the rubberBandSelectionMode property.

void QGraphicsView::scale ( qreal  sx,
qreal  sy 
)

Scales the current view transformation by (sx, sy).

See also
setTransform(), transform(), rotate(), shear(), translate()
QGraphicsScene * QGraphicsView::scene ( ) const

Returns a pointer to the scene which is currently displayed in the view. If no scene is currently displayed a nullptr is returned.

See also
setScene()
QRectF QGraphicsView::sceneRect ( ) const

Returns the value of the sceneRect property.

void QGraphicsView::scrollContentsBy ( int  dx,
int  dy 
)
overrideprotectedvirtual
void QGraphicsView::setAlignment ( Qt::Alignment  alignment)

Sets the value of the QGraphicsView::alignment property to alignment.

void QGraphicsView::setBackgroundBrush ( const QBrush brush)

Sets the value of the backgroundBrush property to brush.

void QGraphicsView::setCacheMode ( CacheMode  mode)

Sets the value of the cacheMode property to mode.

void QGraphicsView::setDragMode ( DragMode  mode)

Sets the value of the dragMode property to mode.

void QGraphicsView::setForegroundBrush ( const QBrush brush)

Sets the value of the foregroundBrush property to brush.

void QGraphicsView::setInteractive ( bool  allowed)

Sets the value of the QGraphicsView::interactive property to allowed.

void QGraphicsView::setMatrix ( const QMatrix matrix,
bool  combine = false 
)

Sets the view's current transformation to matrix. If combine is true then the given matrix is combined with the current matrix, otherwise matrix replaces the current matrix.

The transformation matrix is used to transform the scene into view coordinates. The default transformation uses the identity matrix which means one pixel in the view is one unit in the scene. To simplify interaction with items using a transformed view, QGraphicsView provides mapToScene() and mapFromScene() methods which translate between scene and view coordinates.

scene.addText("GraphicsView rotated clockwise");
view.rotate(90); // the text is rendered with a 90 degree clockwise rotation
view.show();
See also
matrix(), setTransform(), rotate(), scale(), shear(), translate()
void QGraphicsView::setOptimizationFlag ( OptimizationFlag  flag,
bool  enabled = true 
)

Enables flag if enabled is true, otherwise disables flag.

See also
optimizationFlags
void QGraphicsView::setOptimizationFlags ( OptimizationFlags  flags)

Sets the value of the optimizationFlags property to flags.

void QGraphicsView::setRenderHint ( QPainter::RenderHint  hint,
bool  enabled = true 
)

If enabled is true the render hint is enabled, otherwise it is disabled.

See also
renderHints
void QGraphicsView::setRenderHints ( QPainter::RenderHints  hints)

Sets the value of the renderHints property to hints.

void QGraphicsView::setResizeAnchor ( ViewportAnchor  anchor)

Sets the value of the resizeAnchor property to anchor.

void QGraphicsView::setRubberBandSelectionMode ( Qt::ItemSelectionMode  mode)

Sets the value of the rubberBandSelectionMode property to mode.

void QGraphicsView::setScene ( QGraphicsScene scene)

Sets the current scene to the given scene. If the scene is being displayed this method does nothing. When a scene is set on a view the QGraphicsScene::changed() signal is automatically connected to this view's updateScene() slot and the view's scroll bars are adjusted to fit the size of the scene.

See also
scene()
void QGraphicsView::setSceneRect ( const QRectF rect)
inline

Sets the value of the sceneRect property to rect.

void QGraphicsView::setSceneRect ( qreal  x,
qreal  y,
qreal  width,
qreal  height 
)
inline

Sets the value of the sceneRect property to (x, y, width, height).

void QGraphicsView::setTransform ( const QTransform matrix,
bool  combine = false 
)

Sets the view's current transformation to matrix. If combine is true then the given matrix is combined with the current matrix, otherwise matrix replaces the current matrix.

The transformation matrix is used to transform the scene into view coordinates. The default transformation uses the identity matrix which means one pixel in the view is one unit in the scene. To simplify interaction with items using a transformed view, QGraphicsView provides mapToSceene() and mapFromScene() methods which translate between scene and view coordinates.

scene.addText("GraphicsView rotated clockwise");
view.rotate(90); // the text is rendered with a 90 degree clockwise rotation
view.show();
See also
transform(), rotate(), scale(), shear(), translate()
void QGraphicsView::setTransformationAnchor ( ViewportAnchor  anchor)

Sets the value of the transformationAnchor property to anchor.

void QGraphicsView::setupViewport ( QWidget widget)
protectedslot

This slot is called by QAbstractScrollArea after setViewport() has been called. Reimplement this method in a subclass of QGraphicsView to initialize the new viewport widget before it is used.

See also
setViewport()
void QGraphicsView::setViewportUpdateMode ( ViewportUpdateMode  mode)

Sets the value of the viewportUpdateMode property to mode.

void QGraphicsView::shear ( qreal  sh,
qreal  sv 
)

Shears the current view transformation by (sh, sv).

See also
setTransform(), transform(), rotate(), scale(), translate()
void QGraphicsView::showEvent ( QShowEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::showEvent()

QSize QGraphicsView::sizeHint ( ) const
overridevirtual

Reimplemented from QWidget::sizeHint()

QTransform QGraphicsView::transform ( ) const

Returns the current transformation matrix for the view. If no transformation is set the identity matrix is returned.

See also
setTransform(), rotate(), scale(), shear(), translate()
ViewportAnchor QGraphicsView::transformationAnchor ( ) const

Returns the value of the transformationAnchor property.

void QGraphicsView::translate ( qreal  dx,
qreal  dy 
)

Translates the current view transformation by (dx, dy).

See also
setTransform(), transform(), rotate(), shear()
void QGraphicsView::updateScene ( const QList< QRectF > &  rects)
slot

Schedules an update of the scene rectangles rects.

See also
QGraphicsScene::changed()
void QGraphicsView::updateSceneRect ( const QRectF rect)
slot

Notifies QGraphicsView the scene's rectangle has changed. The given rect is the new scene rectangle. If the view already has an explicitly set scene rectangle this method does nothing.

See also
sceneRect, QGraphicsScene::sceneRectChanged()
bool QGraphicsView::viewportEvent ( QEvent event)
overrideprotectedvirtual
QTransform QGraphicsView::viewportTransform ( ) const

Returns a matrix which maps viewport coordinates to scene coordinates.

See also
mapToScene(), mapFromScene()
ViewportUpdateMode QGraphicsView::viewportUpdateMode ( ) const

Returns the value of the viewportUpdateMode property.

void QGraphicsView::wheelEvent ( QWheelEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::wheelEvent()

Property Documentation

QGraphicsView::alignment

This property holds the alignment of the scene in the view when the entire scene is visible.

If the entire scene is visible in the view the alignment will determine where the scene will be rendered in the view. For example, if the alignment is Qt::AlignCenter the scene will be centered in the view and if the alignment is (Qt::AlignLeft | Qt::AlignTop) the scene will be rendered in the top-left corner of the view.

PropertiesClass Methods
read alignment
write setAlignment
QGraphicsView::backgroundBrush

This property holds the background brush of the scene. This property sets the background brush for the scene in this view. It is used to override the scene's own background and defines the behavior of drawBackground(). To provide custom background drawing for this view reimplement drawBackground().

By default, this property contains a brush with the Qt::NoBrush pattern.

See also
QGraphicsScene::backgroundBrush, foregroundBrush
PropertiesClass Methods
read backgroundBrush
write setBackgroundBrush
QGraphicsView::cacheMode

This property holds which parts of the view are cached. QGraphicsView can cache pre-rendered content in a QPixmap, which is then drawn onto the viewport. The purpose of such caching is to speed up the total rendering time for areas which are slow to render. Texture, gradient, and alpha blended backgrounds, can be slow to render, especially with a transformed view. The CacheBackground flag enables caching of the view's background.

The cache is invalidated every time the view is transformed. When scrolling, only partial invalidation is required. By default nothing is cached.

view.setBackgroundBrush(QImage(":/images/backgroundtile.png"));
view.setCacheMode(QGraphicsView::CacheBackground);
See also
resetCachedContent(), QPixmapCache
PropertiesClass Methods
read cacheMode
write setCacheMode
QGraphicsView::dragMode

This property holds the behavior for dragging the mouse over the scene while the left mouse button is pressed. This property defines what should happen when the user clicks on the scene background and drags the mouse along the background. The default value NoDrag does nothing.

This dragMode only affects mouse clicks that are not handled by any item. You can define a custom behavior by creating a subclass of QGraphicsView and reimplementing mouseMoveEvent().

PropertiesClass Methods
read dragMode
write setDragMode
QGraphicsView::foregroundBrush

This property holds the foreground brush of the scene. This property sets the foreground brush for the scene in this view. It is used to override the foreground and defines the behavior of drawForeground(). To customize the foreground drawing for this view reimplement drawForeground(). By default, this property contains a brush with the Qt::NoBrush pattern.

See also
QGraphicsScene::foregroundBrush, backgroundBrush
PropertiesClass Methods
read foregroundBrush
write setForegroundBrush
QGraphicsView::interactive

This property holds whether the view allowed scene interaction. If enabled the view is set to allow scene interaction. Otherwise, this view will not allow interaction and any mouse or key events are ignored. By default, this property is true.

PropertiesClass Methods
read isInteractive
write setInteractive
QGraphicsView::optimizationFlags

This property holds flags which are used to optimize performance. QGraphicsView uses clipping, extra bounding rectangle adjustments, and certain other strategies to improve rendering quality and performance for the common case graphics scene. Depending on the target platform the scene and the viewport, some of these strategies operations can degrade performance and should be turned off. By default, no optimization flags are enabled.

See also
setOptimizationFlag(), OptimizationFlags
PropertiesClass Methods
read optimizationFlags
write setOptimizationFlags
QGraphicsView::renderHints

This property holds the default render hints for the view. These hints are used to initialize the QPainter before each visible item is drawn. QPainter uses render hints to toggle features such as antialiasing and smooth pixmap transformation. QPainter::TextAntialiasing is enabled by default.

scene.addRect(QRectF(-10, -10, 20, 20));
view.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
view.show();
PropertiesClass Methods
read renderHints
write setRenderHints
QGraphicsView::resizeAnchor

This property indicates how the view should position the scene when the view is resized. The default behavior of NoAnchor leaves the scene's position unchanged during a resize. The top-left corner of the view will appear to be stationary while resizing.

The effect of this property is noticeable when only a part of the scene is visible. If the whole scene fits in the view QGraphicsScene uses the view alignment to position the scene in the view.

See also
QGraphicsView::alignment, QGraphicsView::transformationAnchor
PropertiesClass Methods
read resizeAnchor
write setResizeAnchor
QGraphicsView::rubberBandSelectionMode

This property holds the behavior for selecting items with a rubber band selection rectangle. This property defines how items are selected when using the RubberBandDrag drag mode. The default value is Qt::IntersectsItemShape which means all items whose shape intersects with or is contained by the rubber band are selected.

See also
dragMode, items()
PropertiesClass Methods
read rubberBandSelectionMode
write setRubberBandSelectionMode
QGraphicsView::sceneRect

This property holds the area of the scene displayed in the current view. The scene rectangle defines the boundaries of the scene that can be navigated using the scroll bars. If this property is not set or is a null QRectF the value of QGraphicsScene::sceneRect will be used. By default this property contains a rectangle at the origin with zero width and height.

Although the scene supports a virtually unlimited size the range of the scroll bars will never exceed the range of an integer. When the scene is larger than the scroll bar range the translate() method can be used to navigate the scene.

See also
QGraphicsScene::sceneRect
PropertiesClass Methods
read sceneRect
write setSceneRect
QGraphicsView::transformationAnchor

This property defines how the view should position the scene during transformations. The default behavior uses AnchorViewCenter, to ensure the point at the center of the view remains unchanged during transformations. The effect of this property is noticeable when only a part of the scene is visible. If the entire scene fits in the view the view alignment is used to position the scene in the view.

See also
alignment, resizeAnchor
PropertiesClass Methods
read transformationAnchor
write setTransformationAnchor
QGraphicsView::viewportUpdateMode

This property holds how the viewport should update its contents. QGraphicsView uses this property to decide how to update areas of the scene which have been exposed or changed. Normally this property does not need to be changed. However there are some cases where using a different mode can improve rendering performance.

The default value is MinimalViewportUpdate, where QGraphicsView will update as small an area of the viewport as possible when the contents change.

See also
ViewportUpdateMode, cacheMode
PropertiesClass Methods
read viewportUpdateMode
write setViewportUpdateMode