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

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

#include <qgraphicsview.h>

Inheritance diagram for QGraphicsView:
QAbstractScrollArea QFrame QWidget QObject QPaintDevice QDeclarativeView QmlApplicationViewer

Public Types

enum  CacheModeFlag { CacheNone = 0x0, CacheBackground = 0x1 }
 This enum describes the flags that you can set for a QGraphicsView's cache mode. More...
 
enum  DragMode { NoDrag, ScrollHandDrag, RubberBandDrag }
 This enum describes the default action for the view when pressing and dragging the mouse over the viewport. More...
 
enum  OptimizationFlag { DontClipPainter = 0x1, DontSavePainterState = 0x2, DontAdjustForAntialiasing = 0x4, IndirectPainting = 0x8 }
 This enum describes flags that you can enable to improve rendering performance in QGraphicsView. More...
 
enum  ViewportAnchor { NoAnchor, AnchorViewCenter, AnchorUnderMouse }
 This enums describe the possible anchors that QGraphicsView can use when the user resizes the view or when the view is transformed. More...
 
enum  ViewportUpdateMode {
  FullViewportUpdate, MinimalViewportUpdate, SmartViewportUpdate, NoViewportUpdate,
  BoundingRectViewportUpdate
}
 This enum describes how QGraphicsView updates its viewport when the scene contents change or are exposed. More...
 
- Public Types inherited from QFrame
enum  Shadow { Plain = 0x0010, Raised = 0x0020, Sunken = 0x0030 }
 This enum type defines the types of shadow that are used to give a 3D effect to frames. More...
 
enum  Shape {
  NoFrame = 0, Box = 0x0001, Panel = 0x0002, WinPanel = 0x0003,
  HLine = 0x0004, VLine = 0x0005, StyledPanel = 0x0006
}
 This enum type defines the shapes of frame available. More...
 
enum  StyleMask { Shadow_Mask = 0x00f0, Shape_Mask = 0x000f }
 This enum defines two constants that can be used to extract the two components of frameStyle(): More...
 
- Public Types inherited from QWidget
enum  RenderFlag { DrawWindowBackground = 0x1, DrawChildren = 0x2, IgnoreMask = 0x4 }
 This enum describes how to render the widget when calling QWidget::render(). More...
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY
}
 

Public Slots

void invalidateScene (const QRectF &rect=QRectF(), QGraphicsScene::SceneLayers layers=QGraphicsScene::AllLayers)
 Invalidates and schedules a redraw of layers inside rect. More...
 
void updateScene (const QList< QRectF > &rects)
 Schedules an update of the scene rectangles rects. More...
 
void updateSceneRect (const QRectF &rect)
 Notifies QGraphicsView that the scene's scene rect has changed. More...
 
- Public Slots inherited from QWidget
bool close ()
 Closes this widget. More...
 
void hide ()
 Hides the widget. More...
 
void lower ()
 Lowers the widget to the bottom of the parent widget's stack. More...
 
void raise ()
 Raises this widget to the top of the parent widget's stack. More...
 
void repaint ()
 Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the widget is hidden. More...
 
void setDisabled (bool)
 Disables widget input events if disable is true; otherwise enables input events. More...
 
void setEnabled (bool)
 
void setFocus ()
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setHidden (bool hidden)
 Convenience function, equivalent to setVisible(!hidden). More...
 
QT_MOC_COMPAT void setShown (bool shown)
 Use setVisible(shown) instead. More...
 
void setStyleSheet (const QString &styleSheet)
 
virtual void setVisible (bool visible)
 
void setWindowModified (bool)
 
void setWindowTitle (const QString &)
 
void show ()
 Shows the widget and its child widgets. More...
 
void showFullScreen ()
 Shows the widget in full-screen mode. More...
 
void showMaximized ()
 Shows the widget maximized. More...
 
void showMinimized ()
 Shows the widget minimized, as an icon. More...
 
void showNormal ()
 Restores the widget after it has been maximized or minimized. More...
 
void update ()
 Updates the widget unless updates are disabled or the widget is hidden. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Public Functions

Qt::Alignment alignment () const
 
QBrush backgroundBrush () const
 
CacheMode cacheMode () const
 
void centerOn (const QPointF &pos)
 Scrolls the contents of the viewport to ensure that the scene coordinate pos, is centered in the view. More...
 
void centerOn (qreal x, qreal y)
 This function is provided for convenience. More...
 
void centerOn (const QGraphicsItem *item)
 Scrolls the contents of the viewport to ensure that item is centered in the view. More...
 
DragMode dragMode () const
 
void ensureVisible (const QRectF &rect, int xmargin=50, int ymargin=50)
 Scrolls the contents of the viewport so that the scene rectangle rect is visible, with margins specified in pixels by xmargin and ymargin. More...
 
void ensureVisible (qreal x, qreal y, qreal w, qreal h, int xmargin=50, int ymargin=50)
 This function is provided for convenience. More...
 
void ensureVisible (const QGraphicsItem *item, int xmargin=50, int ymargin=50)
 Scrolls the contents of the viewport so that the center of item item is visible, with margins specified in pixels by xmargin and ymargin. More...
 
void fitInView (const QRectF &rect, Qt::AspectRatioMode aspectRadioMode=Qt::IgnoreAspectRatio)
 Scales the view matrix and scrolls the scroll bars to ensure that the scene rectangle rect fits inside the viewport. More...
 
void fitInView (qreal x, qreal y, qreal w, qreal h, Qt::AspectRatioMode aspectRadioMode=Qt::IgnoreAspectRatio)
 
void fitInView (const QGraphicsItem *item, Qt::AspectRatioMode aspectRadioMode=Qt::IgnoreAspectRatio)
 Ensures that item fits tightly inside the view, scaling the view according to aspectRatioMode. More...
 
QBrush foregroundBrush () const
 
QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 Reimplemented Function More...
 
bool isInteractive () const
 
bool isTransformed () const
 Returns true if the view is transformed (i. More...
 
QGraphicsItemitemAt (const QPoint &pos) const
 Returns the item at position pos, which is in viewport coordinates. More...
 
QGraphicsItemitemAt (int x, int y) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This function is provided for convenience. More...
 
QList< QGraphicsItem * > items () const
 Returns a list of all the items in the associated scene, in descending stacking order (i.e., the first item in the returned list is the uppermost item). More...
 
QList< QGraphicsItem * > items (const QPoint &pos) const
 Returns a list of all the items at the position pos in the view. More...
 
QList< QGraphicsItem * > items (int x, int y) const
 This function is provided for convenience. More...
 
QList< QGraphicsItem * > items (const QRect &rect, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 Returns a list of all the items that, depending on mode, are either contained by or intersect with rect. More...
 
QList< QGraphicsItem * > items (int x, int y, int w, int h, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 
QList< QGraphicsItem * > items (const QPolygon &polygon, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 Returns a list of all the items that, depending on mode, are either contained by or intersect with polygon. More...
 
QList< QGraphicsItem * > items (const QPainterPath &path, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 Returns a list of all the items that, depending on mode, are either contained by or intersect with path. More...
 
QPoint mapFromScene (const QPointF &point) const
 Returns the scene coordinate point to viewport coordinates. More...
 
QPolygon mapFromScene (const QRectF &rect) const
 Returns the scene rectangle rect to a viewport coordinate polygon. More...
 
QPolygon mapFromScene (const QPolygonF &polygon) const
 Returns the scene coordinate polygon polygon to a viewport coordinate polygon. More...
 
QPainterPath mapFromScene (const QPainterPath &path) const
 Returns the scene coordinate painter path path to a viewport coordinate painter path. More...
 
QPoint mapFromScene (qreal x, qreal y) const
 This function is provided for convenience. More...
 
QPolygon mapFromScene (qreal x, qreal y, qreal w, qreal h) const
 This function is provided for convenience. More...
 
QPointF mapToScene (const QPoint &point) const
 Returns the viewport coordinate point mapped to scene coordinates. More...
 
QPolygonF mapToScene (const QRect &rect) const
 Returns the viewport rectangle rect mapped to a scene coordinate polygon. More...
 
QPolygonF mapToScene (const QPolygon &polygon) const
 Returns the viewport polygon polygon mapped to a scene coordinate polygon. More...
 
QPainterPath mapToScene (const QPainterPath &path) const
 Returns the viewport painter path path mapped to a scene coordinate painter path. More...
 
QPointF mapToScene (int x, int y) const
 This function is provided for convenience. More...
 
QPolygonF mapToScene (int x, int y, int w, int h) const
 This function is provided for convenience. More...
 
QMatrix matrix () const
 Returns the current transformation matrix for the view. More...
 
OptimizationFlags optimizationFlags () const
 
 QGraphicsView (QWidget *parent=0)
 Constructs a QGraphicsView. More...
 
 QGraphicsView (QGraphicsScene *scene, QWidget *parent=0)
 Constructs a QGraphicsView and sets the visualized scene to scene. More...
 
void render (QPainter *painter, const QRectF &target=QRectF(), const QRect &source=QRect(), Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio)
 Renders the source rect, which is in view coordinates, from the scene into target, which is in paint device coordinates, using painter. More...
 
QPainter::RenderHints renderHints () const
 
void resetCachedContent ()
 Resets any cached content. More...
 
void resetMatrix ()
 Resets the view transformation matrix to the identity matrix. More...
 
void resetTransform ()
 Resets the view transformation to the identity matrix. More...
 
ViewportAnchor resizeAnchor () const
 
void rotate (qreal angle)
 Rotates the current view transformation angle degrees clockwise. More...
 
Qt::ItemSelectionMode rubberBandSelectionMode () const
 
void scale (qreal sx, qreal sy)
 Scales the current view transformation by (sx, sy). More...
 
QGraphicsScenescene () const
 Returns a pointer to the scene that is currently visualized in the view. More...
 
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)
 Sets the view's current transformation matrix to matrix. More...
 
void setOptimizationFlag (OptimizationFlag flag, bool enabled=true)
 Enables flag if enabled is true; otherwise disables flag. More...
 
void setOptimizationFlags (OptimizationFlags flags)
 
void setRenderHint (QPainter::RenderHint hint, bool enabled=true)
 If enabled is true, the render hint hint is enabled; otherwise it is disabled. More...
 
void setRenderHints (QPainter::RenderHints hints)
 
void setResizeAnchor (ViewportAnchor anchor)
 
void setRubberBandSelectionMode (Qt::ItemSelectionMode mode)
 
void setScene (QGraphicsScene *scene)
 Sets the current scene to scene. More...
 
void setSceneRect (const QRectF &rect)
 
void setSceneRect (qreal x, qreal y, qreal w, qreal h)
 
void setTransform (const QTransform &matrix, bool combine=false)
 Sets the view's current transformation matrix to matrix. More...
 
void setTransformationAnchor (ViewportAnchor anchor)
 
void setViewportUpdateMode (ViewportUpdateMode mode)
 
void shear (qreal sh, qreal sv)
 Shears the current view transformation by (sh, sv). More...
 
QSize sizeHint () const
 Reimplemented Function More...
 
QTransform transform () const
 Returns the current transformation matrix for the view. More...
 
ViewportAnchor transformationAnchor () const
 
void translate (qreal dx, qreal dy)
 Translates the current view transformation by (dx, dy). More...
 
QTransform viewportTransform () const
 Returns a matrix that maps viewport coordinates to scene coordinates. More...
 
ViewportUpdateMode viewportUpdateMode () const
 
 ~QGraphicsView ()
 Destructs the QGraphicsView object. More...
 
- Public Functions inherited from QAbstractScrollArea
void addScrollBarWidget (QWidget *widget, Qt::Alignment alignment)
 Adds widget as a scroll bar widget in the location specified by alignment. More...
 
QWidgetcornerWidget () const
 Returns the widget in the corner between the two scroll bars. More...
 
QScrollBarhorizontalScrollBar () const
 Returns the horizontal scroll bar. More...
 
Qt::ScrollBarPolicy horizontalScrollBarPolicy () const
 
QSize maximumViewportSize () const
 Returns the size of the viewport as if the scroll bars had no valid scrolling range. More...
 
QSize minimumSizeHint () const
 Reimplemented Function More...
 
 QAbstractScrollArea (QWidget *parent=0)
 Constructs a viewport. More...
 
QWidgetList scrollBarWidgets (Qt::Alignment alignment)
 Returns a list of the currently set scroll bar widgets. More...
 
void setCornerWidget (QWidget *widget)
 Sets the widget in the corner between the two scroll bars to be widget. More...
 
void setHorizontalScrollBar (QScrollBar *scrollbar)
 Replaces the existing horizontal scroll bar with scrollBar, and sets all the former scroll bar's slider properties on the new scroll bar. More...
 
void setHorizontalScrollBarPolicy (Qt::ScrollBarPolicy)
 
void setVerticalScrollBar (QScrollBar *scrollbar)
 Replaces the existing vertical scroll bar with scrollBar, and sets all the former scroll bar's slider properties on the new scroll bar. More...
 
void setVerticalScrollBarPolicy (Qt::ScrollBarPolicy)
 
void setViewport (QWidget *widget)
 Sets the viewport to be the given widget. More...
 
QSize sizeHint () const
 Reimplemented Function More...
 
QScrollBarverticalScrollBar () const
 Returns the vertical scroll bar. More...
 
Qt::ScrollBarPolicy verticalScrollBarPolicy () const
 
QWidgetviewport () const
 Returns the viewport widget. More...
 
 ~QAbstractScrollArea ()
 Destroys the viewport. More...
 
- Public Functions inherited from QFrame
QRect frameRect () const
 
Shadow frameShadow () const
 
Shape frameShape () const
 
int frameStyle () const
 Returns the frame style. More...
 
int frameWidth () const
 
int lineWidth () const
 
int midLineWidth () const
 
 QFrame (QWidget *parent=0, Qt::WindowFlags f=0)
 Constructs a frame widget with frame style NoFrame and a 1-pixel frame width. More...
 
void setFrameRect (const QRect &)
 em>Reimplemented Function More...
 
void setFrameShadow (Shadow)
 
void setFrameShape (Shape)
 
void setFrameStyle (int)
 Sets the frame style to style. More...
 
void setLineWidth (int)
 
void setMidLineWidth (int)
 
QSize sizeHint () const
 em>Reimplemented Function More...
 
 ~QFrame ()
 Destroys the frame. More...
 
- Public Functions inherited from QWidget
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 Returns the (possibly empty) list of this widget's actions. More...
 
void activateWindow ()
 Sets the top-level widget containing this widget to be the active window. More...
 
void addAction (QAction *action)
 Appends the action action to this widget's list of actions. More...
 
void addActions (QList< QAction *> actions)
 Appends the actions actions to this widget's list of actions. More...
 
void adjustSize ()
 Adjusts the size of the widget to fit its contents. More...
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 Returns the background role of the widget. More...
 
QSize baseSize () const
 
QWidgetchildAt (int x, int y) const
 Returns the visible child widget at the position ({x}, {y}) in the widget's coordinate system. More...
 
QWidgetchildAt (const QPoint &p) const
 Returns the visible child widget at point p in the widget's own coordinate system. More...
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 Takes keyboard input focus from the widget. More...
 
void clearMask ()
 Removes any mask set by setMask(). More...
 
QMargins contentsMargins () const
 The contentsMargins function returns the widget's contents margins. More...
 
QRect contentsRect () const
 Returns the area inside the widget's margins. More...
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
void createWinId ()
 
QCursor cursor () const
 
int devType () const
 
WId effectiveWinId () const
 Returns the effective window system identifier of the widget, i. More...
 
void ensurePolished () const
 Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette). More...
 
Qt::FocusPolicy focusPolicy () const
 
QWidgetfocusProxy () const
 Returns the focus proxy, or 0 if there is no focus proxy. More...
 
QWidgetfocusWidget () const
 Returns the last child of this widget that setFocus had been called on. More...
 
const QFontfont () const
 
QFontInfo fontInfo () const
 Returns the font info for the widget's current font. More...
 
QFontMetrics fontMetrics () const
 Returns the font metrics for the widget's current font. More...
 
QPalette::ColorRole foregroundRole () const
 Returns the foreground role. More...
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 Returns the widget's contents margins for left, top, right, and bottom. More...
 
HDC getDC () const
 Returns the window system handle of the widget, for low-level access. More...
 
void grabGesture (Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
 Subscribes the widget to a given gesture with specific flags. More...
 
void grabKeyboard ()
 Grabs the keyboard input. More...
 
void grabMouse ()
 Grabs the mouse input. More...
 
void grabMouse (const QCursor &)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 Adds a shortcut to Qt's shortcut system that watches for the given key sequence in the given context. More...
 
QGraphicsEffectgraphicsEffect () const
 The graphicsEffect function returns a pointer to the widget's graphics effect. More...
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 Returns the proxy widget for the corresponding embedded widget in a graphics view; otherwise returns 0. More...
 
bool hasFocus () const
 
bool hasMouseTracking () const
 
int height () const
 
virtual int heightForWidth (int) const
 Returns the preferred height for this widget, given the width w. More...
 
QInputContextinputContext ()
 This function returns the QInputContext for this widget. More...
 
Qt::InputMethodHints inputMethodHints () const
 
void insertAction (QAction *before, QAction *action)
 Inserts the action action to this widget's list of actions, before the action before. More...
 
void insertActions (QAction *before, QList< QAction *> actions)
 Inserts the actions actions to this widget's list of actions, before the action before. More...
 
WId internalWinId () const
 Returns the window system identifier of the widget, or 0 if the widget is not created yet. More...
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 Returns true if this widget is a parent, (or grandparent and so on to any level), of the given child, and both widgets are within the same window; otherwise returns false. More...
 
bool isEnabled () const
 
bool isEnabledTo (QWidget *) const
 Returns true if this widget would become enabled if ancestor is enabled; otherwise returns false. More...
 
bool isEnabledToTLW () const
 This function is deprecated. More...
 
bool isFullScreen () const
 
bool isHidden () const
 Returns true if the widget is hidden, otherwise returns false. More...
 
bool isLeftToRight () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isRightToLeft () const
 
bool isTopLevel () const
 Use isWindow() instead. More...
 
bool isVisible () const
 
bool isVisibleTo (QWidget *) const
 Returns true if this widget would become visible if ancestor is shown; otherwise returns false. More...
 
bool isWindow () const
 Returns true if the widget is an independent window, otherwise returns false. More...
 
bool isWindowModified () const
 
QLayoutlayout () const
 Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed. More...
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
Qt::HANDLE macCGHandle () const
 Returns the CoreGraphics handle of the widget. More...
 
Qt::HANDLE macQDHandle () const
 Returns the QuickDraw handle of the widget. More...
 
QPoint mapFrom (QWidget *, const QPoint &) const
 Translates the widget coordinate pos from the coordinate system of parent to this widget's coordinate system. More...
 
QPoint mapFromGlobal (const QPoint &) const
 Translates the global screen coordinate pos to widget coordinates. More...
 
QPoint mapFromParent (const QPoint &) const
 Translates the parent widget coordinate pos to widget coordinates. More...
 
QPoint mapTo (QWidget *, const QPoint &) const
 Translates the widget coordinate pos to the coordinate system of parent. More...
 
QPoint mapToGlobal (const QPoint &) const
 Translates the widget coordinate pos to global screen coordinates. More...
 
QPoint mapToParent (const QPoint &) const
 Translates the widget coordinate pos to a coordinate in the parent widget. More...
 
QRegion mask () const
 Returns the mask currently set on a widget. More...
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
int minimumWidth () const
 
void move (int x, int y)
 This corresponds to move(QPoint(x, y)). More...
 
void move (const QPoint &)
 
QWidgetnativeParentWidget () const
 Returns the native parent for this widget, i. More...
 
QWidgetnextInFocusChain () const
 Returns the next widget in this widget's focus chain. More...
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags type)
 Sets the window flags for the widget to flags, without telling the window system. More...
 
void overrideWindowState (Qt::WindowStates state)
 
QPaintEnginepaintEngine () const
 Returns the widget's paint engine. More...
 
const QPalettepalette () const
 
QWidgetparentWidget () const
 Returns the parent of this widget, or 0 if it does not have any parent widget. More...
 
QPoint pos () const
 
QWidgetpreviousInFocusChain () const
 The previousInFocusChain function returns the previous widget in this widget's focus chain. More...
 
 QWidget (QWidget *parent=0, Qt::WindowFlags f=0)
 Constructs a widget which is a child of parent, with widget flags set to f. More...
 
QRect rect () const
 
void releaseDC (HDC) const
 Releases the HDC hdc acquired by a previous call to getDC(). More...
 
void releaseKeyboard ()
 Releases the keyboard grab. More...
 
void releaseMouse ()
 Releases the mouse grab. More...
 
void releaseShortcut (int id)
 Removes the shortcut with the given id from Qt's shortcut system. More...
 
void removeAction (QAction *action)
 Removes the action action from this widget's list of actions. More...
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the sourceRegion of this widget into the target using renderFlags to determine how to render. More...
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the widget into the painter's QPainter::device(). More...
 
void repaint (int x, int y, int w, int h)
 This version repaints a rectangle (x, y, w, h) inside the widget. More...
 
void repaint (const QRect &)
 This version repaints a rectangle rect inside the widget. More...
 
void repaint (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void resize (int w, int h)
 This corresponds to resize(QSize(w, h)). More...
 
void resize (const QSize &)
 
bool restoreGeometry (const QByteArray &geometry)
 Restores the geometry and state top-level widgets stored in the byte array geometry. More...
 
QByteArray saveGeometry () const
 Saves the current geometry and state for top-level widgets. More...
 
void scroll (int dx, int dy)
 Scrolls the widget including its children dx pixels to the right and dy downward. More...
 
void scroll (int dx, int dy, const QRect &)
 This version only scrolls r and does not move the children of the widget. More...
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute, bool on=true)
 Sets the attribute attribute on this widget if on is true; otherwise clears the attribute. More...
 
void setAutoFillBackground (bool enabled)
 
void setBackgroundRole (QPalette::ColorRole)
 Sets the background role of the widget to role. More...
 
void setBaseSize (const QSize &)
 
void setBaseSize (int basew, int baseh)
 This corresponds to setBaseSize(QSize(basew, baseh)). More...
 
void setContentsMargins (int left, int top, int right, int bottom)
 Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom. More...
 
void setContentsMargins (const QMargins &margins)
 The setContentsMargins function sets the margins around the widget's contents. More...
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &)
 
void setFixedHeight (int h)
 Sets both the minimum and maximum heights of the widget to h without changing the widths. More...
 
void setFixedSize (const QSize &)
 Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing or shrinking. More...
 
void setFixedSize (int w, int h)
 Sets the width of the widget to w and the height to h. More...
 
void setFixedWidth (int w)
 Sets both the minimum and maximum width of the widget to w without changing the heights. More...
 
void setFocus (Qt::FocusReason reason)
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *)
 Sets the widget's focus proxy to widget w. More...
 
void setFont (const QFont &)
 Use the single-argument overload instead. More...
 
void setForegroundRole (QPalette::ColorRole)
 Sets the foreground role of the widget to role. More...
 
void setGeometry (int x, int y, int w, int h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This corresponds to setGeometry(QRect(x, y, w, h)). More...
 
void setGeometry (const QRect &)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 The setGraphicsEffect function is for setting the widget's graphics effect. More...
 
void setInputContext (QInputContext *)
 This function sets the input context context on this widget. More...
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *)
 Sets the layout manager for this widget to layout. More...
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &)
 Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible. More...
 
void setMask (const QRegion &)
 Causes only the parts of the widget which overlap region to be visible. More...
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &)
 
void setMaximumSize (int maxw, int maxh)
 This function corresponds to setMaximumSize(QSize(maxw, maxh)). More...
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &)
 
void setMinimumSize (int minw, int minh)
 This function corresponds to setMinimumSize(QSize(minw, minh)). More...
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &)
 Use the single-argument overload instead. More...
 
void setParent (QWidget *parent)
 Sets the parent of the widget to parent, and resets the window flags. More...
 
void setParent (QWidget *parent, Qt::WindowFlags f)
 This function also takes widget flags, f as an argument. More...
 
void setShortcutAutoRepeat (int id, bool enable=true)
 If enable is true, auto repeat of the shortcut with the given id is enabled; otherwise it is disabled. More...
 
void setShortcutEnabled (int id, bool enable=true)
 If enable is true, the shortcut with the given id is enabled; otherwise the shortcut is disabled. More...
 
void setSizeIncrement (const QSize &)
 
void setSizeIncrement (int w, int h)
 Sets the x (width) size increment to w and the y (height) size increment to h. More...
 
void setSizePolicy (QSizePolicy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 Sets the size policy of the widget to horizontal and vertical, with standard stretch and no height-for-width. More...
 
void setStatusTip (const QString &)
 
void setStyle (QStyle *)
 Sets the widget's GUI style to style. More...
 
void setToolTip (const QString &)
 
void setUpdatesEnabled (bool enable)
 
void setupUi (QWidget *widget)
 Sets up the user interface for the specified widget. More...
 
void setWhatsThis (const QString &)
 
void setWindowFilePath (const QString &filePath)
 
void setWindowFlags (Qt::WindowFlags type)
 
void setWindowIcon (const QIcon &icon)
 
void setWindowIconText (const QString &)
 
void setWindowModality (Qt::WindowModality windowModality)
 
void setWindowOpacity (qreal level)
 
void setWindowRole (const QString &)
 Sets the window's role to role. More...
 
void setWindowState (Qt::WindowStates state)
 Sets the window state to windowState. More...
 
void setWindowSurface (QWindowSurface *surface)
 Sets the window surface to be the surface specified. More...
 
QSize size () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *)
 Places the widget under w in the parent widget's stack. More...
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute) const
 Returns true if attribute attribute is set on this widget; otherwise returns false. More...
 
QString toolTip () const
 
QWidgettopLevelWidget () const
 
bool underMouse () const
 Returns true if the widget is under the mouse cursor; otherwise returns false. More...
 
void ungrabGesture (Qt::GestureType type)
 Unsubscribes the widget from a given gesture type. More...
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (int x, int y, int w, int h)
 This version updates a rectangle (x, y, w, h) inside the widget. More...
 
void update (const QRect &)
 This version updates a rectangle rect inside the widget. More...
 
void update (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void updateGeometry ()
 Notifies the layout system that this widget has changed and may need to change geometry. More...
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 Returns the unobscured region where paint events can occur. More...
 
QString whatsThis () const
 
int width () const
 
QWidgetwindow () const
 Returns the window for this widget, i.e. More...
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 Window flags are a combination of a type (e. More...
 
QIcon windowIcon () const
 
QString windowIconText () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 Returns the window's role, or an empty string. More...
 
Qt::WindowStates windowState () const
 Returns the current window state. More...
 
QWindowSurfacewindowSurface () const
 Returns the QWindowSurface this widget will be drawn into. More...
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 Returns the window type of this widget. More...
 
WId winId () const
 Returns the window system identifier of the widget. More...
 
int x () const
 
const QX11Infox11Info () const
 Returns information about the configuration of the X display used to display the widget. More...
 
Qt::HANDLE x11PictureHandle () const
 Returns the X11 Picture handle of the widget for XRender support. More...
 
int y () const
 
 ~QWidget ()
 Destroys the widget. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 
- Public Functions inherited from QPaintDevice
int colorCount () const
 
int depth () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
QT_DEPRECATED int numColors () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 
virtual ~QPaintDevice ()
 

Protected Slots

void setupViewport (QWidget *widget)
 This slot is called by QAbstractScrollArea after setViewport() has been called. More...
 
- Protected Slots inherited from QAbstractScrollArea
void setupViewport (QWidget *viewport)
 This slot is called by QAbstractScrollArea after setViewport(viewport) has been called. More...
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 Updates the widget's micro focus. More...
 

Protected Functions

void contextMenuEvent (QContextMenuEvent *event)
 Reimplemented Function More...
 
void dragEnterEvent (QDragEnterEvent *event)
 Reimplemented Function More...
 
void dragLeaveEvent (QDragLeaveEvent *event)
 Reimplemented Function More...
 
void dragMoveEvent (QDragMoveEvent *event)
 Reimplemented Function More...
 
virtual void drawBackground (QPainter *painter, const QRectF &rect)
 Draws the background of the scene using painter, before any items and the foreground are drawn. More...
 
virtual void drawForeground (QPainter *painter, const QRectF &rect)
 Draws the foreground of the scene using painter, after the background and all items are drawn. More...
 
virtual void drawItems (QPainter *painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem options[])
 Draws the items items in the scene using painter, after the background and before the foreground are drawn. More...
 
void dropEvent (QDropEvent *event)
 Reimplemented Function More...
 
bool event (QEvent *event)
 Reimplemented Function More...
 
void focusInEvent (QFocusEvent *event)
 Reimplemented Function More...
 
bool focusNextPrevChild (bool next)
 Reimplemented Function More...
 
void focusOutEvent (QFocusEvent *event)
 Reimplemented Function More...
 
void inputMethodEvent (QInputMethodEvent *event)
 Reimplemented Function More...
 
void keyPressEvent (QKeyEvent *event)
 Reimplemented Function More...
 
void keyReleaseEvent (QKeyEvent *event)
 Reimplemented Function More...
 
void mouseDoubleClickEvent (QMouseEvent *event)
 Reimplemented Function More...
 
void mouseMoveEvent (QMouseEvent *event)
 Reimplemented Function More...
 
void mousePressEvent (QMouseEvent *event)
 Reimplemented Function More...
 
void mouseReleaseEvent (QMouseEvent *event)
 Reimplemented Function More...
 
void paintEvent (QPaintEvent *event)
 Reimplemented Function More...
 
 QGraphicsView (QGraphicsViewPrivate &, QWidget *parent=0)
 
void resizeEvent (QResizeEvent *event)
 Reimplemented Function More...
 
void scrollContentsBy (int dx, int dy)
 Reimplemented Function More...
 
void showEvent (QShowEvent *event)
 Reimplemented Function More...
 
bool viewportEvent (QEvent *event)
 Reimplemented Function More...
 
void wheelEvent (QWheelEvent *event)
 Reimplemented Function More...
 
- Protected Functions inherited from QAbstractScrollArea
void contextMenuEvent (QContextMenuEvent *)
 This event handler can be reimplemented in a subclass to receive context menu events for the viewport() widget. More...
 
void dragEnterEvent (QDragEnterEvent *)
 This event handler can be reimplemented in a subclass to receive drag enter events (passed in event), for the viewport() widget. More...
 
void dragLeaveEvent (QDragLeaveEvent *)
 This event handler can be reimplemented in a subclass to receive drag leave events (passed in event), for the viewport() widget. More...
 
void dragMoveEvent (QDragMoveEvent *)
 This event handler can be reimplemented in a subclass to receive drag move events (passed in event), for the viewport() widget. More...
 
void dropEvent (QDropEvent *)
 This event handler can be reimplemented in a subclass to receive drop events (passed in event), for the viewport() widget. More...
 
bool event (QEvent *)
 Reimplemented Function More...
 
void keyPressEvent (QKeyEvent *)
 This function is called with key event e when key presses occur. More...
 
void mouseDoubleClickEvent (QMouseEvent *)
 This event handler can be reimplemented in a subclass to receive mouse double click events for the viewport() widget. More...
 
void mouseMoveEvent (QMouseEvent *)
 This event handler can be reimplemented in a subclass to receive mouse move events for the viewport() widget. More...
 
void mousePressEvent (QMouseEvent *)
 This event handler can be reimplemented in a subclass to receive mouse press events for the viewport() widget. More...
 
void mouseReleaseEvent (QMouseEvent *)
 This event handler can be reimplemented in a subclass to receive mouse release events for the viewport() widget. More...
 
void paintEvent (QPaintEvent *)
 This event handler can be reimplemented in a subclass to receive paint events (passed in event), for the viewport() widget. More...
 
 QAbstractScrollArea (QAbstractScrollAreaPrivate &dd, QWidget *parent=0)
 Creates a new QAbstractScrollAreaPrivate, dd with the given parent. More...
 
void resizeEvent (QResizeEvent *)
 This event handler can be reimplemented in a subclass to receive resize events (passed in event), for the viewport() widget. More...
 
void setViewportMargins (int left, int top, int right, int bottom)
 Sets the margins around the scrolling area to left, top, right and bottom. More...
 
void setViewportMargins (const QMargins &margins)
 Sets margins around the scrolling area. More...
 
void wheelEvent (QWheelEvent *)
 This event handler can be reimplemented in a subclass to receive wheel events for the viewport() widget. More...
 
- Protected Functions inherited from QFrame
void changeEvent (QEvent *)
 This event handler can be reimplemented to handle state changes. More...
 
void drawFrame (QPainter *)
 em>Reimplemented Function More...
 
bool event (QEvent *e)
 Reimplemented Function More...
 
void paintEvent (QPaintEvent *)
 This event handler can be reimplemented in a subclass to receive paint events passed in event. More...
 
 QFrame (QFramePrivate &dd, QWidget *parent=0, Qt::WindowFlags f=0)
 
- Protected Functions inherited from QWidget
virtual void actionEvent (QActionEvent *)
 This event handler is called with the given event whenever the widget's actions are changed. More...
 
virtual void closeEvent (QCloseEvent *)
 This event handler is called with the given event when Qt receives a window close request for a top-level widget from the window system. More...
 
void create (WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
 Creates a new widget window if window is 0, otherwise sets the widget's window to window. More...
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 Frees up window system resources. More...
 
virtual void enabledChange (bool)
 
virtual void enterEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive widget enter events which are passed in the event parameter. More...
 
bool focusNextChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Tab, and returns true if it can find a new widget, or false if it can't. More...
 
bool focusPreviousChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Shift+Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual void fontChange (const QFont &)
 
virtual void hideEvent (QHideEvent *)
 This event handler can be reimplemented in a subclass to receive widget hide events. More...
 
virtual void languageChange ()
 
virtual void leaveEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive widget leave events which are passed in the event parameter. More...
 
virtual bool macEvent (EventHandlerCallRef, EventRef)
 This special event handler can be reimplemented in a subclass to receive native Macintosh events. More...
 
int metric (PaintDeviceMetric) const
 Internal implementation of the virtual QPaintDevice::metric() function. More...
 
virtual void moveEvent (QMoveEvent *)
 This event handler can be reimplemented in a subclass to receive widget move events which are passed in the event parameter. More...
 
virtual void paletteChange (const QPalette &)
 
 QWidget (QWidgetPrivate &d, QWidget *parent, Qt::WindowFlags f)
 
virtual bool qwsEvent (QWSEvent *)
 This special event handler can be reimplemented in a subclass to receive native Qt for Embedded Linux events which are passed in the event parameter. More...
 
void resetInputContext ()
 This function can be called on the widget that currently has focus to reset the input method operating on it. More...
 
virtual void styleChange (QStyle &)
 
virtual void tabletEvent (QTabletEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive tablet events for the widget. More...
 
virtual void windowActivationChange (bool)
 
virtual bool winEvent (MSG *message, long *result)
 This special event handler can be reimplemented in a subclass to receive native Windows events which are passed in the message parameter. More...
 
virtual bool x11Event (XEvent *)
 This special event handler can be reimplemented in a subclass to receive native X11 events passed in the event parameter. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Functions inherited from QPaintDevice
 QPaintDevice ()
 

Properties

Qt::Alignment alignment
 the alignment of the scene in the view when the whole scene is visible. More...
 
QBrush backgroundBrush
 the background brush of the scene. More...
 
CacheMode cacheMode
 which parts of the view are cached More...
 
DragMode dragMode
 the behavior for dragging the mouse over the scene while the left mouse button is pressed. More...
 
QBrush foregroundBrush
 the foreground brush of the scene. More...
 
bool interactive
 whether the view allowed scene interaction. More...
 
OptimizationFlags optimizationFlags
 flags that can be used to tune QGraphicsView's performance. More...
 
QPainter::RenderHints renderHints
 the default render hints for the view More...
 
ViewportAnchor resizeAnchor
 how the view should position the scene when the view is resized. More...
 
Qt::ItemSelectionMode rubberBandSelectionMode
 the behavior for selecting items with a rubber band selection rectangle. More...
 
QRectF sceneRect
 the area of the scene visualized by this view. More...
 
ViewportAnchor transformationAnchor
 how the view should position the scene during transformations. More...
 
ViewportUpdateMode viewportUpdateMode
 how the viewport should update its contents. More...
 

Friends

class QGraphicsItemPrivate
 
class QGraphicsScene
 
class QGraphicsScenePrivate
 
class QGraphicsSceneWidget
 

Additional Inherited Members

- Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 This signal is emitted when the widget's contextMenuPolicy is Qt::CustomContextMenu, and the user has requested a context menu on the widget. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QWidget
static QWidgetfind (WId)
 Returns a pointer to the widget with window identifer/handle id. More...
 
static QWidgetkeyboardGrabber ()
 Returns the widget that is currently grabbing the keyboard input. More...
 
static QWidgetmouseGrabber ()
 Returns the widget that is currently grabbing the mouse input. More...
 
static void setTabOrder (QWidget *, QWidget *)
 Puts the second widget after the first widget in the focus order. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Functions inherited from QPaintDevice
static QWSDisplayqwsDisplay ()
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Variables inherited from QPaintDevice
ushort painters
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

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

Since
4.2

QGraphicsView visualizes the contents of a QGraphicsScene in a scrollable viewport. To create a scene with geometrical items, see QGraphicsScene's documentation. QGraphicsView is part of the Graphics View Framework.

To visualize a scene, you start by constructing a QGraphicsView object, passing the address of the scene you want to visualize to QGraphicsView's constructor. Alternatively, you can call setScene() to set the scene at a later point. After you call show(), the view will by default scroll to the center of the scene and display any items that are visible at this point. For example:

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

You can explicitly scroll to any position on the scene by using the scroll bars, or by calling centerOn(). By passing a point to centerOn(), QGraphicsView will scroll its viewport to ensure that the point is centered in the view. An overload is provided for scrolling to a QGraphicsItem, in which case QGraphicsView will see to that the center of the item is centered in the view. If all you want is to ensure that a certain area is visible, (but not necessarily centered,) you can call ensureVisible() instead.

QGraphicsView can be used to visualize a whole scene, or only parts of it. The visualized area is by default detected automatically when the view is displayed for the first time (by calling QGraphicsScene::itemsBoundingRect()). To set the visualized area rectangle yourself, you can call setSceneRect(). This will adjust the scroll bars' ranges appropriately. Note that although the scene supports a virtually unlimited size, the range of the scroll bars will never exceed the range of an integer (INT_MIN, INT_MAX).

QGraphicsView visualizes the scene by calling render(). By default, the items are drawn onto the viewport by using a regular QPainter, and using default render hints. To change the default render hints that QGraphicsView passes to QPainter when painting items, you can call setRenderHints().

By default, QGraphicsView provides a regular QWidget for the viewport widget. You can access this widget by calling viewport(), or you can replace it by calling setViewport(). To render using OpenGL, simply call setViewport(new QGLWidget). QGraphicsView takes ownership of the viewport widget.

QGraphicsView supports affine transformations, using QTransform. You can either pass a matrix to setTransform(), or you can call one of the convenience functions rotate(), scale(), translate() or shear(). The most two common transformations are scaling, which is used to implement zooming, and rotation. QGraphicsView keeps the center of the view fixed during a transformation. Because of the scene alignment (setAligment()), translating the view will have no visual impact.

You can interact with the items on the scene by using the mouse and keyboard. QGraphicsView translates the mouse and key events into scene events, (events that inherit QGraphicsSceneEvent,), and forward them to the visualized scene. In the end, it's the individual item that handles the events and reacts to them. For example, if you click on a selectable item, the item will typically let the scene know that it has been selected, and it will also redraw itself to display a selection rectangle. Similiary, if you click and drag the mouse to move a movable item, it's the item that handles the mouse moves and moves itself. Item interaction is enabled by default, and you can toggle it by calling setInteractive().

You can also provide your own custom scene interaction, by creating a subclass of QGraphicsView, and reimplementing the mouse and key event handlers. To simplify how you programmatically interact with items in the view, QGraphicsView provides the mapping functions mapToScene() and mapFromScene(), and the item accessors items() and itemAt(). These functions allow you to map points, rectangles, polygons and paths between view coordinates and scene coordinates, and to find items on the scene using view coordinates.

graphicsview-view.png
See also
QGraphicsScene, QGraphicsItem, QGraphicsSceneEvent

Definition at line 64 of file qgraphicsview.h.

Enumerations

◆ CacheModeFlag

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

  • CacheNone All painting is done directly onto the viewport.
  • CacheBackground 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
Enumerator
CacheNone 
CacheBackground 

Definition at line 92 of file qgraphicsview.h.

◆ DragMode

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

  • NoDrag Nothing happens; the mouse event is ignored.
  • ScrollHandDrag The cursor changes into a pointing hand, and dragging the mouse around will scroll the scrolbars. This mode works both in interactive and non-interactive mode.
  • RubberBandDrag 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()
Enumerator
NoDrag 
ScrollHandDrag 
RubberBandDrag 

Definition at line 98 of file qgraphicsview.h.

◆ OptimizationFlag

This enum describes flags that you can enable to improve rendering performance in QGraphicsView.

Since
4.3

By default, none of these flags are set. Note that setting a flag usually imposes a side effect, and this effect can vary between paint devices and platforms.

  • DontClipPainter This value is obsolete and has no effect.
  • DontSavePainterState When rendering, QGraphicsView protects the painter state (see QPainter::save()) when rendering the background or foreground, and when rendering each item. This allows you to leave the painter in an altered state (i.e., you can call QPainter::setPen() or QPainter::setBrush() without restoring the state after painting). However, if the items consistently do restore the state, you should enable this flag to prevent QGraphicsView from doing the same.
  • DontAdjustForAntialiasing Disables QGraphicsView's antialiasing auto-adjustment of exposed areas. Items that render antialiased lines on the boundaries of their QGraphicsItem::boundingRect() can end up rendering parts of the line outside. To prevent rendering artifacts, QGraphicsView expands all exposed regions by 2 pixels in all directions. If you enable this flag, QGraphicsView will no longer perform these adjustments, minimizing the areas that require redrawing, which improves performance. A common side effect is that items that do draw with antialiasing can leave painting traces behind on the scene as they are moved.
Enumerator
DontClipPainter 
DontSavePainterState 
DontAdjustForAntialiasing 
IndirectPainting 

Definition at line 112 of file qgraphicsview.h.

◆ ViewportAnchor

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

  • NoAnchor No anchor, i.e. the view leaves the scene's position unchanged.
  • AnchorViewCenter The scene point at the center of the view is used as the anchor.
  • AnchorUnderMouse The point under the mouse is used as the anchor.
See also
resizeAnchor, transformationAnchor
Enumerator
NoAnchor 
AnchorViewCenter 
AnchorUnderMouse 

Definition at line 86 of file qgraphicsview.h.

◆ ViewportUpdateMode

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

Since
4.3
  • FullViewportUpdate 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.
  • MinimalViewportUpdate 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.
  • SmartViewportUpdate QGraphicsView will attempt to find an optimal update mode by analyzing the areas that require a redraw.
  • BoundingRectViewportUpdate 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.
  • NoViewportUpdate 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
Enumerator
FullViewportUpdate 
MinimalViewportUpdate 
SmartViewportUpdate 
NoViewportUpdate 
BoundingRectViewportUpdate 

Definition at line 104 of file qgraphicsview.h.

Constructors and Destructors

◆ QGraphicsView() [1/3]

QGraphicsView::QGraphicsView ( QWidget parent = 0)

Constructs a QGraphicsView.

parent is passed to QWidget's constructor.

Definition at line 1141 of file qgraphicsview.cpp.

1143 {
1144  setViewport(0);
1145  setAcceptDrops(true);
1147  // Investigate leaving these disabled by default.
1150 }
QWidget * viewport() const
Returns the viewport widget.
void setBackgroundRole(QPalette::ColorRole)
Sets the background role of the widget to role.
Definition: qwidget.cpp:4708
QAbstractScrollArea(QWidget *parent=0)
Constructs a viewport.
void setAcceptDrops(bool on)
Definition: qwidget.cpp:3534
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
void setViewport(QWidget *widget)
Sets the viewport to be the given widget.

◆ QGraphicsView() [2/3]

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

Constructs a QGraphicsView and sets the visualized scene to scene.

parent is passed to QWidget's constructor.

Definition at line 1156 of file qgraphicsview.cpp.

1158 {
1159  setScene(scene);
1160  setViewport(0);
1161  setAcceptDrops(true);
1163  // Investigate leaving these disabled by default.
1166 }
QWidget * viewport() const
Returns the viewport widget.
void setBackgroundRole(QPalette::ColorRole)
Sets the background role of the widget to role.
Definition: qwidget.cpp:4708
void setScene(QGraphicsScene *scene)
Sets the current scene to scene.
QAbstractScrollArea(QWidget *parent=0)
Constructs a viewport.
void setAcceptDrops(bool on)
Definition: qwidget.cpp:3534
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
void setViewport(QWidget *widget)
Sets the viewport to be the given widget.

◆ ~QGraphicsView()

QGraphicsView::~QGraphicsView ( )

Destructs the QGraphicsView object.

Definition at line 1185 of file qgraphicsview.cpp.

1186 {
1187  Q_D(QGraphicsView);
1188  if (d->scene)
1189  d->scene->d_func()->views.removeAll(this);
1190  delete d->lastDragDropEvent;
1191 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ QGraphicsView() [3/3]

QGraphicsView::QGraphicsView ( QGraphicsViewPrivate dd,
QWidget parent = 0 
)
protected
Warning
This function is not part of the public interface.

Definition at line 1171 of file qgraphicsview.cpp.

1172  : QAbstractScrollArea(dd, parent)
1173 {
1174  setViewport(0);
1175  setAcceptDrops(true);
1177  // Investigate leaving these disabled by default.
1180 }
QWidget * viewport() const
Returns the viewport widget.
void setBackgroundRole(QPalette::ColorRole)
Sets the background role of the widget to role.
Definition: qwidget.cpp:4708
QAbstractScrollArea(QWidget *parent=0)
Constructs a viewport.
void setAcceptDrops(bool on)
Definition: qwidget.cpp:3534
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
void setViewport(QWidget *widget)
Sets the viewport to be the given widget.

Functions

◆ alignment()

Qt::Alignment QGraphicsView::alignment ( ) const

Referenced by setAlignment(), and setRenderHint().

◆ backgroundBrush()

QBrush QGraphicsView::backgroundBrush ( ) const

◆ cacheMode()

CacheMode QGraphicsView::cacheMode ( ) const

◆ centerOn() [1/3]

void QGraphicsView::centerOn ( const QPointF pos)

Scrolls the contents of the viewport to ensure that 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.

Note
If the item is close to or outside the border, it will be visible in the view, but not centered.
See also
ensureVisible()

Definition at line 1880 of file qgraphicsview.cpp.

Referenced by centerOn(), and fitInView().

1881 {
1882  Q_D(QGraphicsView);
1883  qreal width = viewport()->width();
1884  qreal height = viewport()->height();
1885  QPointF viewPoint = d->matrix.map(pos);
1886  QPointF oldCenterPoint = pos;
1887 
1888  if (!d->leftIndent) {
1889  if (isRightToLeft()) {
1890  qint64 horizontal = 0;
1891  horizontal += horizontalScrollBar()->minimum();
1892  horizontal += horizontalScrollBar()->maximum();
1893  horizontal -= int(viewPoint.x() - width / qreal(2.0));
1894  horizontalScrollBar()->setValue(horizontal);
1895  } else {
1896  horizontalScrollBar()->setValue(int(viewPoint.x() - width / qreal(2.0)));
1897  }
1898  }
1899  if (!d->topIndent)
1900  verticalScrollBar()->setValue(int(viewPoint.y() - height / qreal(2.0)));
1901  d->lastCenterPoint = oldCenterPoint;
1902 }
QPoint pos() const
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
int minimum() const
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QScrollBar * verticalScrollBar() const
Returns the vertical scroll bar.
#define Q_D(Class)
Definition: qglobal.h:2482
int height() const
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QWidget * viewport() const
Returns the viewport widget.
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
int width() const
__int64 qint64
Definition: qglobal.h:942
QScrollBar * horizontalScrollBar() const
Returns the horizontal scroll bar.
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
bool isRightToLeft() const
Definition: qwidget.h:428
int maximum() const

◆ centerOn() [2/3]

void QGraphicsView::centerOn ( qreal  x,
qreal  y 
)
inline

This function is provided for convenience.

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

It's equivalent to calling centerOn(QPointF(x, y)).

Definition at line 289 of file qgraphicsview.h.

290 { centerOn(QPointF(ax, ay)); }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void centerOn(const QPointF &pos)
Scrolls the contents of the viewport to ensure that the scene coordinate pos, is centered in the view...

◆ centerOn() [3/3]

void QGraphicsView::centerOn ( const QGraphicsItem item)

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

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

See also
ensureVisible()

Definition at line 1926 of file qgraphicsview.cpp.

1927 {
1928  centerOn(item->sceneBoundingRect().center());
1929 }
void centerOn(const QPointF &pos)
Scrolls the contents of the viewport to ensure that the scene coordinate pos, is centered in the view...
QPointF center() const
Returns the center point of the rectangle.
Definition: qrect.h:686
QRectF sceneBoundingRect() const
Returns the bounding rect of this item in scene coordinates, by combining sceneTransform() with bound...

◆ contextMenuEvent()

void QGraphicsView::contextMenuEvent ( QContextMenuEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 2981 of file qgraphicsview.cpp.

2982 {
2983  Q_D(QGraphicsView);
2984  if (!d->scene || !d->sceneInteractionAllowed)
2985  return;
2986 
2987  d->mousePressViewPoint = event->pos();
2988  d->mousePressScenePoint = mapToScene(d->mousePressViewPoint);
2989  d->mousePressScreenPoint = event->globalPos();
2990  d->lastMouseMoveScenePoint = d->mousePressScenePoint;
2991  d->lastMouseMoveScreenPoint = d->mousePressScreenPoint;
2992 
2994  contextEvent.setWidget(viewport());
2995  contextEvent.setScenePos(d->mousePressScenePoint);
2996  contextEvent.setScreenPos(d->mousePressScreenPoint);
2997  contextEvent.setModifiers(event->modifiers());
2998  contextEvent.setReason((QGraphicsSceneContextMenuEvent::Reason)(event->reason()));
2999  contextEvent.setAccepted(event->isAccepted());
3000  QApplication::sendEvent(d->scene, &contextEvent);
3001  event->setAccepted(contextEvent.isAccepted());
3002 }
double d
Definition: qnumeric_p.h:62
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget * viewport() const
Returns the viewport widget.
bool isAccepted() const
Definition: qcoreevent.h:307
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
Reason reason() const
Returns the reason for this context event.
Definition: qevent.h:415
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition: qevent.h:79
Reason
This enum describes the reason why the context event was sent.
The QGraphicsSceneContextMenuEvent class provides context menu events in the graphics view framework...

◆ dragEnterEvent()

void QGraphicsView::dragEnterEvent ( QDragEnterEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3038 of file qgraphicsview.cpp.

3039 {
3040 #ifndef QT_NO_DRAGANDDROP
3041  Q_D(QGraphicsView);
3042  if (!d->scene || !d->sceneInteractionAllowed)
3043  return;
3044 
3045  // Disable replaying of mouse move events.
3046  d->useLastMouseEvent = false;
3047 
3048  // Generate a scene event.
3050  d->populateSceneDragDropEvent(&sceneEvent, event);
3051 
3052  // Store it for later use.
3053  d->storeDragDropEvent(&sceneEvent);
3054 
3055  // Send it to the scene.
3056  QApplication::sendEvent(d->scene, &sceneEvent);
3057 
3058  // Accept the originating event if the scene accepted the scene event.
3059  if (sceneEvent.isAccepted()) {
3060  event->setAccepted(true);
3061  event->setDropAction(sceneEvent.dropAction());
3062  }
3063 #else
3064  Q_UNUSED(event)
3065 #endif
3066 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QGraphicsSceneDragDropEvent class provides events for drag and drop in the graphics view framewor...
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ dragLeaveEvent()

void QGraphicsView::dragLeaveEvent ( QDragLeaveEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3071 of file qgraphicsview.cpp.

3072 {
3073 #ifndef QT_NO_DRAGANDDROP
3074  Q_D(QGraphicsView);
3075  if (!d->scene || !d->sceneInteractionAllowed)
3076  return;
3077  if (!d->lastDragDropEvent) {
3078  qWarning("QGraphicsView::dragLeaveEvent: drag leave received before drag enter");
3079  return;
3080  }
3081 
3082  // Generate a scene event.
3084  sceneEvent.setScenePos(d->lastDragDropEvent->scenePos());
3085  sceneEvent.setScreenPos(d->lastDragDropEvent->screenPos());
3086  sceneEvent.setButtons(d->lastDragDropEvent->buttons());
3087  sceneEvent.setModifiers(d->lastDragDropEvent->modifiers());
3088  sceneEvent.setPossibleActions(d->lastDragDropEvent->possibleActions());
3089  sceneEvent.setProposedAction(d->lastDragDropEvent->proposedAction());
3090  sceneEvent.setDropAction(d->lastDragDropEvent->dropAction());
3091  sceneEvent.setMimeData(d->lastDragDropEvent->mimeData());
3092  sceneEvent.setWidget(d->lastDragDropEvent->widget());
3093  sceneEvent.setSource(d->lastDragDropEvent->source());
3094  delete d->lastDragDropEvent;
3095  d->lastDragDropEvent = 0;
3096 
3097  // Send it to the scene.
3098  QApplication::sendEvent(d->scene, &sceneEvent);
3099 
3100  // Accept the originating event if the scene accepted the scene event.
3101  if (sceneEvent.isAccepted())
3102  event->setAccepted(true);
3103 #else
3104  Q_UNUSED(event)
3105 #endif
3106 }
double d
Definition: qnumeric_p.h:62
void setAccepted(bool accepted)
Definition: qcoreevent.h:306
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QGraphicsSceneDragDropEvent class provides events for drag and drop in the graphics view framewor...
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ dragMode()

DragMode QGraphicsView::dragMode ( ) const

Referenced by setOptimizationFlag().

◆ dragMoveEvent()

void QGraphicsView::dragMoveEvent ( QDragMoveEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3111 of file qgraphicsview.cpp.

3112 {
3113 #ifndef QT_NO_DRAGANDDROP
3114  Q_D(QGraphicsView);
3115  if (!d->scene || !d->sceneInteractionAllowed)
3116  return;
3117 
3118  // Generate a scene event.
3120  d->populateSceneDragDropEvent(&sceneEvent, event);
3121 
3122  // Store it for later use.
3123  d->storeDragDropEvent(&sceneEvent);
3124 
3125  // Send it to the scene.
3126  QApplication::sendEvent(d->scene, &sceneEvent);
3127 
3128  // Ignore the originating event if the scene ignored the scene event.
3129  event->setAccepted(sceneEvent.isAccepted());
3130  if (sceneEvent.isAccepted())
3131  event->setDropAction(sceneEvent.dropAction());
3132 #else
3133  Q_UNUSED(event)
3134 #endif
3135 }
double d
Definition: qnumeric_p.h:62
void setDropAction(Qt::DropAction action)
Sets the action to be performed on the data by the target.
Definition: qevent.cpp:2746
#define Q_D(Class)
Definition: qglobal.h:2482
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QGraphicsSceneDragDropEvent class provides events for drag and drop in the graphics view framewor...
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ drawBackground()

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 function to provide a custom background for this view.

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

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

The default implementation fills rect using the view's backgroundBrush. If no such brush is defined (the default), the scene's drawBackground() function is called instead.

See also
drawForeground(), QGraphicsScene::drawBackground()

Definition at line 3783 of file qgraphicsview.cpp.

Referenced by paintEvent(), and render().

3784 {
3785  Q_D(QGraphicsView);
3786  if (d->scene && d->backgroundBrush.style() == Qt::NoBrush) {
3787  d->scene->drawBackground(painter, rect);
3788  return;
3789  }
3790 
3791  painter->fillRect(rect, d->backgroundBrush);
3792 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ drawForeground()

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 function to provide a custom foreground for this view.

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

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

The default implementation fills rect using the view's foregroundBrush. If no such brush is defined (the default), the scene's drawForeground() function is called instead.

See also
drawBackground(), QGraphicsScene::drawForeground()

Definition at line 3811 of file qgraphicsview.cpp.

Referenced by paintEvent(), and render().

3812 {
3813  Q_D(QGraphicsView);
3814  if (d->scene && d->foregroundBrush.style() == Qt::NoBrush) {
3815  d->scene->drawForeground(painter, rect);
3816  return;
3817  }
3818 
3819  painter->fillRect(rect, d->foregroundBrush);
3820 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ drawItems()

void QGraphicsView::drawItems ( QPainter painter,
int  numItems,
QGraphicsItem items[],
const QStyleOptionGraphicsItem  options[] 
)
protectedvirtual

Draws the items items in the scene using painter, after the background and before the foreground are drawn.

numItems is the number of items in items and options in options. options is a list of styleoptions; one for each item. Reimplement this function to provide custom item drawing for this view.

The default implementation calls the scene's drawItems() function.

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

See also
drawForeground(), drawBackground(), QGraphicsScene::drawItems()

Definition at line 3842 of file qgraphicsview.cpp.

Referenced by paintEvent(), and render().

3845 {
3846  Q_D(QGraphicsView);
3847  if (d->scene) {
3848  QWidget *widget = painter->device() == viewport() ? viewport() : 0;
3849  d->scene->drawItems(painter, numItems, items, options, widget);
3850  }
3851 }
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or 0 if the painter is not acti...
Definition: qpainter.cpp:1530
double d
Definition: qnumeric_p.h:62
QPointer< QWidget > widget
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget * viewport() const
Returns the viewport widget.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ dropEvent()

void QGraphicsView::dropEvent ( QDropEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3008 of file qgraphicsview.cpp.

3009 {
3010 #ifndef QT_NO_DRAGANDDROP
3011  Q_D(QGraphicsView);
3012  if (!d->scene || !d->sceneInteractionAllowed)
3013  return;
3014 
3015  // Generate a scene event.
3017  d->populateSceneDragDropEvent(&sceneEvent, event);
3018 
3019  // Send it to the scene.
3020  QApplication::sendEvent(d->scene, &sceneEvent);
3021 
3022  // Accept the originating event if the scene accepted the scene event.
3023  event->setAccepted(sceneEvent.isAccepted());
3024  if (sceneEvent.isAccepted())
3025  event->setDropAction(sceneEvent.dropAction());
3026 
3027  delete d->lastDragDropEvent;
3028  d->lastDragDropEvent = 0;
3029 
3030 #else
3031  Q_UNUSED(event)
3032 #endif
3033 }
double d
Definition: qnumeric_p.h:62
void setDropAction(Qt::DropAction action)
Sets the action to be performed on the data by the target.
Definition: qevent.cpp:2746
#define Q_D(Class)
Definition: qglobal.h:2482
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QGraphicsSceneDragDropEvent class provides events for drag and drop in the graphics view framewor...
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ ensureVisible() [1/3]

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

Scrolls the contents of the viewport so that the scene rectangle rect is visible, with margins specified in pixels by xmargin and ymargin.

If the specified rect cannot be reached, the contents are scrolled to the nearest valid position. The default value for both margins is 50 pixels.

See also
centerOn()

Definition at line 1940 of file qgraphicsview.cpp.

Referenced by ensureVisible(), and QGraphicsItem::ensureVisible().

1941 {
1942  Q_D(QGraphicsView);
1943  qreal width = viewport()->width();
1944  qreal height = viewport()->height();
1945  QRectF viewRect = d->matrix.mapRect(rect);
1946 
1947  qreal left = d->horizontalScroll();
1948  qreal right = left + width;
1949  qreal top = d->verticalScroll();
1950  qreal bottom = top + height;
1951 
1952  if (viewRect.left() <= left + xmargin) {
1953  // need to scroll from the left
1954  if (!d->leftIndent)
1955  horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - qreal(0.5)));
1956  }
1957  if (viewRect.right() >= right - xmargin) {
1958  // need to scroll from the right
1959  if (!d->leftIndent)
1960  horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + qreal(0.5)));
1961  }
1962  if (viewRect.top() <= top + ymargin) {
1963  // need to scroll from the top
1964  if (!d->topIndent)
1965  verticalScrollBar()->setValue(int(viewRect.top() - ymargin - qreal(0.5)));
1966  }
1967  if (viewRect.bottom() >= bottom - ymargin) {
1968  // need to scroll from the bottom
1969  if (!d->topIndent)
1970  verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + qreal(0.5)));
1971  }
1972 }
double d
Definition: qnumeric_p.h:62
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
double qreal
Definition: qglobal.h:1193
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
QScrollBar * verticalScrollBar() const
Returns the vertical scroll bar.
#define Q_D(Class)
Definition: qglobal.h:2482
int height() const
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
QWidget * viewport() const
Returns the viewport widget.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
int width() const
QScrollBar * horizontalScrollBar() const
Returns the horizontal scroll bar.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ ensureVisible() [2/3]

void QGraphicsView::ensureVisible ( qreal  x,
qreal  y,
qreal  w,
qreal  h,
int  xmargin = 50,
int  ymargin = 50 
)
inline

This function is provided for convenience.

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

It's equivalent to calling ensureVisible(QRectF(x, y, w, h), xmargin, ymargin).

Definition at line 291 of file qgraphicsview.h.

292 { ensureVisible(QRectF(ax, ay, aw, ah), xmargin, ymargin); }
void ensureVisible(const QRectF &rect, int xmargin=50, int ymargin=50)
Scrolls the contents of the viewport so that the scene rectangle rect is visible, with margins specif...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ ensureVisible() [3/3]

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

Scrolls the contents of the viewport so that the center of item item is visible, with margins specified in pixels by xmargin and ymargin.

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

If the specified point cannot be reached, the contents are scrolled to the nearest valid position. The default value for both margins is 50 pixels.

See also
centerOn()

Definition at line 1999 of file qgraphicsview.cpp.

2000 {
2001  ensureVisible(item->sceneBoundingRect(), xmargin, ymargin);
2002 }
void ensureVisible(const QRectF &rect, int xmargin=50, int ymargin=50)
Scrolls the contents of the viewport so that the scene rectangle rect is visible, with margins specif...
QRectF sceneBoundingRect() const
Returns the bounding rect of this item in scene coordinates, by combining sceneTransform() with bound...

◆ event()

bool QGraphicsView::event ( QEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QObject.

Definition at line 2813 of file qgraphicsview.cpp.

Referenced by viewportEvent().

2814 {
2815  Q_D(QGraphicsView);
2816 
2817  if (d->sceneInteractionAllowed) {
2818  switch (event->type()) {
2820  if (d->scene)
2821  return QApplication::sendEvent(d->scene, event);
2822  break;
2823  case QEvent::KeyPress:
2824  if (d->scene) {
2825  QKeyEvent *k = static_cast<QKeyEvent *>(event);
2826  if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) {
2827  // Send the key events to the scene. This will invoke the
2828  // scene's tab focus handling, and if the event is
2829  // accepted, we return (prevent further event delivery),
2830  // and the base implementation will call QGraphicsView's
2831  // focusNextPrevChild() function. If the event is ignored,
2832  // we fall back to standard tab focus handling.
2833  QApplication::sendEvent(d->scene, event);
2834  if (event->isAccepted())
2835  return true;
2836  // Ensure the event doesn't propagate just because the
2837  // scene ignored it. If the event propagates, then tab
2838  // handling will be called twice (this and parent).
2839  event->accept();
2840  }
2841  }
2842  break;
2843  default:
2844  break;
2845  }
2846  }
2847 
2848  return QAbstractScrollArea::event(event);
2849 }
double d
Definition: qnumeric_p.h:62
The QKeyEvent class describes a key event.
Definition: qevent.h:224
#define Q_D(Class)
Definition: qglobal.h:2482
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
bool isAccepted() const
Definition: qcoreevent.h:307
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
bool event(QEvent *event)
Reimplemented Function
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
bool event(QEvent *)
Reimplemented Function
Type type() const
Returns the event type.
Definition: qcoreevent.h:303

◆ fitInView() [1/3]

void QGraphicsView::fitInView ( const QRectF rect,
Qt::AspectRatioMode  aspectRatioMode = Qt::IgnoreAspectRatio 
)

Scales the view matrix and scrolls the scroll bars to ensure that the scene rectangle rect fits inside the viewport.

rect must be inside the scene rect; otherwise, fitInView() cannot guarantee that the whole rect is visible.

This function keeps the view's rotation, translation, or shear. The view is scaled according to aspectRatioMode. rect will be centered in the view if it does not fit tightly.

It's common to call fitInView() from inside a reimplementation of resizeEvent(), to ensure that the whole scene, or parts of the scene, scales automatically to fit the new size of the viewport as the view is resized. Note though, that calling fitInView() from inside resizeEvent() can lead to unwanted resize recursion, if the new transformation toggles the automatic state of the scrollbars. You can toggle the scrollbar policies to always on or always off to prevent this (see horizontalScrollBarPolicy() and verticalScrollBarPolicy()).

If rect is empty, or if the viewport is too small, this function will do nothing.

See also
setTransform(), ensureVisible(), centerOn()

Definition at line 2028 of file qgraphicsview.cpp.

Referenced by fitInView().

2029 {
2030  Q_D(QGraphicsView);
2031  if (!d->scene || rect.isNull())
2032  return;
2033 
2034  // Reset the view scale to 1:1.
2035  QRectF unity = d->matrix.mapRect(QRectF(0, 0, 1, 1));
2036  if (unity.isEmpty())
2037  return;
2038  scale(1 / unity.width(), 1 / unity.height());
2039 
2040  // Find the ideal x / y scaling ratio to fit \a rect in the view.
2041  int margin = 2;
2042  QRectF viewRect = viewport()->rect().adjusted(margin, margin, -margin, -margin);
2043  if (viewRect.isEmpty())
2044  return;
2045  QRectF sceneRect = d->matrix.mapRect(rect);
2046  if (sceneRect.isEmpty())
2047  return;
2048  qreal xratio = viewRect.width() / sceneRect.width();
2049  qreal yratio = viewRect.height() / sceneRect.height();
2050 
2051  // Respect the aspect ratio mode.
2052  switch (aspectRatioMode) {
2053  case Qt::KeepAspectRatio:
2054  xratio = yratio = qMin(xratio, yratio);
2055  break;
2057  xratio = yratio = qMax(xratio, yratio);
2058  break;
2059  case Qt::IgnoreAspectRatio:
2060  break;
2061  }
2062 
2063  // Scale and center on the center of \a rect.
2064  scale(xratio, yratio);
2065  centerOn(rect.center());
2066 }
double d
Definition: qnumeric_p.h:62
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
#define Q_D(Class)
Definition: qglobal.h:2482
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QWidget * viewport() const
Returns the viewport widget.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QRectF sceneRect() const
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
void scale(qreal sx, qreal sy)
Scales the current view transformation by (sx, sy).
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:658
void centerOn(const QPointF &pos)
Scrolls the contents of the viewport to ensure that the scene coordinate pos, is centered in the view...
QPointF center() const
Returns the center point of the rectangle.
Definition: qrect.h:686
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655

◆ fitInView() [2/3]

void QGraphicsView::fitInView ( qreal  x,
qreal  y,
qreal  w,
qreal  h,
Qt::AspectRatioMode  aspectRadioMode = Qt::IgnoreAspectRatio 
)
inline

Definition at line 293 of file qgraphicsview.h.

294 { fitInView(QRectF(ax, ay, w, h), mode); }
void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode=Qt::IgnoreAspectRatio)
Scales the view matrix and scrolls the scroll bars to ensure that the scene rectangle rect fits insid...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ fitInView() [3/3]

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

Ensures that item fits tightly inside the view, scaling the view according to aspectRatioMode.

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

See also
ensureVisible(), centerOn()

Definition at line 2094 of file qgraphicsview.cpp.

2095 {
2096  QPainterPath path = item->isClipped() ? item->clipPath() : item->shape();
2097  if (item->d_ptr->hasTranslateOnlySceneTransform()) {
2098  path.translate(item->d_ptr->sceneTransform.dx(), item->d_ptr->sceneTransform.dy());
2099  fitInView(path.boundingRect(), aspectRatioMode);
2100  } else {
2101  fitInView(item->d_ptr->sceneTransform.map(path).boundingRect(), aspectRatioMode);
2102  }
2103 }
bool isClipped() const
Returns true if this item is clipped.
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
void translate(qreal dx, qreal dy)
Translates all elements in the path by ({dx}, {dy}).
QScopedPointer< QGraphicsItemPrivate > d_ptr
bool hasTranslateOnlySceneTransform()
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
virtual QPainterPath shape() const
Returns the shape of this item as a QPainterPath in local coordinates.
void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode=Qt::IgnoreAspectRatio)
Scales the view matrix and scrolls the scroll bars to ensure that the scene rectangle rect fits insid...
QRectF boundingRect() const
Returns the bounding rectangle of this painter path as a rectangle with floating point precision...
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
QPainterPath clipPath() const
Returns this item&#39;s clip path, or an empty QPainterPath if this item is not clipped.
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273

◆ focusInEvent()

void QGraphicsView::focusInEvent ( QFocusEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3140 of file qgraphicsview.cpp.

3141 {
3142  Q_D(QGraphicsView);
3143  d->updateInputMethodSensitivity();
3145  if (d->scene)
3146  QApplication::sendEvent(d->scene, event);
3147  // Pass focus on if the scene cannot accept focus.
3148  if (!d->scene || !event->isAccepted())
3150 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool isAccepted() const
Definition: qcoreevent.h:307
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
virtual void focusInEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition: qwidget.cpp:9431

◆ focusNextPrevChild()

bool QGraphicsView::focusNextPrevChild ( bool  next)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3155 of file qgraphicsview.cpp.

3156 {
3158 }
virtual bool focusNextPrevChild(bool next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can&#39;t.
Definition: qwidget.cpp:6836

◆ focusOutEvent()

void QGraphicsView::focusOutEvent ( QFocusEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3163 of file qgraphicsview.cpp.

3164 {
3165  Q_D(QGraphicsView);
3167  if (d->scene)
3168  QApplication::sendEvent(d->scene, event);
3169 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
virtual void focusOutEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
Definition: qwidget.cpp:9457
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ foregroundBrush()

QBrush QGraphicsView::foregroundBrush ( ) const

Referenced by setBackgroundBrush().

◆ inputMethodEvent()

void QGraphicsView::inputMethodEvent ( QInputMethodEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3759 of file qgraphicsview.cpp.

3760 {
3761  Q_D(QGraphicsView);
3762  if (d->scene)
3763  QApplication::sendEvent(d->scene, event);
3764 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ inputMethodQuery()

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

Reimplemented Function

Reimplemented from QWidget.

Definition at line 2590 of file qgraphicsview.cpp.

2591 {
2592  Q_D(const QGraphicsView);
2593  if (!d->scene)
2594  return QVariant();
2595 
2596  QVariant value = d->scene->inputMethodQuery(query);
2597  if (value.type() == QVariant::RectF)
2598  value = d->mapRectFromScene(value.toRectF());
2599  else if (value.type() == QVariant::PointF)
2600  value = mapFromScene(value.toPointF());
2601  else if (value.type() == QVariant::Rect)
2602  value = d->mapRectFromScene(value.toRect()).toRect();
2603  else if (value.type() == QVariant::Point)
2604  value = mapFromScene(value.toPoint());
2605  return value;
2606 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
QPointF toPointF() const
Returns the variant as a QPointF if the variant has type() Point or PointF ; otherwise returns a null...
Definition: qvariant.cpp:2509
QRectF toRectF() const
Returns the variant as a QRectF if the variant has type() Rect or RectF ; otherwise returns an invali...
Definition: qvariant.cpp:2463
#define Q_D(Class)
Definition: qglobal.h:2482
QPoint mapFromScene(const QPointF &point) const
Returns the scene coordinate point to viewport coordinates.
QRect toRect() const
Returns the variant as a QRect if the variant has type() Rect ; otherwise returns an invalid QRect...
Definition: qvariant.cpp:2416
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
QPoint toPoint() const
Returns the variant as a QPoint if the variant has type() Point or PointF ; otherwise returns a null ...
Definition: qvariant.cpp:2400

◆ invalidateScene

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

Invalidates and schedules a redraw of layers inside rect.

rect is in scene coordinates. Any cached content for layers inside rect is unconditionally invalidated and redrawn.

You can call this function to notify QGraphicsView of changes to the background or the foreground of the scene. It is commonly used for scenes with tile-based backgrounds to notify changes when QGraphicsView has enabled background caching.

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

See also
QGraphicsScene::invalidate(), update()

Definition at line 1601 of file qgraphicsview.cpp.

Referenced by QGraphicsScene::invalidate().

1602 {
1603  Q_D(QGraphicsView);
1604  if ((layers & QGraphicsScene::BackgroundLayer) && !d->mustResizeBackgroundPixmap) {
1605  QRect viewRect = mapFromScene(rect).boundingRect();
1606  if (viewport()->rect().intersects(viewRect)) {
1607  // The updated background area is exposed; schedule this area for
1608  // redrawing.
1609  d->backgroundPixmapExposed += viewRect;
1610  if (d->scene)
1611  d->scene->update(rect);
1612  }
1613  }
1614 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget * viewport() const
Returns the viewport widget.
QRect rect() const
QPoint mapFromScene(const QPointF &point) const
Returns the scene coordinate point to viewport coordinates.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ isInteractive()

bool QGraphicsView::isInteractive ( ) const

Definition at line 1629 of file qgraphicsview.cpp.

1630 {
1631  Q_D(const QGraphicsView);
1632  return d->sceneInteractionAllowed;
1633 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ isTransformed()

bool QGraphicsView::isTransformed ( ) const

Returns true if the view is transformed (i.

Since
4.6

e., a non-identity transform has been assigned, or the scrollbars are adjusted).

See also
setTransform(), horizontalScrollBar(), verticalScrollBar()

Definition at line 3888 of file qgraphicsview.cpp.

Referenced by QGraphicsScenePrivate::itemsAtPosition(), paintEvent(), QGraphicsScene::update(), and updateHelper().

3889 {
3890  Q_D(const QGraphicsView);
3891  return !d->identityMatrix || d->horizontalScroll() || d->verticalScroll();
3892 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ itemAt() [1/2]

QGraphicsItem * QGraphicsView::itemAt ( const QPoint pos) const

Returns the item at position pos, which is in viewport coordinates.

If there are several items at this position, this function returns the topmost item.

Example:

void CustomView::mousePressEvent(QMouseEvent *event)
{
if (QGraphicsItem *item = itemAt(event->pos())) {
qDebug() << "You clicked on item" << item;
} else {
qDebug() << "You didn't click on an item.";
}
}
See also
items(), {QGraphicsItem::Sorting}{Sorting}

Definition at line 2368 of file qgraphicsview.cpp.

Referenced by QGraphicsItem::unsetCursor().

2369 {
2370  Q_D(const QGraphicsView);
2371  if (!d->scene)
2372  return 0;
2373  QList<QGraphicsItem *> itemsAtPos = items(pos);
2374  return itemsAtPos.isEmpty() ? 0 : itemsAtPos.first();
2375 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
QList< QGraphicsItem * > items() const
Returns a list of all the items in the associated scene, in descending stacking order (i...
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ itemAt() [2/2]

QGraphicsItem * QGraphicsView::itemAt ( int  x,
int  y 
) const
inline

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

It's equivalent to calling itemAt(QPoint(x, y)).

Definition at line 299 of file qgraphicsview.h.

300 { return itemAt(QPoint(ax, ay)); }
QGraphicsItem * itemAt(const QPoint &pos) const
Returns the item at position pos, which is in viewport coordinates.
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53

◆ items() [1/7]

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

Returns a list of all the items in the associated scene, in descending stacking order (i.e., the first item in the returned list is the uppermost item).

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

Definition at line 2219 of file qgraphicsview.cpp.

Referenced by itemAt(), QGraphicsScenePrivate::itemsAtPosition(), and QGraphicsItem::setCursor().

2220 {
2221  Q_D(const QGraphicsView);
2222  if (!d->scene)
2223  return QList<QGraphicsItem *>();
2224  return d->scene->items();
2225 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ items() [2/7]

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

Returns a list of all the items at the position pos in the view.

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

This function is most commonly called from within mouse event handlers in a subclass in QGraphicsView. pos is in untransformed viewport coordinates, just like QMouseEvent::pos().

void CustomView::mousePressEvent(QMouseEvent *event)
{
qDebug() << "There are" << items(event->pos()).size()
<< "items at position" << mapToScene(event->pos());
}
See also
QGraphicsScene::items(), {QGraphicsItem::Sorting}{Sorting}

Definition at line 2241 of file qgraphicsview.cpp.

2242 {
2243  Q_D(const QGraphicsView);
2244  if (!d->scene)
2245  return QList<QGraphicsItem *>();
2246  // ### Unify these two, and use the items(QPointF) version in
2247  // QGraphicsScene instead. The scene items function could use the viewport
2248  // transform to map the point to a rect/polygon.
2249  if ((d->identityMatrix || d->matrix.type() <= QTransform::TxScale)) {
2250  // Use the rect version
2252  return d->scene->items(xinv.mapRect(QRectF(pos.x(), pos.y(), 1, 1)),
2255  viewportTransform());
2256  }
2257  // Use the polygon version
2258  return d->scene->items(mapToScene(pos.x(), pos.y(), 1, 1),
2261  viewportTransform());
2262 }
double d
Definition: qnumeric_p.h:62
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
#define Q_D(Class)
Definition: qglobal.h:2482
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
QTransform viewportTransform() const
Returns a matrix that maps viewport coordinates to scene coordinates.
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ items() [3/7]

QList< QGraphicsItem * > QGraphicsView::items ( int  x,
int  y 
) const
inline

This function is provided for convenience.

It's equivalent to calling items(QPoint(x, y)).

Definition at line 295 of file qgraphicsview.h.

296 { return items(QPoint(ax, ay)); }
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QList< QGraphicsItem * > items() const
Returns a list of all the items in the associated scene, in descending stacking order (i...

◆ items() [4/7]

QList< QGraphicsItem * > QGraphicsView::items ( const QRect rect,
Qt::ItemSelectionMode  mode = Qt::IntersectsItemShape 
) const

Returns a list of all the items that, depending on mode, are either contained by or intersect with rect.

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

rect is in viewport coordinates.

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

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

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

Definition at line 2292 of file qgraphicsview.cpp.

2293 {
2294  Q_D(const QGraphicsView);
2295  if (!d->scene)
2296  return QList<QGraphicsItem *>();
2297  return d->scene->items(mapToScene(rect), mode, Qt::DescendingOrder, viewportTransform());
2298 }
double d
Definition: qnumeric_p.h:62
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
#define Q_D(Class)
Definition: qglobal.h:2482
QTransform viewportTransform() const
Returns a matrix that maps viewport coordinates to scene coordinates.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ items() [5/7]

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

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

Definition at line 297 of file qgraphicsview.h.

298 { return items(QRect(ax, ay, w, h), mode); }
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QList< QGraphicsItem * > items() const
Returns a list of all the items in the associated scene, in descending stacking order (i...

◆ items() [6/7]

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

Returns a list of all the items that, depending on mode, are either contained by or intersect with polygon.

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

polygon is in viewport coordinates.

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

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

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

Definition at line 2326 of file qgraphicsview.cpp.

2327 {
2328  Q_D(const QGraphicsView);
2329  if (!d->scene)
2330  return QList<QGraphicsItem *>();
2331  return d->scene->items(mapToScene(polygon), mode, Qt::DescendingOrder, viewportTransform());
2332 }
double d
Definition: qnumeric_p.h:62
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
#define Q_D(Class)
Definition: qglobal.h:2482
QTransform viewportTransform() const
Returns a matrix that maps viewport coordinates to scene coordinates.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ items() [7/7]

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

Returns a list of all the items that, depending on mode, are either contained by or intersect with path.

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

path is in viewport coordinates.

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

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

Definition at line 2349 of file qgraphicsview.cpp.

2350 {
2351  Q_D(const QGraphicsView);
2352  if (!d->scene)
2353  return QList<QGraphicsItem *>();
2354  return d->scene->items(mapToScene(path), mode, Qt::DescendingOrder, viewportTransform());
2355 }
double d
Definition: qnumeric_p.h:62
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
#define Q_D(Class)
Definition: qglobal.h:2482
QTransform viewportTransform() const
Returns a matrix that maps viewport coordinates to scene coordinates.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ keyPressEvent()

void QGraphicsView::keyPressEvent ( QKeyEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3174 of file qgraphicsview.cpp.

3175 {
3176  Q_D(QGraphicsView);
3177  if (!d->scene || !d->sceneInteractionAllowed) {
3179  return;
3180  }
3181  QApplication::sendEvent(d->scene, event);
3182  if (!event->isAccepted())
3184 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool isAccepted() const
Definition: qcoreevent.h:307
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
void keyPressEvent(QKeyEvent *)
This function is called with key event e when key presses occur.

◆ keyReleaseEvent()

void QGraphicsView::keyReleaseEvent ( QKeyEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3189 of file qgraphicsview.cpp.

3190 {
3191  Q_D(QGraphicsView);
3192  if (!d->scene || !d->sceneInteractionAllowed)
3193  return;
3194  QApplication::sendEvent(d->scene, event);
3195  if (!event->isAccepted())
3197 }
double d
Definition: qnumeric_p.h:62
virtual void keyReleaseEvent(QKeyEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive key release events...
Definition: qwidget.cpp:9407
#define Q_D(Class)
Definition: qglobal.h:2482
bool isAccepted() const
Definition: qcoreevent.h:307
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ mapFromScene() [1/6]

QPoint QGraphicsView::mapFromScene ( const QPointF point) const

Returns the scene coordinate point to viewport coordinates.

See also
mapToScene()

Definition at line 2491 of file qgraphicsview.cpp.

Referenced by QGraphicsItemPrivate::genericMapFromScene(), inputMethodQuery(), invalidateScene(), and mapFromScene().

2492 {
2493  Q_D(const QGraphicsView);
2494  QPointF p = d->identityMatrix ? point : d->matrix.map(point);
2495  p.rx() -= d->horizontalScroll();
2496  p.ry() -= d->verticalScroll();
2497  return p.toPoint();
2498 }
double d
Definition: qnumeric_p.h:62
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_D(Class)
Definition: qglobal.h:2482
qreal & rx()
Returns a reference to the x coordinate of this point.
Definition: qpoint.h:302
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376
qreal & ry()
Returns a reference to the y coordinate of this point.
Definition: qpoint.h:307
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ mapFromScene() [2/6]

QPolygon QGraphicsView::mapFromScene ( const QRectF rect) const

Returns the scene rectangle rect to a viewport coordinate polygon.

See also
mapToScene()

Definition at line 2516 of file qgraphicsview.cpp.

2517 {
2518  Q_D(const QGraphicsView);
2519  QPointF tl;
2520  QPointF tr;
2521  QPointF br;
2522  QPointF bl;
2523  if (!d->identityMatrix) {
2524  const QTransform &x = d->matrix;
2525  tl = x.map(rect.topLeft());
2526  tr = x.map(rect.topRight());
2527  br = x.map(rect.bottomRight());
2528  bl = x.map(rect.bottomLeft());
2529  } else {
2530  tl = rect.topLeft();
2531  tr = rect.topRight();
2532  br = rect.bottomRight();
2533  bl = rect.bottomLeft();
2534  }
2535  QPointF scrollOffset(d->horizontalScroll(), d->verticalScroll());
2536  tl -= scrollOffset;
2537  tr -= scrollOffset;
2538  br -= scrollOffset;
2539  bl -= scrollOffset;
2540 
2541  QPolygon poly(4);
2542  poly[0] = tl.toPoint();
2543  poly[1] = tr.toPoint();
2544  poly[2] = br.toPoint();
2545  poly[3] = bl.toPoint();
2546  return poly;
2547 }
double d
Definition: qnumeric_p.h:62
QPointF bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:540
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPointF topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:539
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QPointF bottomLeft() const
Returns the position of the rectangle&#39;s bottom-left corner.
Definition: qrect.h:542
The QPolygon class provides a vector of points using integer precision.
Definition: qpolygon.h:60
#define Q_D(Class)
Definition: qglobal.h:2482
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
int x() const
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
QPointF topRight() const
Returns the position of the rectangle&#39;s top-right corner.
Definition: qrect.h:541
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ mapFromScene() [3/6]

QPolygon QGraphicsView::mapFromScene ( const QPolygonF polygon) const

Returns the scene coordinate polygon polygon to a viewport coordinate polygon.

See also
mapToScene()

Definition at line 2565 of file qgraphicsview.cpp.

2566 {
2567  QPolygon poly;
2568  foreach (const QPointF &point, polygon)
2569  poly << mapFromScene(point);
2570  return poly;
2571 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QPolygon class provides a vector of points using integer precision.
Definition: qpolygon.h:60
QPoint mapFromScene(const QPointF &point) const
Returns the scene coordinate point to viewport coordinates.

◆ mapFromScene() [4/6]

QPainterPath QGraphicsView::mapFromScene ( const QPainterPath path) const

Returns the scene coordinate painter path path to a viewport coordinate painter path.

See also
mapToScene()

Definition at line 2579 of file qgraphicsview.cpp.

2580 {
2581  Q_D(const QGraphicsView);
2582  QTransform matrix = d->matrix;
2583  matrix *= QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll());
2584  return matrix.map(path);
2585 }
double d
Definition: qnumeric_p.h:62
QMatrix matrix() const
Returns the current transformation matrix for the view.
#define Q_D(Class)
Definition: qglobal.h:2482
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis...
Definition: qtransform.cpp:462
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ mapFromScene() [5/6]

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

This function is provided for convenience.

It's equivalent to calling mapFromScene(QPointF(x, y)).

Definition at line 305 of file qgraphicsview.h.

306 { return mapFromScene(QPointF(ax, ay)); }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPoint mapFromScene(const QPointF &point) const
Returns the scene coordinate point to viewport coordinates.

◆ mapFromScene() [6/6]

QPolygon QGraphicsView::mapFromScene ( qreal  x,
qreal  y,
qreal  w,
qreal  h 
) const
inline

This function is provided for convenience.

It's equivalent to calling mapFromScene(QRectF(x, y, w, h)).

Definition at line 307 of file qgraphicsview.h.

308 { return mapFromScene(QRectF(ax, ay, w, h)); }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QPoint mapFromScene(const QPointF &point) const
Returns the scene coordinate point to viewport coordinates.

◆ mapToScene() [1/6]

QPointF QGraphicsView::mapToScene ( const QPoint point) const

Returns the viewport coordinate point mapped to scene coordinates.

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

See also
mapFromScene()

Definition at line 2394 of file qgraphicsview.cpp.

Referenced by contextMenuEvent(), QGraphicsItem::isUnderMouse(), items(), QGraphicsScenePrivate::leaveScene(), QGestureEvent::mapToGraphicsScene(), mapToScene(), mouseDoubleClickEvent(), QmlJSDebugger::ZoomTool::mouseMoveEvent(), mouseMoveEvent(), QmlJSDebugger::ZoomTool::mousePressEvent(), mousePressEvent(), QmlJSDebugger::ZoomTool::mouseReleaseEvent(), mouseReleaseEvent(), paintEvent(), render(), QWidgetPrivate::screenGeometry(), QmlJSDebugger::SubcomponentMaskLayerItem::setCurrentItem(), viewportEvent(), and wheelEvent().

2395 {
2396  Q_D(const QGraphicsView);
2397  QPointF p = point;
2398  p.rx() += d->horizontalScroll();
2399  p.ry() += d->verticalScroll();
2400  return d->identityMatrix ? p : d->matrix.inverted().map(p);
2401 }
double d
Definition: qnumeric_p.h:62
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_D(Class)
Definition: qglobal.h:2482
qreal & rx()
Returns a reference to the x coordinate of this point.
Definition: qpoint.h:302
qreal & ry()
Returns a reference to the y coordinate of this point.
Definition: qpoint.h:307
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ mapToScene() [2/6]

QPolygonF QGraphicsView::mapToScene ( const QRect rect) const

Returns the viewport rectangle rect mapped to a scene coordinate polygon.

See also
mapFromScene()

Definition at line 2419 of file qgraphicsview.cpp.

2420 {
2421  Q_D(const QGraphicsView);
2422  if (!rect.isValid())
2423  return QPolygonF();
2424 
2425  QPointF scrollOffset(d->horizontalScroll(), d->verticalScroll());
2426  QRect r = rect.adjusted(0, 0, 1, 1);
2427  QPointF tl = scrollOffset + r.topLeft();
2428  QPointF tr = scrollOffset + r.topRight();
2429  QPointF br = scrollOffset + r.bottomRight();
2430  QPointF bl = scrollOffset + r.bottomLeft();
2431 
2432  QPolygonF poly(4);
2433  if (!d->identityMatrix) {
2434  QTransform x = d->matrix.inverted();
2435  poly[0] = x.map(tl);
2436  poly[1] = x.map(tr);
2437  poly[2] = x.map(br);
2438  poly[3] = x.map(bl);
2439  } else {
2440  poly[0] = tl;
2441  poly[1] = tr;
2442  poly[2] = br;
2443  poly[3] = bl;
2444  }
2445  return poly;
2446 }
double d
Definition: qnumeric_p.h:62
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
#define Q_D(Class)
Definition: qglobal.h:2482
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
int x() const
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ mapToScene() [3/6]

QPolygonF QGraphicsView::mapToScene ( const QPolygon polygon) const

Returns the viewport polygon polygon mapped to a scene coordinate polygon.

See also
mapFromScene()

Definition at line 2464 of file qgraphicsview.cpp.

2465 {
2466  QPolygonF poly;
2467  foreach (const QPoint &point, polygon)
2468  poly << mapToScene(point);
2469  return poly;
2470 }
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53

◆ mapToScene() [4/6]

QPainterPath QGraphicsView::mapToScene ( const QPainterPath path) const

Returns the viewport painter path path mapped to a scene coordinate painter path.

See also
mapFromScene()

Definition at line 2478 of file qgraphicsview.cpp.

2479 {
2480  Q_D(const QGraphicsView);
2481  QTransform matrix = QTransform::fromTranslate(d->horizontalScroll(), d->verticalScroll());
2482  matrix *= d->matrix.inverted();
2483  return matrix.map(path);
2484 }
double d
Definition: qnumeric_p.h:62
QMatrix matrix() const
Returns the current transformation matrix for the view.
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis...
Definition: qtransform.cpp:462
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ mapToScene() [5/6]

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

This function is provided for convenience.

It's equivalent to calling mapToScene(QPoint(x, y)).

Definition at line 301 of file qgraphicsview.h.

302 { return mapToScene(QPoint(ax, ay)); }
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53

◆ mapToScene() [6/6]

QPolygonF QGraphicsView::mapToScene ( int  x,
int  y,
int  w,
int  h 
) const
inline

This function is provided for convenience.

It's equivalent to calling mapToScene(QRect(x, y, w, h)).

Definition at line 303 of file qgraphicsview.h.

304 { return mapToScene(QRect(ax, ay, w, h)); }
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ matrix()

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

Definition at line 1769 of file qgraphicsview.cpp.

Referenced by mapFromScene(), mapToScene(), QGraphicsViewPrivate::mapToScene(), rotate(), scale(), setTransform(), shear(), and translate().

1770 {
1771  Q_D(const QGraphicsView);
1772  return d->matrix.toAffine();
1773 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ mouseDoubleClickEvent()

void QGraphicsView::mouseDoubleClickEvent ( QMouseEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3202 of file qgraphicsview.cpp.

3203 {
3204  Q_D(QGraphicsView);
3205  if (!d->scene || !d->sceneInteractionAllowed)
3206  return;
3207 
3208  d->storeMouseEvent(event);
3209  d->mousePressViewPoint = event->pos();
3210  d->mousePressScenePoint = mapToScene(d->mousePressViewPoint);
3211  d->mousePressScreenPoint = event->globalPos();
3212  d->lastMouseMoveScenePoint = d->mousePressScenePoint;
3213  d->lastMouseMoveScreenPoint = d->mousePressScreenPoint;
3214  d->mousePressButton = event->button();
3215 
3217  mouseEvent.setWidget(viewport());
3218  mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint);
3219  mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint);
3220  mouseEvent.setScenePos(mapToScene(d->mousePressViewPoint));
3221  mouseEvent.setScreenPos(d->mousePressScreenPoint);
3222  mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint);
3223  mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint);
3224  mouseEvent.setButtons(event->buttons());
3225  mouseEvent.setButtons(event->buttons());
3226  mouseEvent.setAccepted(false);
3227  mouseEvent.setButton(event->button());
3228  mouseEvent.setModifiers(event->modifiers());
3229  if (event->spontaneous())
3231  else
3233 }
double d
Definition: qnumeric_p.h:62
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget * viewport() const
Returns the viewport widget.
bool spontaneous() const
Returns true if the event originated outside the application (a system event); otherwise returns fals...
Definition: qcoreevent.h:304
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event)
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition: qevent.h:79

◆ mouseMoveEvent()

void QGraphicsView::mouseMoveEvent ( QMouseEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3316 of file qgraphicsview.cpp.

3317 {
3318  Q_D(QGraphicsView);
3319 
3320 #ifndef QT_NO_RUBBERBAND
3321  if (d->dragMode == QGraphicsView::RubberBandDrag && d->sceneInteractionAllowed) {
3322  d->storeMouseEvent(event);
3323  if (d->rubberBanding) {
3324  // Check for enough drag distance
3325  if ((d->mousePressViewPoint - event->pos()).manhattanLength()
3327  return;
3328  }
3329 
3330  // Update old rubberband
3331  if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate && !d->rubberBandRect.isEmpty()) {
3332  if (d->viewportUpdateMode != FullViewportUpdate)
3333  viewport()->update(d->rubberBandRegion(viewport(), d->rubberBandRect));
3334  else
3335  d->updateAll();
3336  }
3337 
3338  // Stop rubber banding if the user has let go of all buttons (even
3339  // if we didn't get the release events).
3340  if (!event->buttons()) {
3341  d->rubberBanding = false;
3342  d->rubberBandRect = QRect();
3343  return;
3344  }
3345 
3346  // Update rubberband position
3347  const QPoint &mp = d->mousePressViewPoint;
3348  QPoint ep = event->pos();
3349  d->rubberBandRect = QRect(qMin(mp.x(), ep.x()), qMin(mp.y(), ep.y()),
3350  qAbs(mp.x() - ep.x()) + 1, qAbs(mp.y() - ep.y()) + 1);
3351 
3352  // Update new rubberband
3353  if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate){
3354  if (d->viewportUpdateMode != FullViewportUpdate)
3355  viewport()->update(d->rubberBandRegion(viewport(), d->rubberBandRect));
3356  else
3357  d->updateAll();
3358  }
3359  // Set the new selection area
3360  QPainterPath selectionArea;
3361  selectionArea.addPolygon(mapToScene(d->rubberBandRect));
3362  selectionArea.closeSubpath();
3363  if (d->scene)
3364  d->scene->setSelectionArea(selectionArea, d->rubberBandSelectionMode,
3365  viewportTransform());
3366  return;
3367  }
3368  } else
3369 #endif // QT_NO_RUBBERBAND
3370  if (d->dragMode == QGraphicsView::ScrollHandDrag) {
3371  if (d->handScrolling) {
3372  QScrollBar *hBar = horizontalScrollBar();
3373  QScrollBar *vBar = verticalScrollBar();
3374  QPoint delta = event->pos() - d->lastMouseEvent.pos();
3375  hBar->setValue(hBar->value() + (isRightToLeft() ? delta.x() : -delta.x()));
3376  vBar->setValue(vBar->value() - delta.y());
3377 
3378  // Detect how much we've scrolled to disambiguate scrolling from
3379  // clicking.
3380  ++d->handScrollMotions;
3381  }
3382  }
3383 
3384  d->mouseMoveEventHandler(event);
3385 }
double d
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
void closeSubpath()
Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting ...
QScrollBar * verticalScrollBar() const
Returns the vertical scroll bar.
void addPolygon(const QPolygonF &polygon)
Adds the given polygon to the path as an (unclosed) subpath.
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_D(Class)
Definition: qglobal.h:2482
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
QTransform viewportTransform() const
Returns a matrix that maps viewport coordinates to scene coordinates.
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QWidget * viewport() const
Returns the viewport widget.
The QScrollBar widget provides a vertical or horizontal scroll bar.
Definition: qscrollbar.h:59
int value() const
static int startDragDistance()
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QScrollBar * horizontalScrollBar() const
Returns the horizontal scroll bar.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
bool isRightToLeft() const
Definition: qwidget.h:428
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128

◆ mousePressEvent()

void QGraphicsView::mousePressEvent ( QMouseEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3238 of file qgraphicsview.cpp.

3239 {
3240  Q_D(QGraphicsView);
3241 
3242  // Store this event for replaying, finding deltas, and for
3243  // scroll-dragging; even in non-interactive mode, scroll hand dragging is
3244  // allowed, so we store the event at the very top of this function.
3245  d->storeMouseEvent(event);
3246  d->lastMouseEvent.setAccepted(false);
3247 
3248  if (d->sceneInteractionAllowed) {
3249  // Store some of the event's button-down data.
3250  d->mousePressViewPoint = event->pos();
3251  d->mousePressScenePoint = mapToScene(d->mousePressViewPoint);
3252  d->mousePressScreenPoint = event->globalPos();
3253  d->lastMouseMoveScenePoint = d->mousePressScenePoint;
3254  d->lastMouseMoveScreenPoint = d->mousePressScreenPoint;
3255  d->mousePressButton = event->button();
3256 
3257  if (d->scene) {
3258  // Convert and deliver the mouse event to the scene.
3260  mouseEvent.setWidget(viewport());
3261  mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint);
3262  mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint);
3263  mouseEvent.setScenePos(d->mousePressScenePoint);
3264  mouseEvent.setScreenPos(d->mousePressScreenPoint);
3265  mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint);
3266  mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint);
3267  mouseEvent.setButtons(event->buttons());
3268  mouseEvent.setButton(event->button());
3269  mouseEvent.setModifiers(event->modifiers());
3270  mouseEvent.setAccepted(false);
3271  if (event->spontaneous())
3273  else
3275 
3276  // Update the original mouse event accepted state.
3277  bool isAccepted = mouseEvent.isAccepted();
3278  event->setAccepted(isAccepted);
3279 
3280  // Update the last mouse event accepted state.
3281  d->lastMouseEvent.setAccepted(isAccepted);
3282 
3283  if (isAccepted)
3284  return;
3285  }
3286  }
3287 
3288 #ifndef QT_NO_RUBBERBAND
3289  if (d->dragMode == QGraphicsView::RubberBandDrag && !d->rubberBanding) {
3290  if (d->sceneInteractionAllowed) {
3291  // Rubberbanding is only allowed in interactive mode.
3292  event->accept();
3293  d->rubberBanding = true;
3294  d->rubberBandRect = QRect();
3295  if (d->scene) {
3296  // Initiating a rubber band always clears the selection.
3297  d->scene->clearSelection();
3298  }
3299  }
3300  } else
3301 #endif
3302  if (d->dragMode == QGraphicsView::ScrollHandDrag && event->button() == Qt::LeftButton) {
3303  // Left-button press in scroll hand mode initiates hand scrolling.
3304  event->accept();
3305  d->handScrolling = true;
3306  d->handScrollMotions = 0;
3307 #ifndef QT_NO_CURSOR
3309 #endif
3310  }
3311 }
double d
Definition: qnumeric_p.h:62
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget * viewport() const
Returns the viewport widget.
bool spontaneous() const
Returns true if the event originated outside the application (a system event); otherwise returns fals...
Definition: qcoreevent.h:304
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event)
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition: qevent.h:79

◆ mouseReleaseEvent()

void QGraphicsView::mouseReleaseEvent ( QMouseEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3390 of file qgraphicsview.cpp.

3391 {
3392  Q_D(QGraphicsView);
3393 
3394 #ifndef QT_NO_RUBBERBAND
3395  if (d->dragMode == QGraphicsView::RubberBandDrag && d->sceneInteractionAllowed && !event->buttons()) {
3396  if (d->rubberBanding) {
3397  if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate){
3398  if (d->viewportUpdateMode != FullViewportUpdate)
3399  viewport()->update(d->rubberBandRegion(viewport(), d->rubberBandRect));
3400  else
3401  d->updateAll();
3402  }
3403  d->rubberBanding = false;
3404  d->rubberBandRect = QRect();
3405  }
3406  } else
3407 #endif
3408  if (d->dragMode == QGraphicsView::ScrollHandDrag && event->button() == Qt::LeftButton) {
3409 #ifndef QT_NO_CURSOR
3410  // Restore the open hand cursor. ### There might be items
3411  // under the mouse that have a valid cursor at this time, so
3412  // we could repeat the steps from mouseMoveEvent().
3414 #endif
3415  d->handScrolling = false;
3416 
3417  if (d->scene && d->sceneInteractionAllowed && !d->lastMouseEvent.isAccepted() && d->handScrollMotions <= 6) {
3418  // If we've detected very little motion during the hand drag, and
3419  // no item accepted the last event, we'll interpret that as a
3420  // click to the scene, and reset the selection.
3421  d->scene->clearSelection();
3422  }
3423  }
3424 
3425  d->storeMouseEvent(event);
3426 
3427  if (!d->sceneInteractionAllowed)
3428  return;
3429 
3430  if (!d->scene)
3431  return;
3432 
3434  mouseEvent.setWidget(viewport());
3435  mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint);
3436  mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint);
3437  mouseEvent.setScenePos(mapToScene(event->pos()));
3438  mouseEvent.setScreenPos(event->globalPos());
3439  mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint);
3440  mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint);
3441  mouseEvent.setButtons(event->buttons());
3442  mouseEvent.setButton(event->button());
3443  mouseEvent.setModifiers(event->modifiers());
3444  mouseEvent.setAccepted(false);
3445  if (event->spontaneous())
3447  else
3449 
3450  // Update the last mouse event selected state.
3451  d->lastMouseEvent.setAccepted(mouseEvent.isAccepted());
3452 
3453 #ifndef QT_NO_CURSOR
3454  if (mouseEvent.isAccepted() && mouseEvent.buttons() == 0 && viewport()->testAttribute(Qt::WA_SetCursor)) {
3455  // The last mouse release on the viewport will trigger clearing the cursor.
3456  d->_q_unsetViewportCursor();
3457  }
3458 #endif
3459 }
double d
Definition: qnumeric_p.h:62
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
#define Q_D(Class)
Definition: qglobal.h:2482
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QWidget * viewport() const
Returns the viewport widget.
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
bool spontaneous() const
Returns true if the event originated outside the application (a system event); otherwise returns fals...
Definition: qcoreevent.h:304
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event)
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition: qevent.h:79
const QPoint & globalPos() const
Returns the global position of the mouse cursor at the time of the event.
Definition: qevent.h:96

◆ optimizationFlags()

OptimizationFlags QGraphicsView::optimizationFlags ( ) const

Referenced by setViewportUpdateMode().

◆ paintEvent()

void QGraphicsView::paintEvent ( QPaintEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3494 of file qgraphicsview.cpp.

Referenced by QDeclarativeView::paintEvent().

3495 {
3496  Q_D(QGraphicsView);
3497  if (!d->scene) {
3499  return;
3500  }
3501 
3502  // Set up painter state protection.
3503  d->scene->d_func()->painterStateProtection = !(d->optimizationFlags & DontSavePainterState);
3504 
3505  // Determine the exposed region
3506  d->exposedRegion = event->region();
3507  QRectF exposedSceneRect = mapToScene(d->exposedRegion.boundingRect()).boundingRect();
3508 
3509  // Set up the painter
3510  QPainter painter(viewport());
3511 #ifndef QT_NO_RUBBERBAND
3512  if (d->rubberBanding && !d->rubberBandRect.isEmpty())
3513  painter.save();
3514 #endif
3515  // Set up render hints
3516  painter.setRenderHints(painter.renderHints(), false);
3517  painter.setRenderHints(d->renderHints, true);
3518 
3519  // Set up viewport transform
3520  const bool viewTransformed = isTransformed();
3521  if (viewTransformed)
3522  painter.setWorldTransform(viewportTransform());
3523  const QTransform viewTransform = painter.worldTransform();
3524 
3525  // Draw background
3526  if ((d->cacheMode & CacheBackground)
3527 #ifdef Q_WS_X11
3528  && X11->use_xrender
3529 #endif
3530  ) {
3531  // Recreate the background pixmap, and flag the whole background as
3532  // exposed.
3533  if (d->mustResizeBackgroundPixmap) {
3534  d->backgroundPixmap = QPixmap(viewport()->size());
3535  QBrush bgBrush = viewport()->palette().brush(viewport()->backgroundRole());
3536  if (!bgBrush.isOpaque())
3537  d->backgroundPixmap.fill(Qt::transparent);
3538  QPainter p(&d->backgroundPixmap);
3539  p.fillRect(0, 0, d->backgroundPixmap.width(), d->backgroundPixmap.height(), bgBrush);
3540  d->backgroundPixmapExposed = QRegion(viewport()->rect());
3541  d->mustResizeBackgroundPixmap = false;
3542  }
3543 
3544  // Redraw exposed areas
3545  if (!d->backgroundPixmapExposed.isEmpty()) {
3546  QPainter backgroundPainter(&d->backgroundPixmap);
3547  backgroundPainter.setClipRegion(d->backgroundPixmapExposed, Qt::ReplaceClip);
3548  if (viewTransformed)
3549  backgroundPainter.setTransform(viewTransform);
3550  QRectF backgroundExposedSceneRect = mapToScene(d->backgroundPixmapExposed.boundingRect()).boundingRect();
3551  drawBackground(&backgroundPainter, backgroundExposedSceneRect);
3552  d->backgroundPixmapExposed = QRegion();
3553  }
3554 
3555  // Blit the background from the background pixmap
3556  if (viewTransformed) {
3557  painter.setWorldTransform(QTransform());
3558  painter.drawPixmap(QPoint(), d->backgroundPixmap);
3559  painter.setWorldTransform(viewTransform);
3560  } else {
3561  painter.drawPixmap(QPoint(), d->backgroundPixmap);
3562  }
3563  } else {
3564  if (!(d->optimizationFlags & DontSavePainterState))
3565  painter.save();
3566  drawBackground(&painter, exposedSceneRect);
3567  if (!(d->optimizationFlags & DontSavePainterState))
3568  painter.restore();
3569  }
3570 
3571  // Items
3572  if (!(d->optimizationFlags & IndirectPainting)) {
3573  const quint32 oldRectAdjust = d->scene->d_func()->rectAdjust;
3574  if (d->optimizationFlags & QGraphicsView::DontAdjustForAntialiasing)
3575  d->scene->d_func()->rectAdjust = 1;
3576  else
3577  d->scene->d_func()->rectAdjust = 2;
3578  d->scene->d_func()->drawItems(&painter, viewTransformed ? &viewTransform : 0,
3579  &d->exposedRegion, viewport());
3580  d->scene->d_func()->rectAdjust = oldRectAdjust;
3581  // Make sure the painter's world transform is restored correctly when
3582  // drawing without painter state protection (DontSavePainterState).
3583  // We only change the worldTransform() so there's no need to do a full-blown
3584  // save() and restore(). Also note that we don't have to do this in case of
3585  // IndirectPainting (the else branch), because in that case we always save()
3586  // and restore() in QGraphicsScene::drawItems().
3587  if (!d->scene->d_func()->painterStateProtection)
3588  painter.setOpacity(1.0);
3589  painter.setWorldTransform(viewTransform);
3590  } else {
3591  // Make sure we don't have unpolished items before we draw
3592  if (!d->scene->d_func()->unpolishedItems.isEmpty())
3593  d->scene->d_func()->_q_polishItems();
3594  // We reset updateAll here (after we've issued polish events)
3595  // so that we can discard update requests coming from polishEvent().
3596  d->scene->d_func()->updateAll = false;
3597 
3598  // Find all exposed items
3599  bool allItems = false;
3600  QList<QGraphicsItem *> itemList = d->findItems(d->exposedRegion, &allItems, viewTransform);
3601  if (!itemList.isEmpty()) {
3602  // Generate the style options.
3603  const int numItems = itemList.size();
3604  QGraphicsItem **itemArray = &itemList[0]; // Relies on QList internals, but is perfectly valid.
3605  QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems);
3607  for (int i = 0; i < numItems; ++i) {
3608  QGraphicsItem *item = itemArray[i];
3609  QGraphicsItemPrivate *itemd = item->d_ptr.data();
3610  itemd->initStyleOption(&styleOptionArray[i], viewTransform, d->exposedRegion, allItems);
3611  // Cache the item's area in view coordinates.
3612  // Note that we have to do this here in case the base class implementation
3613  // (QGraphicsScene::drawItems) is not called. If it is, we'll do this
3614  // operation twice, but that's the price one has to pay for using indirect
3615  // painting :-/.
3616  const QRectF brect = adjustedItemEffectiveBoundingRect(item);
3617  if (!itemd->itemIsUntransformable()) {
3618  transform = item->sceneTransform();
3619  if (viewTransformed)
3620  transform *= viewTransform;
3621  } else {
3622  transform = item->deviceTransform(viewTransform);
3623  }
3624  itemd->paintedViewBoundingRects.insert(d->viewport, transform.mapRect(brect).toRect());
3625  }
3626  // Draw the items.
3627  drawItems(&painter, numItems, itemArray, styleOptionArray);
3628  d->freeStyleOptionsArray(styleOptionArray);
3629  }
3630  }
3631 
3632  // Foreground
3633  drawForeground(&painter, exposedSceneRect);
3634 
3635 #ifndef QT_NO_RUBBERBAND
3636  // Rubberband
3637  if (d->rubberBanding && !d->rubberBandRect.isEmpty()) {
3638  painter.restore();
3639  QStyleOptionRubberBand option;
3640  option.initFrom(viewport());
3641  option.rect = d->rubberBandRect;
3642  option.shape = QRubberBand::Rectangle;
3643 
3645  if (viewport()->style()->styleHint(QStyle::SH_RubberBand_Mask, &option, viewport(), &mask)) {
3646  // painter clipping for masked rubberbands
3647  painter.setClipRegion(mask.region, Qt::IntersectClip);
3648  }
3649 
3650  viewport()->style()->drawControl(QStyle::CE_RubberBand, &option, &painter, viewport());
3651  }
3652 #endif
3653 
3654  painter.end();
3655 
3656  // Restore painter state protection.
3657  d->scene->d_func()->painterStateProtection = true;
3658 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
QPalette palette
the widget&#39;s palette
Definition: qwidget.h:180
static QRectF adjustedItemEffectiveBoundingRect(const QGraphicsItem *item)
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
bool isTransformed() const
Returns true if the view is transformed (i.
QSize size() const
QScopedPointer< QGraphicsItemPrivate > d_ptr
T * data() const
Returns the value of the pointer referenced by this object.
QTransform sceneTransform() const
Returns this item&#39;s scene transformation matrix.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QPalette::ColorRole backgroundRole() const
Returns the background role of the widget.
Definition: qwidget.cpp:4677
#define X11
Definition: qt_x11_p.h:724
#define Q_D(Class)
Definition: qglobal.h:2482
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QStyle * style() const
Definition: qwidget.cpp:2742
QTransform viewportTransform() const
Returns a matrix that maps viewport coordinates to scene coordinates.
static const QRectF boundingRect(const QPointF *points, int pointCount)
QWidget * viewport() const
Returns the viewport widget.
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
friend class QPixmap
Definition: qwidget.h:748
void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events (passed in event)...
bool itemIsUntransformable() const
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
void initStyleOption(QStyleOptionGraphicsItem *option, const QTransform &worldTransform, const QRegion &exposedRegion, bool allItems=false) const
const char * styleHint(const QFontDef &request)
QTransform transform() const
Returns the current transformation matrix for the view.
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
virtual void drawForeground(QPainter *painter, const QRectF &rect)
Draws the foreground of the scene using painter, after the background and all items are drawn...
bool isOpaque() const
Returns true if the brush is fully opaque otherwise false.
Definition: qbrush.cpp:910
The QStyleOptionRubberBand class is used to describe the parameters needed for drawing a rubber band...
Definition: qstyleoption.h:669
QRect rect() const
QRegion mask() const
Returns the mask currently set on a widget.
Definition: qwidget.cpp:10058
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874
QTransform deviceTransform(const QTransform &viewportTransform) const
Returns this item&#39;s device transformation matrix, using viewportTransform to map from scene to device...
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QStyleHintReturnMask class provides style hints that return a QRegion.
Definition: qstyleoption.h:923
virtual void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem options[])
Draws the items items in the scene using painter, after the background and before the foreground are ...
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given element with the provided painter with the style options specified by option...
unsigned int quint32
Definition: qglobal.h:938
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
virtual void drawBackground(QPainter *painter, const QRectF &rect)
Draws the background of the scene using painter, before any items and the foreground are drawn...
QRubberBand::Shape shape
the shape of the rubber band
Definition: qstyleoption.h:675
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
QMap< QWidget *, QRect > paintedViewBoundingRects
QRegion region
the region for style hints that return a QRegion
Definition: qstyleoption.h:930
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem...
Definition: qstyleoption.h:867
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ render()

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

Renders the source rect, which is in view coordinates, from the scene into target, which is in paint device coordinates, using painter.

This function is useful for capturing the contents of the view onto a paint device, such as a QImage (e.g., to take a screenshot), or for printing to QPrinter. For example:

scene.addItem(...
...
QGraphicsView view(&scene);
view.show();
...
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));

If source is a null rect, this function will use viewport()->rect() to determine what to draw. If target is a null rect, the full dimensions of painter's paint device (e.g., for a QPrinter, the page size) will be used.

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

See also
QGraphicsScene::render()

Definition at line 2125 of file qgraphicsview.cpp.

Referenced by QmlJSDebugger::ColorPickerTool::pickColor().

2127 {
2128  // ### Switch to using the recursive rendering algorithm instead.
2129 
2130  Q_D(QGraphicsView);
2131  if (!d->scene || !(painter && painter->isActive()))
2132  return;
2133 
2134  // Default source rect = viewport rect
2135  QRect sourceRect = source;
2136  if (source.isNull())
2137  sourceRect = viewport()->rect();
2138 
2139  // Default target rect = device rect
2140  QRectF targetRect = target;
2141  if (target.isNull()) {
2142  if (painter->device()->devType() == QInternal::Picture)
2143  targetRect = sourceRect;
2144  else
2145  targetRect.setRect(0, 0, painter->device()->width(), painter->device()->height());
2146  }
2147 
2148  // Find the ideal x / y scaling ratio to fit \a source into \a target.
2149  qreal xratio = targetRect.width() / sourceRect.width();
2150  qreal yratio = targetRect.height() / sourceRect.height();
2151 
2152  // Scale according to the aspect ratio mode.
2153  switch (aspectRatioMode) {
2154  case Qt::KeepAspectRatio:
2155  xratio = yratio = qMin(xratio, yratio);
2156  break;
2158  xratio = yratio = qMax(xratio, yratio);
2159  break;
2160  case Qt::IgnoreAspectRatio:
2161  break;
2162  }
2163 
2164  // Find all items to draw, and reverse the list (we want to draw
2165  // in reverse order).
2166  QPolygonF sourceScenePoly = mapToScene(sourceRect.adjusted(-1, -1, 1, 1));
2167  QList<QGraphicsItem *> itemList = d->scene->items(sourceScenePoly,
2169  QGraphicsItem **itemArray = new QGraphicsItem *[itemList.size()];
2170  int numItems = itemList.size();
2171  for (int i = 0; i < numItems; ++i)
2172  itemArray[numItems - i - 1] = itemList.at(i);
2173  itemList.clear();
2174 
2175  // Setup painter matrix.
2176  QTransform moveMatrix = QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll());
2177  QTransform painterMatrix = d->matrix * moveMatrix;
2178  painterMatrix *= QTransform()
2179  .translate(targetRect.left(), targetRect.top())
2180  .scale(xratio, yratio)
2181  .translate(-sourceRect.left(), -sourceRect.top());
2182 
2183  // Generate the style options
2184  QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems);
2185  for (int i = 0; i < numItems; ++i)
2186  itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], painterMatrix, targetRect.toRect());
2187 
2188  painter->save();
2189 
2190  // Clip in device coordinates to avoid QRegion transformations.
2191  painter->setClipRect(targetRect);
2192  QPainterPath path;
2193  path.addPolygon(sourceScenePoly);
2194  path.closeSubpath();
2195  painter->setClipPath(painterMatrix.map(path), Qt::IntersectClip);
2196 
2197  // Transform the painter.
2198  painter->setTransform(painterMatrix, true);
2199 
2200  // Render the scene.
2201  QRectF sourceSceneRect = sourceScenePoly.boundingRect();
2202  drawBackground(painter, sourceSceneRect);
2203  drawItems(painter, numItems, itemArray, styleOptionArray);
2204  drawForeground(painter, sourceSceneRect);
2205 
2206  delete [] itemArray;
2207  d->freeStyleOptionsArray(styleOptionArray);
2208 
2209  painter->restore();
2210 }
void setTransform(const QTransform &transform, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9547
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or 0 if the painter is not acti...
Definition: qpainter.cpp:1530
double d
Definition: qnumeric_p.h:62
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:231
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
int height() const
Definition: qpaintdevice.h:92
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
Definition: qpainter.cpp:2801
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
void closeSubpath()
Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting ...
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
void addPolygon(const QPolygonF &polygon)
Adds the given polygon to the path as an (unclosed) subpath.
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
Definition: qtransform.cpp:417
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QRectF boundingRect() const
Returns the bounding rectangle of the polygon, or QRectF(0,0,0,0) if the polygon is empty...
Definition: qpolygon.cpp:742
#define Q_D(Class)
Definition: qglobal.h:2482
virtual int devType() const
Definition: qpaintdevice.h:167
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QWidget * viewport() const
Returns the viewport widget.
int width() const
Definition: qpaintdevice.h:91
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
bool isActive() const
Returns true if begin() has been called and end() has not yet been called; otherwise returns false...
Definition: qpainter.cpp:1545
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
void setRect(qreal x, qreal y, qreal w, qreal h)
Sets the coordinates of the rectangle&#39;s top-left corner to (x, y), and its size to the given width an...
Definition: qrect.h:754
virtual void drawForeground(QPainter *painter, const QRectF &rect)
Draws the foreground of the scene using painter, after the background and all items are drawn...
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
void scale(qreal sx, qreal sy)
Scales the current view transformation by (sx, sy).
virtual void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem options[])
Draws the items items in the scene using painter, after the background and before the foreground are ...
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
virtual void drawBackground(QPainter *painter, const QRectF &rect)
Draws the background of the scene using painter, before any items and the foreground are drawn...
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QScopedPointer< QObjectData > d_ptr
Definition: qobject.h:320
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis...
Definition: qtransform.cpp:462
void setClipPath(const QPainterPath &path, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip path for the painter to the given path, with the clip operation...
Definition: qpainter.cpp:3365
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem...
Definition: qstyleoption.h:867
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ renderHints()

QPainter::RenderHints QGraphicsView::renderHints ( ) const

Referenced by sizeHint().

◆ resetCachedContent()

void QGraphicsView::resetCachedContent ( )

Resets any cached content.

Calling this function will clear QGraphicsView's cache. If the current cache mode is CacheNone , this function does nothing.

This function is called automatically for you when the backgroundBrush or QGraphicsScene::backgroundBrush properties change; you only need to call this function if you have reimplemented QGraphicsScene::drawBackground() or QGraphicsView::drawBackground() to draw a custom background, and need to trigger a full redraw.

See also
cacheMode()

Definition at line 1566 of file qgraphicsview.cpp.

Referenced by QGraphicsScene::setBackgroundBrush(), and setCacheMode().

1567 {
1568  Q_D(QGraphicsView);
1569  if (d->cacheMode == CacheNone)
1570  return;
1571 
1572  if (d->cacheMode & CacheBackground) {
1573  // Background caching is enabled.
1574  d->mustResizeBackgroundPixmap = true;
1575  d->updateAll();
1576  } else if (d->mustResizeBackgroundPixmap) {
1577  // Background caching is disabled.
1578  // Cleanup, free some resources.
1579  d->mustResizeBackgroundPixmap = false;
1580  d->backgroundPixmap = QPixmap();
1581  d->backgroundPixmapExposed = QRegion();
1582  }
1583 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
friend class QPixmap
Definition: qwidget.h:748
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ resetMatrix()

void QGraphicsView::resetMatrix ( )

Resets the view transformation matrix to the identity matrix.

See also
resetTransform()

Definition at line 1811 of file qgraphicsview.cpp.

1812 {
1813  resetTransform();
1814 }
void resetTransform()
Resets the view transformation to the identity matrix.

◆ resetTransform()

void QGraphicsView::resetTransform ( )

Resets the view transformation to the identity matrix.

See also
transform(), setTransform()

Definition at line 3953 of file qgraphicsview.cpp.

Referenced by resetMatrix().

3954 {
3956 }
void setTransform(const QTransform &matrix, bool combine=false)
Sets the view&#39;s current transformation matrix to matrix.
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ resizeAnchor()

ViewportAnchor QGraphicsView::resizeAnchor ( ) const

Referenced by setTransformationAnchor().

◆ resizeEvent()

void QGraphicsView::resizeEvent ( QResizeEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3663 of file qgraphicsview.cpp.

Referenced by QDeclarativeView::resizeEvent().

3664 {
3665  Q_D(QGraphicsView);
3666  // Save the last center point - the resize may scroll the view, which
3667  // changes the center point.
3668  QPointF oldLastCenterPoint = d->lastCenterPoint;
3669 
3671  d->recalculateContentSize();
3672 
3673  // Restore the center point again.
3674  if (d->resizeAnchor == NoAnchor && !d->keepLastCenterPoint) {
3675  d->updateLastCenterPoint();
3676  } else {
3677  d->lastCenterPoint = oldLastCenterPoint;
3678  }
3679  d->centerView(d->resizeAnchor);
3680  d->keepLastCenterPoint = false;
3681 
3682  if (d->cacheMode & CacheBackground) {
3683  // Invalidate the background pixmap
3684  d->mustResizeBackgroundPixmap = true;
3685  }
3686 }
double d
Definition: qnumeric_p.h:62
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_D(Class)
Definition: qglobal.h:2482
void resizeEvent(QResizeEvent *)
This event handler can be reimplemented in a subclass to receive resize events (passed in event)...
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ rotate()

void QGraphicsView::rotate ( qreal  angle)

Rotates the current view transformation angle degrees clockwise.

See also
setTransform(), transform(), scale(), shear(), translate()

Definition at line 1821 of file qgraphicsview.cpp.

1822 {
1823  Q_D(QGraphicsView);
1824  QTransform matrix = d->matrix;
1825  matrix.rotate(angle);
1826  setTransform(matrix);
1827 }
double d
Definition: qnumeric_p.h:62
QMatrix matrix() const
Returns the current transformation matrix for the view.
#define Q_D(Class)
Definition: qglobal.h:2482
void setTransform(const QTransform &matrix, bool combine=false)
Sets the view&#39;s current transformation matrix to matrix.
QTransform & rotate(qreal a, Qt::Axis axis=Qt::ZAxis)
Rotates the coordinate system counterclockwise by the given angle about the specified axis and return...
Definition: qtransform.cpp:615
qreal angle(const QPointF &p1, const QPointF &p2)
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ rubberBandSelectionMode()

Qt::ItemSelectionMode QGraphicsView::rubberBandSelectionMode ( ) const

Referenced by setDragMode().

◆ scale()

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

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

See also
setTransform(), transform(), rotate(), shear(), translate()

Definition at line 1834 of file qgraphicsview.cpp.

Referenced by fitInView(), and render().

1835 {
1836  Q_D(QGraphicsView);
1837  QTransform matrix = d->matrix;
1838  matrix.scale(sx, sy);
1839  setTransform(matrix);
1840 }
double d
Definition: qnumeric_p.h:62
QMatrix matrix() const
Returns the current transformation matrix for the view.
#define Q_D(Class)
Definition: qglobal.h:2482
void setTransform(const QTransform &matrix, bool combine=false)
Sets the view&#39;s current transformation matrix to matrix.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
QTransform & scale(qreal sx, qreal sy)
Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the mat...
Definition: qtransform.cpp:485
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ scene()

QGraphicsScene * QGraphicsView::scene ( ) const

Returns a pointer to the scene that is currently visualized in the view.

If no scene is currently visualized, 0 is returned.

See also
setScene()

Definition at line 1646 of file qgraphicsview.cpp.

Referenced by QDeclarativeView::paintEvent(), QmlJSDebugger::QDeclarativeViewInspector::QDeclarativeViewInspector(), QmlJSDebugger::AbstractLiveEditTool::scene(), QDeclarativeTextInputPrivate::sendMouseEventToInputContext(), and QDeclarativeView::setRootObject().

1647 {
1648  Q_D(const QGraphicsView);
1649  return d->scene;
1650 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ sceneRect()

QRectF QGraphicsView::sceneRect ( ) const

Referenced by fitInView(), setScene(), and sizeHint().

◆ scrollContentsBy()

void QGraphicsView::scrollContentsBy ( int  dx,
int  dy 
)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractScrollArea.

Definition at line 3691 of file qgraphicsview.cpp.

3692 {
3693  Q_D(QGraphicsView);
3694  d->dirtyScroll = true;
3695  if (d->transforming)
3696  return;
3697  if (isRightToLeft())
3698  dx = -dx;
3699 
3700  if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate) {
3701  if (d->viewportUpdateMode != QGraphicsView::FullViewportUpdate) {
3702  if (d->accelerateScrolling) {
3703 #ifndef QT_NO_RUBBERBAND
3704  // Update new and old rubberband regions
3705  if (!d->rubberBandRect.isEmpty()) {
3706  QRegion rubberBandRegion(d->rubberBandRegion(viewport(), d->rubberBandRect));
3707  rubberBandRegion += rubberBandRegion.translated(-dx, -dy);
3708  viewport()->update(rubberBandRegion);
3709  }
3710 #endif
3711  d->dirtyScrollOffset.rx() += dx;
3712  d->dirtyScrollOffset.ry() += dy;
3713  d->dirtyRegion.translate(dx, dy);
3714  viewport()->scroll(dx, dy);
3715  } else {
3716  d->updateAll();
3717  }
3718  } else {
3719  d->updateAll();
3720  }
3721  }
3722 
3723  d->updateLastCenterPoint();
3724 
3725  if ((d->cacheMode & CacheBackground)
3726 #ifdef Q_WS_X11
3727  && X11->use_xrender
3728 #endif
3729  ) {
3730  // Scroll the background pixmap
3731  QRegion exposed;
3732  if (!d->backgroundPixmap.isNull())
3733  d->backgroundPixmap.scroll(dx, dy, d->backgroundPixmap.rect(), &exposed);
3734 
3735  // Invalidate the background pixmap
3736  d->backgroundPixmapExposed.translate(dx, dy);
3737  d->backgroundPixmapExposed += exposed;
3738  }
3739 
3740  // Always replay on scroll.
3741  if (d->sceneInteractionAllowed)
3742  d->replayLastMouseEvent();
3743 }
void scroll(int dx, int dy)
Scrolls the widget including its children dx pixels to the right and dy downward. ...
Definition: qwidget.cpp:10684
double d
Definition: qnumeric_p.h:62
#define X11
Definition: qt_x11_p.h:724
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QWidget * viewport() const
Returns the viewport widget.
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
QRegion translated(int dx, int dy) const
Returns a copy of the region that is translated dx along the x axis and dy along the y axis...
Definition: qregion.cpp:743
bool isRightToLeft() const
Definition: qwidget.h:428

◆ setAlignment()

void QGraphicsView::setAlignment ( Qt::Alignment  alignment)

Definition at line 1277 of file qgraphicsview.cpp.

1278 {
1279  Q_D(QGraphicsView);
1280  if (d->alignment != alignment) {
1281  d->alignment = alignment;
1282  d->recalculateContentSize();
1283  }
1284 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Qt::Alignment alignment() const
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ setBackgroundBrush()

void QGraphicsView::setBackgroundBrush ( const QBrush brush)

Definition at line 2629 of file qgraphicsview.cpp.

2630 {
2631  Q_D(QGraphicsView);
2632  d->backgroundBrush = brush;
2633  d->updateAll();
2634 
2635  if (d->cacheMode & CacheBackground) {
2636  // Invalidate the background pixmap
2637  d->mustResizeBackgroundPixmap = true;
2638  }
2639 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ setCacheMode()

void QGraphicsView::setCacheMode ( CacheMode  mode)

Definition at line 1544 of file qgraphicsview.cpp.

1545 {
1546  Q_D(QGraphicsView);
1547  if (mode == d->cacheMode)
1548  return;
1549  d->cacheMode = mode;
1551 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void resetCachedContent()
Resets any cached content.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ setDragMode()

void QGraphicsView::setDragMode ( DragMode  mode)

Definition at line 1458 of file qgraphicsview.cpp.

1459 {
1460  Q_D(QGraphicsView);
1461  if (d->dragMode == mode)
1462  return;
1463 
1464 #ifndef QT_NO_CURSOR
1465  if (d->dragMode == ScrollHandDrag)
1466  viewport()->unsetCursor();
1467 #endif
1468 
1469  // If dragMode is unset while dragging, e.g. via a keyEvent, we
1470  // don't unset the handScrolling state. When enabling scrolling
1471  // again the mouseMoveEvent will automatically start scrolling,
1472  // without a mousePress
1473  if (d->dragMode == ScrollHandDrag && mode == NoDrag && d->handScrolling)
1474  d->handScrolling = false;
1475 
1476  d->dragMode = mode;
1477 
1478 #ifndef QT_NO_CURSOR
1479  if (d->dragMode == ScrollHandDrag) {
1480  // Forget the stored viewport cursor when we enter scroll hand drag mode.
1481  d->hasStoredOriginalCursor = false;
1483  }
1484 #endif
1485 }
double d
Definition: qnumeric_p.h:62
void unsetCursor()
Definition: qwidget.cpp:5311
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget * viewport() const
Returns the viewport widget.
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ setForegroundBrush()

void QGraphicsView::setForegroundBrush ( const QBrush brush)

Definition at line 2662 of file qgraphicsview.cpp.

2663 {
2664  Q_D(QGraphicsView);
2665  d->foregroundBrush = brush;
2666  d->updateAll();
2667 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ setInteractive()

void QGraphicsView::setInteractive ( bool  allowed)

Definition at line 1634 of file qgraphicsview.cpp.

1635 {
1636  Q_D(QGraphicsView);
1637  d->sceneInteractionAllowed = allowed;
1638 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ setMatrix()

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

Sets the view's current transformation matrix to matrix.

If combine is true, then matrix is combined with the current matrix; otherwise, matrix replaces the current matrix. combine is false by default.

The transformation matrix tranforms the scene into view coordinates. Using the default transformation, provided by the identity matrix, one pixel in the view represents one unit in the scene (e.g., a 10x10 rectangular item is drawn using 10x10 pixels in the view). If a 2x2 scaling matrix is applied, the scene will be drawn in 1:2 (e.g., a 10x10 rectangular item is then drawn using 20x20 pixels in the view).

Example:

scene.addText("GraphicsView rotated clockwise");
QGraphicsView view(&scene);
view.rotate(90); // the text is rendered with a 90 degree clockwise rotation
view.show();

To simplify interation with items using a transformed view, QGraphicsView provides mapTo... and mapFrom... functions that can translate between scene and view coordinates. For example, you can call mapToScene() to map a view coordinate to a floating point scene coordinate, or mapFromScene() to map from floating point scene coordinates to view coordinates.

See also
matrix(), setTransform(), rotate(), scale(), shear(), translate()

Definition at line 1801 of file qgraphicsview.cpp.

1802 {
1803  setTransform(QTransform(matrix), combine);
1804 }
void setTransform(const QTransform &matrix, bool combine=false)
Sets the view&#39;s current transformation matrix to matrix.
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ setOptimizationFlag()

void QGraphicsView::setOptimizationFlag ( OptimizationFlag  flag,
bool  enabled = true 
)

Enables flag if enabled is true; otherwise disables flag.

See also
optimizationFlags

Definition at line 1427 of file qgraphicsview.cpp.

1428 {
1429  Q_D(QGraphicsView);
1430  if (enabled)
1431  d->optimizationFlags |= flag;
1432  else
1433  d->optimizationFlags &= ~flag;
1434 }
double d
Definition: qnumeric_p.h:62
bool enabled
whether the widget is enabled
Definition: qwidget.h:157
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ setOptimizationFlags()

void QGraphicsView::setOptimizationFlags ( OptimizationFlags  flags)

Definition at line 1416 of file qgraphicsview.cpp.

1417 {
1418  Q_D(QGraphicsView);
1419  d->optimizationFlags = flags;
1420 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ setRenderHint()

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

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

See also
renderHints

Definition at line 1245 of file qgraphicsview.cpp.

1246 {
1247  Q_D(QGraphicsView);
1248  QPainter::RenderHints oldHints = d->renderHints;
1249  if (enabled)
1250  d->renderHints |= hint;
1251  else
1252  d->renderHints &= ~hint;
1253  if (oldHints != d->renderHints)
1254  d->updateAll();
1255 }
double d
Definition: qnumeric_p.h:62
bool enabled
whether the widget is enabled
Definition: qwidget.h:157
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ setRenderHints()

void QGraphicsView::setRenderHints ( QPainter::RenderHints  hints)

Definition at line 1230 of file qgraphicsview.cpp.

1231 {
1232  Q_D(QGraphicsView);
1233  if (hints == d->renderHints)
1234  return;
1235  d->renderHints = hints;
1236  d->updateAll();
1237 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ setResizeAnchor()

void QGraphicsView::setResizeAnchor ( ViewportAnchor  anchor)

Definition at line 1347 of file qgraphicsview.cpp.

1348 {
1349  Q_D(QGraphicsView);
1350  d->resizeAnchor = anchor;
1351 
1352  // Ensure mouse tracking is enabled in the case we are using AnchorUnderMouse
1353  // in order to have up-to-date information for centering the view.
1354  if (d->resizeAnchor == AnchorUnderMouse)
1355  d->viewport->setMouseTracking(true);
1356 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ setRubberBandSelectionMode()

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

Definition at line 1509 of file qgraphicsview.cpp.

1510 {
1511  Q_D(QGraphicsView);
1512  d->rubberBandSelectionMode = mode;
1513 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ setScene()

void QGraphicsView::setScene ( QGraphicsScene scene)

Sets the current scene to scene.

If scene is already being viewed, this function 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.

Definition at line 1660 of file qgraphicsview.cpp.

Referenced by QGraphicsView().

1661 {
1662  Q_D(QGraphicsView);
1663  if (d->scene == scene)
1664  return;
1665 
1666  // Always update the viewport when the scene changes.
1667  d->updateAll();
1668 
1669  // Remove the previously assigned scene.
1670  if (d->scene) {
1671  disconnect(d->scene, SIGNAL(changed(QList<QRectF>)),
1672  this, SLOT(updateScene(QList<QRectF>)));
1673  disconnect(d->scene, SIGNAL(sceneRectChanged(QRectF)),
1674  this, SLOT(updateSceneRect(QRectF)));
1675  d->scene->d_func()->removeView(this);
1676  d->connectedToScene = false;
1677 
1678  if (isActiveWindow() && isVisible()) {
1679  QEvent windowDeactivate(QEvent::WindowDeactivate);
1680  QApplication::sendEvent(d->scene, &windowDeactivate);
1681  }
1682  if(hasFocus())
1683  d->scene->clearFocus();
1684  }
1685 
1686  // Assign the new scene and update the contents (scrollbars, etc.)).
1687  if ((d->scene = scene)) {
1688  connect(d->scene, SIGNAL(sceneRectChanged(QRectF)),
1689  this, SLOT(updateSceneRect(QRectF)));
1690  d->updateSceneSlotReimplementedChecked = false;
1691  d->scene->d_func()->addView(this);
1692  d->recalculateContentSize();
1693  d->lastCenterPoint = sceneRect().center();
1694  d->keepLastCenterPoint = true;
1695  // We are only interested in mouse tracking if items accept
1696  // hover events or use non-default cursors.
1697  if (!d->scene->d_func()->allItemsIgnoreHoverEvents
1698  || !d->scene->d_func()->allItemsUseDefaultCursor) {
1699  d->viewport->setMouseTracking(true);
1700  }
1701 
1702  // enable touch events if any items is interested in them
1703  if (!d->scene->d_func()->allItemsIgnoreTouchEvents)
1704  d->viewport->setAttribute(Qt::WA_AcceptTouchEvents);
1705 
1706  if (isActiveWindow() && isVisible()) {
1707  QEvent windowActivate(QEvent::WindowActivate);
1708  QApplication::sendEvent(d->scene, &windowActivate);
1709  }
1710  } else {
1711  d->recalculateContentSize();
1712  }
1713 
1714  d->updateInputMethodSensitivity();
1715 
1716  if (d->scene && hasFocus())
1717  d->scene->setFocus();
1718 }
void updateScene(const QList< QRectF > &rects)
Schedules an update of the scene rectangles rects.
double d
Definition: qnumeric_p.h:62
bool isVisible() const
Definition: qwidget.h:1005
#define SLOT(a)
Definition: qobjectdefs.h:226
bool isActiveWindow() const
bool hasFocus() const
Definition: qwidget.cpp:6583
#define Q_D(Class)
Definition: qglobal.h:2482
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
QRectF sceneRect() const
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
void updateSceneRect(const QRectF &rect)
Notifies QGraphicsView that the scene&#39;s scene rect has changed.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
QPointF center() const
Returns the center point of the rectangle.
Definition: qrect.h:686

◆ setSceneRect() [1/2]

void QGraphicsView::setSceneRect ( const QRectF rect)

Definition at line 1755 of file qgraphicsview.cpp.

Referenced by QmlJSDebugger::ZoomTool::mouseReleaseEvent(), QDeclarativeView::resizeEvent(), and QmlJSDebugger::ZoomTool::scaleView().

1756 {
1757  Q_D(QGraphicsView);
1758  d->hasSceneRect = !rect.isNull();
1759  d->sceneRect = rect;
1760  d->recalculateContentSize();
1761 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QRect rect() const
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655

◆ setSceneRect() [2/2]

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

Definition at line 287 of file qgraphicsview.h.

288 { setSceneRect(QRectF(ax, ay, aw, ah)); }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void setSceneRect(const QRectF &rect)

◆ setTransform()

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

Sets the view's current transformation matrix to matrix.

If combine is true, then matrix is combined with the current matrix; otherwise, matrix replaces the current matrix. combine is false by default.

The transformation matrix tranforms the scene into view coordinates. Using the default transformation, provided by the identity matrix, one pixel in the view represents one unit in the scene (e.g., a 10x10 rectangular item is drawn using 10x10 pixels in the view). If a 2x2 scaling matrix is applied, the scene will be drawn in 1:2 (e.g., a 10x10 rectangular item is then drawn using 20x20 pixels in the view).

Example:

scene.addText("GraphicsView rotated clockwise");
QGraphicsView view(&scene);
view.rotate(90); // the text is rendered with a 90 degree clockwise rotation
view.show();

To simplify interation with items using a transformed view, QGraphicsView provides mapTo... and mapFrom... functions that can translate between scene and view coordinates. For example, you can call mapToScene() to map a view coordiate to a floating point scene coordinate, or mapFromScene() to map from floating point scene coordinates to view coordinates.

See also
transform(), rotate(), scale(), shear(), translate()

Definition at line 3920 of file qgraphicsview.cpp.

Referenced by QmlJSDebugger::ZoomTool::mouseReleaseEvent(), resetTransform(), rotate(), scale(), QmlJSDebugger::ZoomTool::scaleView(), setMatrix(), shear(), and translate().

3921 {
3922  Q_D(QGraphicsView);
3923  QTransform oldMatrix = d->matrix;
3924  if (!combine)
3925  d->matrix = matrix;
3926  else
3927  d->matrix = matrix * d->matrix;
3928  if (oldMatrix == d->matrix)
3929  return;
3930 
3931  d->identityMatrix = d->matrix.isIdentity();
3932  d->transforming = true;
3933  if (d->scene) {
3934  d->recalculateContentSize();
3935  d->centerView(d->transformationAnchor);
3936  } else {
3937  d->updateLastCenterPoint();
3938  }
3939 
3940  if (d->sceneInteractionAllowed)
3941  d->replayLastMouseEvent();
3942  d->transforming = false;
3943 
3944  // Any matrix operation requires a full update.
3945  d->updateAll();
3946 }
double d
Definition: qnumeric_p.h:62
QMatrix matrix() const
Returns the current transformation matrix for the view.
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ setTransformationAnchor()

void QGraphicsView::setTransformationAnchor ( ViewportAnchor  anchor)

Definition at line 1312 of file qgraphicsview.cpp.

1313 {
1314  Q_D(QGraphicsView);
1315  d->transformationAnchor = anchor;
1316 
1317  // Ensure mouse tracking is enabled in the case we are using AnchorUnderMouse
1318  // in order to have up-to-date information for centering the view.
1319  if (d->transformationAnchor == AnchorUnderMouse)
1320  d->viewport->setMouseTracking(true);
1321 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ setupViewport

void QGraphicsView::setupViewport ( QWidget widget)
protectedslot

This slot is called by QAbstractScrollArea after setViewport() has been called.

Reimplement this function in a subclass of QGraphicsView to initialize the new viewport widget before it is used.

See also
setViewport()

Definition at line 2766 of file qgraphicsview.cpp.

2767 {
2768  Q_D(QGraphicsView);
2769 
2770  if (!widget) {
2771  qWarning("QGraphicsView::setupViewport: cannot initialize null widget");
2772  return;
2773  }
2774 
2775  const bool isGLWidget = widget->inherits("QGLWidget");
2776 
2777  d->accelerateScrolling = !(isGLWidget);
2778 
2780 
2781  if (!isGLWidget) {
2782  // autoFillBackground enables scroll acceleration.
2783  widget->setAutoFillBackground(true);
2784  }
2785 
2786  // We are only interested in mouse tracking if items
2787  // accept hover events or use non-default cursors or if
2788  // AnchorUnderMouse is used as transformation or resize anchor.
2789  if ((d->scene && (!d->scene->d_func()->allItemsIgnoreHoverEvents
2790  || !d->scene->d_func()->allItemsUseDefaultCursor))
2791  || d->transformationAnchor == AnchorUnderMouse
2792  || d->resizeAnchor == AnchorUnderMouse) {
2793  widget->setMouseTracking(true);
2794  }
2795 
2796  // enable touch events if any items is interested in them
2797  if (d->scene && !d->scene->d_func()->allItemsIgnoreTouchEvents)
2799 
2800 #ifndef QT_NO_GESTURES
2801  if (d->scene) {
2802  foreach (Qt::GestureType gesture, d->scene->d_func()->grabbedGestures.keys())
2803  widget->grabGesture(gesture);
2804  }
2805 #endif
2806 
2807  widget->setAcceptDrops(acceptDrops());
2808 }
double d
Definition: qnumeric_p.h:62
bool acceptDrops() const
#define Q_D(Class)
Definition: qglobal.h:2482
void grabGesture(Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
Subscribes the widget to a given gesture with specific flags.
Definition: qwidget.cpp:12964
Q_CORE_EXPORT void qWarning(const char *,...)
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
Definition: qobject.h:275
GestureType
Definition: qnamespace.h:1759
void setMouseTracking(bool enable)
Definition: qwidget.h:990
void setAutoFillBackground(bool enabled)
Definition: qwidget.cpp:631
void setAcceptDrops(bool on)
Definition: qwidget.cpp:3534
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
void setFocusPolicy(Qt::FocusPolicy policy)
Definition: qwidget.cpp:7631

◆ setViewportUpdateMode()

void QGraphicsView::setViewportUpdateMode ( ViewportUpdateMode  mode)

Definition at line 1384 of file qgraphicsview.cpp.

1385 {
1386  Q_D(QGraphicsView);
1387  d->viewportUpdateMode = mode;
1388 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ shear()

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

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

See also
setTransform(), transform(), rotate(), scale(), translate()

Definition at line 1847 of file qgraphicsview.cpp.

1848 {
1849  Q_D(QGraphicsView);
1850  QTransform matrix = d->matrix;
1851  matrix.shear(sh, sv);
1852  setTransform(matrix);
1853 }
double d
Definition: qnumeric_p.h:62
QMatrix matrix() const
Returns the current transformation matrix for the view.
QTransform & shear(qreal sh, qreal sv)
Shears the coordinate system by sh horizontally and sv vertically, and returns a reference to the mat...
Definition: qtransform.cpp:551
#define Q_D(Class)
Definition: qglobal.h:2482
void setTransform(const QTransform &matrix, bool combine=false)
Sets the view&#39;s current transformation matrix to matrix.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ showEvent()

void QGraphicsView::showEvent ( QShowEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3748 of file qgraphicsview.cpp.

3749 {
3750  Q_D(QGraphicsView);
3751  d->recalculateContentSize();
3752  d->centerView(d->transformationAnchor);
3754 }
double d
Definition: qnumeric_p.h:62
virtual void showEvent(QShowEvent *)
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
Definition: qwidget.cpp:9842
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ sizeHint()

QSize QGraphicsView::sizeHint ( ) const
virtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1196 of file qgraphicsview.cpp.

1197 {
1198  Q_D(const QGraphicsView);
1199  if (d->scene) {
1200  QSizeF baseSize = d->matrix.mapRect(sceneRect()).size();
1201  baseSize += QSizeF(d->frameWidth * 2, d->frameWidth * 2);
1202  return baseSize.boundedTo((3 * QApplication::desktop()->size()) / 4).toSize();
1203  }
1205 }
QSize baseSize() const
double d
Definition: qnumeric_p.h:62
QSize size() const
QSize toSize() const
Returns an integer based copy of this size.
Definition: qsize.h:355
#define Q_D(Class)
Definition: qglobal.h:2482
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
QRectF sceneRect() const
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
QSizeF boundedTo(const QSizeF &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition: qsize.h:350
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
QSize sizeHint() const
Reimplemented Function

◆ transform()

QTransform QGraphicsView::transform ( ) const

Returns the current transformation matrix for the view.

If no current transformation is set, the identity matrix is returned.

See also
setTransform(), rotate(), scale(), shear(), translate()

Definition at line 3859 of file qgraphicsview.cpp.

Referenced by paintEvent(), and updateScene().

3860 {
3861  Q_D(const QGraphicsView);
3862  return d->matrix;
3863 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ transformationAnchor()

ViewportAnchor QGraphicsView::transformationAnchor ( ) const

Referenced by setAlignment().

◆ translate()

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

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

See also
setTransform(), transform(), rotate(), shear()

Definition at line 1860 of file qgraphicsview.cpp.

1861 {
1862  Q_D(QGraphicsView);
1863  QTransform matrix = d->matrix;
1864  matrix.translate(dx, dy);
1865  setTransform(matrix);
1866 }
double d
Definition: qnumeric_p.h:62
QMatrix matrix() const
Returns the current transformation matrix for the view.
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
Definition: qtransform.cpp:417
#define Q_D(Class)
Definition: qglobal.h:2482
void setTransform(const QTransform &matrix, bool combine=false)
Sets the view&#39;s current transformation matrix to matrix.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ updateScene

void QGraphicsView::updateScene ( const QList< QRectF > &  rects)
slot

Schedules an update of the scene rectangles rects.

See also
QGraphicsScene::changed()

Definition at line 2674 of file qgraphicsview.cpp.

Referenced by setScene(), and viewportEvent().

2675 {
2676  // ### Note: Since 4.5, this slot is only called if the user explicitly
2677  // establishes a connection between the scene and the view, as the scene
2678  // and view are no longer connected. We need to keep it working (basically
2679  // leave it as it is), but the new delivery path is through
2680  // QGraphicsScenePrivate::itemUpdate().
2681  Q_D(QGraphicsView);
2682  if (d->fullUpdatePending || d->viewportUpdateMode == QGraphicsView::NoViewportUpdate)
2683  return;
2684 
2685  // Extract and reset dirty scene rect info.
2686  QVector<QRect> dirtyViewportRects;
2687  const QVector<QRect> &dirtyRects = d->dirtyRegion.rects();
2688  for (int i = 0; i < dirtyRects.size(); ++i)
2689  dirtyViewportRects += dirtyRects.at(i);
2690  d->dirtyRegion = QRegion();
2691  d->dirtyBoundingRect = QRect();
2692 
2693  bool fullUpdate = !d->accelerateScrolling || d->viewportUpdateMode == QGraphicsView::FullViewportUpdate;
2694  bool boundingRectUpdate = (d->viewportUpdateMode == QGraphicsView::BoundingRectViewportUpdate)
2695  || (d->viewportUpdateMode == QGraphicsView::SmartViewportUpdate
2696  && ((dirtyViewportRects.size() + rects.size()) >= QGRAPHICSVIEW_REGION_RECT_THRESHOLD));
2697 
2698  QRegion updateRegion;
2700  QRect viewportRect = viewport()->rect();
2701  bool redraw = false;
2703 
2704  // Convert scene rects to viewport rects.
2705  foreach (const QRectF &rect, rects) {
2706  QRect xrect = transform.mapRect(rect).toAlignedRect();
2707  if (!(d->optimizationFlags & DontAdjustForAntialiasing))
2708  xrect.adjust(-2, -2, 2, 2);
2709  else
2710  xrect.adjust(-1, -1, 1, 1);
2711  if (!viewportRect.intersects(xrect))
2712  continue;
2713  dirtyViewportRects << xrect;
2714  }
2715 
2716  foreach (const QRect &rect, dirtyViewportRects) {
2717  // Add the exposed rect to the update region. In rect update
2718  // mode, we only count the bounding rect of items.
2719  if (!boundingRectUpdate) {
2720  updateRegion += rect;
2721  } else {
2722  boundingRect |= rect;
2723  }
2724  redraw = true;
2725  if (fullUpdate) {
2726  // If fullUpdate is true and we found a visible dirty rect,
2727  // we're done.
2728  break;
2729  }
2730  }
2731 
2732  if (!redraw)
2733  return;
2734 
2735  if (fullUpdate)
2736  viewport()->update();
2737  else if (boundingRectUpdate)
2738  viewport()->update(boundingRect);
2739  else
2740  viewport()->update(updateRegion);
2741 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QTransform viewportTransform() const
Returns a matrix that maps viewport coordinates to scene coordinates.
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
static const QRectF boundingRect(const QPointF *points, int pointCount)
QWidget * viewport() const
Returns the viewport widget.
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
static const int QGRAPHICSVIEW_REGION_RECT_THRESHOLD
QTransform transform() const
Returns the current transformation matrix for the view.
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QRect rect() const
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
bool intersects(const QRect &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:1429
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ updateSceneRect

void QGraphicsView::updateSceneRect ( const QRectF rect)
slot

Notifies QGraphicsView that the scene's scene rect has changed.

rect is the new scene rect. If the view already has an explicitly set scene rect, this function does nothing.

See also
sceneRect, QGraphicsScene::sceneRectChanged()

Definition at line 2750 of file qgraphicsview.cpp.

Referenced by setScene().

2751 {
2752  Q_D(QGraphicsView);
2753  if (!d->hasSceneRect) {
2754  d->sceneRect = rect;
2755  d->recalculateContentSize();
2756  }
2757 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QRect rect() const
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ viewportEvent()

bool QGraphicsView::viewportEvent ( QEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractScrollArea.

Definition at line 2854 of file qgraphicsview.cpp.

2855 {
2856  Q_D(QGraphicsView);
2857  if (!d->scene)
2858  return QAbstractScrollArea::viewportEvent(event);
2859 
2860  switch (event->type()) {
2861  case QEvent::Enter:
2862  QApplication::sendEvent(d->scene, event);
2863  break;
2865  QApplication::sendEvent(d->scene, event);
2866  break;
2868  // ### This is a temporary fix for until we get proper mouse
2869  // grab events. mouseGrabberItem should be set to 0 if we lose
2870  // the mouse grab.
2871  // Remove all popups when the scene loses focus.
2872  if (!d->scene->d_func()->popupWidgets.isEmpty())
2873  d->scene->d_func()->removePopup(d->scene->d_func()->popupWidgets.first());
2874  QApplication::sendEvent(d->scene, event);
2875  break;
2876  case QEvent::Show:
2877  if (d->scene && isActiveWindow()) {
2878  QEvent windowActivate(QEvent::WindowActivate);
2879  QApplication::sendEvent(d->scene, &windowActivate);
2880  }
2881  break;
2882  case QEvent::Hide:
2883  // spontaneous event will generate a WindowDeactivate.
2884  if (!event->spontaneous() && d->scene && isActiveWindow()) {
2885  QEvent windowDeactivate(QEvent::WindowDeactivate);
2886  QApplication::sendEvent(d->scene, &windowDeactivate);
2887  }
2888  break;
2889  case QEvent::Leave:
2890  // ### This is a temporary fix for until we get proper mouse grab
2891  // events. activeMouseGrabberItem should be set to 0 if we lose the
2892  // mouse grab.
2895  || (QApplication::activeWindow() != window())) {
2896  if (!d->scene->d_func()->popupWidgets.isEmpty())
2897  d->scene->d_func()->removePopup(d->scene->d_func()->popupWidgets.first());
2898  }
2899  d->useLastMouseEvent = false;
2900  // a hack to pass a viewport pointer to the scene inside the leave event
2901  Q_ASSERT(event->d == 0);
2902  event->d = reinterpret_cast<QEventPrivate *>(viewport());
2903  QApplication::sendEvent(d->scene, event);
2904  break;
2905 #ifndef QT_NO_TOOLTIP
2906  case QEvent::ToolTip: {
2907  QHelpEvent *toolTip = static_cast<QHelpEvent *>(event);
2909  helpEvent.setWidget(viewport());
2910  helpEvent.setScreenPos(toolTip->globalPos());
2911  helpEvent.setScenePos(mapToScene(toolTip->pos()));
2912  QApplication::sendEvent(d->scene, &helpEvent);
2913  toolTip->setAccepted(helpEvent.isAccepted());
2914  return true;
2915  }
2916 #endif
2917  case QEvent::Paint:
2918  // Reset full update
2919  d->fullUpdatePending = false;
2920  d->dirtyScrollOffset = QPoint();
2921  if (d->scene) {
2922  // Check if this view reimplements the updateScene slot; if it
2923  // does, we can't do direct update delivery and have to fall back
2924  // to connecting the changed signal.
2925  if (!d->updateSceneSlotReimplementedChecked) {
2926  d->updateSceneSlotReimplementedChecked = true;
2927  const QMetaObject *mo = metaObject();
2928  if (mo != &QGraphicsView::staticMetaObject) {
2929  if (mo->indexOfSlot("updateScene(QList<QRectF>)")
2930  != QGraphicsView::staticMetaObject.indexOfSlot("updateScene(QList<QRectF>)")) {
2931  connect(d->scene, SIGNAL(changed(QList<QRectF>)),
2932  this, SLOT(updateScene(QList<QRectF>)));
2933  }
2934  }
2935  }
2936  }
2937  break;
2938  case QEvent::TouchBegin:
2939  case QEvent::TouchUpdate:
2940  case QEvent::TouchEnd:
2941  {
2942  if (!isEnabled())
2943  return false;
2944 
2945  if (d->scene && d->sceneInteractionAllowed) {
2946  // Convert and deliver the touch event to the scene.
2947  QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
2948  touchEvent->setWidget(viewport());
2950  (void) QApplication::sendEvent(d->scene, touchEvent);
2951  }
2952 
2953  return true;
2954  }
2955 #ifndef QT_NO_GESTURES
2956  case QEvent::Gesture:
2958  {
2959  if (!isEnabled())
2960  return false;
2961 
2962  if (d->scene && d->sceneInteractionAllowed) {
2963  QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(event);
2964  gestureEvent->setWidget(viewport());
2965  (void) QApplication::sendEvent(d->scene, gestureEvent);
2966  }
2967  return true;
2968  }
2969 #endif // QT_NO_GESTURES
2970  default:
2971  break;
2972  }
2973 
2974  return QAbstractScrollArea::viewportEvent(event);
2975 }
void updateScene(const QList< QRectF > &rects)
Schedules an update of the scene rectangles rects.
double d
Definition: qnumeric_p.h:62
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
static QWidget * activeWindow()
Returns the application top-level window that has the keyboard input focus, or 0 if no application wi...
void setAccepted(bool accepted)
Definition: qcoreevent.h:306
#define SLOT(a)
Definition: qobjectdefs.h:226
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
bool isActiveWindow() const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget * viewport() const
Returns the viewport widget.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static QWidget * activeModalWidget()
Returns the active modal widget.
The QGestureEvent class provides the description of triggered gestures.
Definition: qevent.h:841
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool spontaneous() const
Returns true if the event originated outside the application (a system event); otherwise returns fals...
Definition: qcoreevent.h:304
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
int indexOfSlot(const char *slot) const
Finds slot and returns its index; otherwise returns -1.
bool isEnabled() const
Definition: qwidget.h:948
QEventPrivate * d
Definition: qcoreevent.h:315
virtual bool viewportEvent(QEvent *)
The main event handler for the scrolling area (the viewport() widget).
The QGraphicsSceneHelpEvent class provides events when a tooltip is requested.
bool event(QEvent *event)
Reimplemented Function
QString toolTip() const
static QWidget * activePopupWidget()
Returns the active popup widget.
static void translateTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *touchEvent)
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void setWidget(QWidget *widget)
Sets the widget for this event to the widget specified.
Definition: qevent.cpp:5039
const QPoint & globalPos() const
Returns the mouse cursor position when the event was generated in global coordinates.
Definition: qevent.h:598
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
The QTouchEvent class contains parameters that describe a touch event.
Definition: qevent.h:741
void setWidget(QWidget *awidget)
Definition: qevent.h:823
QTouchEventSequence touchEvent(QWidget *widget=0, QTouchEvent::DeviceType deviceType=QTouchEvent::TouchScreen)
Creates and returns a QTouchEventSequence for the device deviceType to simulate events for widget...
Definition: qtesttouch.h:141
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition: qevent.h:586
const QPoint & pos() const
Returns the mouse cursor position when the event was generated, relative to the widget to which the e...
Definition: qevent.h:597

◆ viewportTransform()

QTransform QGraphicsView::viewportTransform ( ) const

Returns a matrix that maps viewport coordinates to scene coordinates.

See also
mapToScene(), mapFromScene()

Definition at line 3870 of file qgraphicsview.cpp.

Referenced by QGraphicsItemPrivate::genericMapFromScene(), QGraphicsScenePrivate::gestureEventHandler(), items(), QGraphicsScenePrivate::itemsAtPosition(), mouseMoveEvent(), QGraphicsItem::mouseMoveEvent(), paintEvent(), QGraphicsScene::update(), updateHelper(), and updateScene().

3871 {
3872  Q_D(const QGraphicsView);
3873  QTransform moveMatrix = QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll());
3874  return d->identityMatrix ? moveMatrix : d->matrix * moveMatrix;
3875 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis...
Definition: qtransform.cpp:462
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ viewportUpdateMode()

ViewportUpdateMode QGraphicsView::viewportUpdateMode ( ) const

Referenced by setResizeAnchor().

◆ wheelEvent()

void QGraphicsView::wheelEvent ( QWheelEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3465 of file qgraphicsview.cpp.

3466 {
3467  Q_D(QGraphicsView);
3468  if (!d->scene || !d->sceneInteractionAllowed) {
3470  return;
3471  }
3472 
3473  event->ignore();
3474 
3476  wheelEvent.setWidget(viewport());
3477  wheelEvent.setScenePos(mapToScene(event->pos()));
3478  wheelEvent.setScreenPos(event->globalPos());
3479  wheelEvent.setButtons(event->buttons());
3480  wheelEvent.setModifiers(event->modifiers());
3481  wheelEvent.setDelta(event->delta());
3482  wheelEvent.setOrientation(event->orientation());
3483  wheelEvent.setAccepted(false);
3485  event->setAccepted(wheelEvent.isAccepted());
3486  if (!event->isAccepted())
3488 }
double d
Definition: qnumeric_p.h:62
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
#define Q_D(Class)
Definition: qglobal.h:2482
void wheelEvent(QWheelEvent *)
This event handler can be reimplemented in a subclass to receive wheel events for the viewport() widg...
QWidget * viewport() const
Returns the viewport widget.
bool isAccepted() const
Definition: qcoreevent.h:307
int delta() const
Returns the distance that the wheel is rotated, in eighths of a degree.
Definition: qevent.h:150
Qt::MouseButtons buttons() const
Returns the mouse state when the event occurred.
Definition: qevent.h:158
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
Qt::Orientation orientation() const
Returns the wheel&#39;s orientation.
Definition: qevent.h:159
const QPoint & pos() const
Returns the position of the mouse cursor relative to the widget that received the event...
Definition: qevent.h:151
const QPoint & globalPos() const
Returns the global position of the mouse pointer at the time of the event.
Definition: qevent.h:152
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
The QGraphicsSceneWheelEvent class provides wheel events in the graphics view framework.
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition: qevent.h:79
void wheelEvent(QWheelEvent *event)
Reimplemented Function

Friends and Related Functions

◆ QGraphicsItemPrivate

friend class QGraphicsItemPrivate
friend

Definition at line 281 of file qgraphicsview.h.

◆ QGraphicsScene

friend class QGraphicsScene
friend

Definition at line 279 of file qgraphicsview.h.

◆ QGraphicsScenePrivate

Definition at line 280 of file qgraphicsview.h.

◆ QGraphicsSceneWidget

friend class QGraphicsSceneWidget
friend

Definition at line 278 of file qgraphicsview.h.

Properties

◆ alignment

Qt::Alignment QGraphicsView::alignment
private

the alignment of the scene in the view when the whole scene is visible.

If the whole scene is visible in the view, (i.e., there are no visible scroll bars,) the view's alignment will decide where the scene will be rendered in the view. For example, if the alignment is Qt::AlignCenter, which is default, 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.

Definition at line 73 of file qgraphicsview.h.

◆ backgroundBrush

QBrush QGraphicsView::backgroundBrush
private

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, you can reimplement drawBackground() instead.

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

See also
QGraphicsScene::backgroundBrush, foregroundBrush

Definition at line 69 of file qgraphicsview.h.

◆ cacheMode

QGraphicsView::CacheMode QGraphicsView::cacheMode
private

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 that are slow to render. Texture, gradient and alpha blended backgrounds, for example, can be notibly slow to render; especially with a transformed view. The CacheBackground flag enables caching of the view's background. For example:

view.setBackgroundBrush(QImage(":/images/backgroundtile.png"));

The cache is invalidated every time the view is transformed. However, when scrolling, only partial invalidation is required.

By default, nothing is cached.

See also
resetCachedContent(), QPixmapCache

Definition at line 76 of file qgraphicsview.h.

◆ dragMode

QGraphicsView::DragMode QGraphicsView::dragMode
private

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 (e.g., scrolling the viewport contents using a pointing hand cursor, or selecting multiple items with a rubber band). The default value, NoDrag, does nothing.

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

Definition at line 75 of file qgraphicsview.h.

◆ foregroundBrush

QBrush QGraphicsView::foregroundBrush
private

the foreground brush of the scene.

This property sets the foreground brush for the scene in this view. It is used to override the scene's own foreground, and defines the behavior of drawForeground(). To provide custom foreground drawing for this view, you can reimplement drawForeground() instead.

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

See also
QGraphicsScene::foregroundBrush, backgroundBrush

Definition at line 70 of file qgraphicsview.h.

◆ interactive

QGraphicsView::interactive
private

whether the view allowed scene interaction.

If enabled, this view is set to allow scene interaction. Otherwise, this view will not allow interaction, and any mouse or key events are ignored (i.e., it will act as a read-only view).

By default, this property is true.

Definition at line 71 of file qgraphicsview.h.

◆ optimizationFlags

QGraphicsView::OptimizationFlags QGraphicsView::optimizationFlags
private

flags that can be used to tune QGraphicsView's performance.

Since
4.3

QGraphicsView uses clipping, extra bounding rect adjustments, and certain other aids to improve rendering quality and performance for the common case graphics scene. However, depending on the target platform, the scene, and the viewport in use, some of these operations can degrade performance.

The effect varies from flag to flag; see the OptimizationFlags documentation for details.

By default, no optimization flags are enabled.

See also
setOptimizationFlag()

Definition at line 83 of file qgraphicsview.h.

Referenced by QGraphicsScene::drawItems().

◆ renderHints

QPainter::RenderHints QGraphicsView::renderHints
private

the default render hints for the view

These hints are used to initialize QPainter before each visible item is drawn. QPainter uses render hints to toggle rendering features such as antialiasing and smooth pixmap transformation.

QPainter::TextAntialiasing is enabled by default.

Example:

Definition at line 74 of file qgraphicsview.h.

◆ resizeAnchor

QGraphicsView::ViewportAnchor QGraphicsView::resizeAnchor
private

how the view should position the scene when the view is resized.

QGraphicsView uses this property to decide how to position the scene in the viewport when the viewport widget's size changes. The default behavior, NoAnchor, leaves the scene's position unchanged during a resize; the top-left corner of the view will appear to be anchored while resizing.

Note that the effect of this property is noticeable when only a part of the scene is visible (i.e., when there are scroll bars). Otherwise, if the whole scene fits in the view, QGraphicsScene uses the view alignment to position the scene in the view.

See also
alignment, transformationAnchor, Qt::WNorthWestGravity

Definition at line 78 of file qgraphicsview.h.

◆ rubberBandSelectionMode

Qt::ItemSelectionMode QGraphicsView::rubberBandSelectionMode
private

the behavior for selecting items with a rubber band selection rectangle.

Since
4.3

This property defines how items are selected when using the RubberBandDrag drag mode.

The default value is Qt::IntersectsItemShape; all items whose shape intersects with or is contained by the rubber band are selected.

See also
dragMode, items()

Definition at line 81 of file qgraphicsview.h.

◆ sceneRect

QRectF QGraphicsView::sceneRect
private

the area of the scene visualized by this view.

The scene rectangle defines the extent of the scene, and in the view's case, this means the area of the scene that you can navigate using the scroll bars.

If unset, or if a null QRectF is set, this property has the same value as QGraphicsScene::sceneRect, and it changes with QGraphicsScene::sceneRect. Otherwise, the view's scene rect is unaffected by the scene.

Note that, although the scene supports a virtually unlimited size, the range of the scroll bars will never exceed the range of an integer (INT_MIN, INT_MAX). When the scene is larger than the scroll bars' values, you can choose to use translate() to navigate the scene instead.

By default, this property contains a rectangle at the origin with zero width and height.

See also
QGraphicsScene::sceneRect

Definition at line 72 of file qgraphicsview.h.

◆ transformationAnchor

QGraphicsView::ViewportAnchor QGraphicsView::transformationAnchor
private

how the view should position the scene during transformations.

QGraphicsView uses this property to decide how to position the scene in the viewport when the transformation matrix changes, and the coordinate system of the view is transformed. The default behavior, AnchorViewCenter, ensures that the scene point at the center of the view remains unchanged during transformations (e.g., when rotating, the scene will appear to rotate around the center of the view).

Note that the effect of this property is noticeable when only a part of the scene is visible (i.e., when there are scroll bars). Otherwise, if the whole scene fits in the view, QGraphicsScene uses the view alignment to position the scene in the view.

See also
alignment, resizeAnchor

Definition at line 77 of file qgraphicsview.h.

◆ viewportUpdateMode

QGraphicsView::ViewportUpdateMode QGraphicsView::viewportUpdateMode
private

how the viewport should update its contents.

Since
4.3

QGraphicsView uses this property to decide how to update areas of the scene that have been reexposed or changed. Usually you do not need to modify this property, but there are some cases where doing so can improve rendering performance. See the ViewportUpdateMode documentation for specific details.

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

Definition at line 79 of file qgraphicsview.h.

Referenced by QGLGraphicsSystem::createWindowSurface().


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