<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html><head><title>QGraphicsView Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } td.postheader { font-family: sans-serif } tr.address { font-family: sans-serif } body { background: #ffffff; color: black; } </style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QGraphicsView Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QGraphicsView class provides a widget for displaying the contents of a <a href="qgraphicsscene.html">QGraphicsScene</a>. <a href="#details">More...</a></p> <p>Inherits <a href="qabstractscrollarea.html">QAbstractScrollArea</a>.</p><p>Inherited by <a href="qdeclarativeview.html">QDeclarativeView</a>.</p><h3>Types</h3><ul><li><div class="fn" />class <b><a href="qgraphicsview-cachemode.html">CacheMode</a></b></li><li><div class="fn" />enum <b><a href="qgraphicsview.html#CacheModeFlag-enum">CacheModeFlag</a></b> { CacheNone, CacheBackground }</li><li><div class="fn" />enum <b><a href="qgraphicsview.html#DragMode-enum">DragMode</a></b> { NoDrag, ScrollHandDrag, RubberBandDrag }</li><li><div class="fn" />enum <b><a href="qgraphicsview.html#OptimizationFlag-enum">OptimizationFlag</a></b> { DontClipPainter, DontSavePainterState, DontAdjustForAntialiasing }</li><li><div class="fn" />class <b><a href="qgraphicsview-optimizationflags.html">OptimizationFlags</a></b></li><li><div class="fn" />enum <b><a href="qgraphicsview.html#ViewportAnchor-enum">ViewportAnchor</a></b> { NoAnchor, AnchorViewCenter, AnchorUnderMouse }</li><li><div class="fn" />enum <b><a href="qgraphicsview.html#ViewportUpdateMode-enum">ViewportUpdateMode</a></b> { FullViewportUpdate, MinimalViewportUpdate, SmartViewportUpdate, BoundingRectViewportUpdate, NoViewportUpdate }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qgraphicsview.html#QGraphicsView">__init__</a></b> (<i>self</i>, QWidget <i>parent</i> = None)</li><li><div class="fn" /><b><a href="qgraphicsview.html#QGraphicsView-2">__init__</a></b> (<i>self</i>, QGraphicsScene <i>scene</i>, QWidget <i>parent</i> = None)</li><li><div class="fn" />Qt.Alignment <b><a href="qgraphicsview.html#alignment">alignment</a></b> (<i>self</i>)</li><li><div class="fn" />QBrush <b><a href="qgraphicsview.html#backgroundBrush">backgroundBrush</a></b> (<i>self</i>)</li><li><div class="fn" />CacheMode <b><a href="qgraphicsview.html#cacheMode">cacheMode</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#centerOn">centerOn</a></b> (<i>self</i>, QPointF <i>pos</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#centerOn-2">centerOn</a></b> (<i>self</i>, QGraphicsItem <i>item</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#centerOn-3">centerOn</a></b> (<i>self</i>, float <i>ax</i>, float <i>ay</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#contextMenuEvent">contextMenuEvent</a></b> (<i>self</i>, QContextMenuEvent <i>event</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#dragEnterEvent">dragEnterEvent</a></b> (<i>self</i>, QDragEnterEvent <i>event</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#dragLeaveEvent">dragLeaveEvent</a></b> (<i>self</i>, QDragLeaveEvent <i>event</i>)</li><li><div class="fn" />DragMode <b><a href="qgraphicsview.html#dragMode">dragMode</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#dragMoveEvent">dragMoveEvent</a></b> (<i>self</i>, QDragMoveEvent <i>event</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#drawBackground">drawBackground</a></b> (<i>self</i>, QPainter <i>painter</i>, QRectF <i>rect</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#drawForeground">drawForeground</a></b> (<i>self</i>, QPainter <i>painter</i>, QRectF <i>rect</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#drawItems">drawItems</a></b> (<i>self</i>, QPainter <i>painter</i>, list-of-QGraphicsItem <i>items</i>, list-of-QStyleOptionGraphicsItem <i>options</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#dropEvent">dropEvent</a></b> (<i>self</i>, QDropEvent <i>event</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#ensureVisible">ensureVisible</a></b> (<i>self</i>, QRectF <i>rect</i>, int <i>xMargin</i> = 50, int <i>yMargin</i> = 50)</li><li><div class="fn" /><b><a href="qgraphicsview.html#ensureVisible-2">ensureVisible</a></b> (<i>self</i>, QGraphicsItem <i>item</i>, int <i>xMargin</i> = 50, int <i>yMargin</i> = 50)</li><li><div class="fn" /><b><a href="qgraphicsview.html#ensureVisible-3">ensureVisible</a></b> (<i>self</i>, float <i>x</i>, float <i>y</i>, float <i>w</i>, float <i>h</i>, int <i>xMargin</i> = 50, int <i>yMargin</i> = 50)</li><li><div class="fn" />bool <b><a href="qgraphicsview.html#event">event</a></b> (<i>self</i>, QEvent <i>event</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#fitInView">fitInView</a></b> (<i>self</i>, QRectF <i>rect</i>, Qt.AspectRatioMode <i>mode</i> = Qt.IgnoreAspectRatio)</li><li><div class="fn" /><b><a href="qgraphicsview.html#fitInView-2">fitInView</a></b> (<i>self</i>, QGraphicsItem <i>item</i>, Qt.AspectRatioMode <i>mode</i> = Qt.IgnoreAspectRatio)</li><li><div class="fn" /><b><a href="qgraphicsview.html#fitInView-3">fitInView</a></b> (<i>self</i>, float <i>x</i>, float <i>y</i>, float <i>w</i>, float <i>h</i>, Qt.AspectRatioMode <i>mode</i> = Qt.IgnoreAspectRatio)</li><li><div class="fn" /><b><a href="qgraphicsview.html#focusInEvent">focusInEvent</a></b> (<i>self</i>, QFocusEvent <i>event</i>)</li><li><div class="fn" />bool <b><a href="qgraphicsview.html#focusNextPrevChild">focusNextPrevChild</a></b> (<i>self</i>, bool <i>next</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#focusOutEvent">focusOutEvent</a></b> (<i>self</i>, QFocusEvent <i>event</i>)</li><li><div class="fn" />QBrush <b><a href="qgraphicsview.html#foregroundBrush">foregroundBrush</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#inputMethodEvent">inputMethodEvent</a></b> (<i>self</i>, QInputMethodEvent <i>event</i>)</li><li><div class="fn" />QVariant <b><a href="qgraphicsview.html#inputMethodQuery">inputMethodQuery</a></b> (<i>self</i>, Qt.InputMethodQuery <i>query</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#invalidateScene">invalidateScene</a></b> (<i>self</i>, QRectF <i>rect</i> = QRectF(), QGraphicsScene.SceneLayers <i>layers</i> = QGraphicsScene.AllLayers)</li><li><div class="fn" />bool <b><a href="qgraphicsview.html#isInteractive">isInteractive</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qgraphicsview.html#isTransformed">isTransformed</a></b> (<i>self</i>)</li><li><div class="fn" />QGraphicsItem <b><a href="qgraphicsview.html#itemAt">itemAt</a></b> (<i>self</i>, QPoint <i>pos</i>)</li><li><div class="fn" />QGraphicsItem <b><a href="qgraphicsview.html#itemAt-2">itemAt</a></b> (<i>self</i>, int <i>ax</i>, int <i>ay</i>)</li><li><div class="fn" />list-of-QGraphicsItem <b><a href="qgraphicsview.html#items">items</a></b> (<i>self</i>)</li><li><div class="fn" />list-of-QGraphicsItem <b><a href="qgraphicsview.html#items-2">items</a></b> (<i>self</i>, QPoint <i>pos</i>)</li><li><div class="fn" />list-of-QGraphicsItem <b><a href="qgraphicsview.html#items-3">items</a></b> (<i>self</i>, int <i>ax</i>, int <i>ay</i>)</li><li><div class="fn" />list-of-QGraphicsItem <b><a href="qgraphicsview.html#items-4">items</a></b> (<i>self</i>, int <i>x</i>, int <i>y</i>, int <i>w</i>, int <i>h</i>, Qt.ItemSelectionMode <i>mode</i> = Qt.IntersectsItemShape)</li><li><div class="fn" />list-of-QGraphicsItem <b><a href="qgraphicsview.html#items-5">items</a></b> (<i>self</i>, QRect <i>rect</i>, Qt.ItemSelectionMode <i>mode</i> = Qt.IntersectsItemShape)</li><li><div class="fn" />list-of-QGraphicsItem <b><a href="qgraphicsview.html#items-6">items</a></b> (<i>self</i>, QPolygon <i>polygon</i>, Qt.ItemSelectionMode <i>mode</i> = Qt.IntersectsItemShape)</li><li><div class="fn" />list-of-QGraphicsItem <b><a href="qgraphicsview.html#items-7">items</a></b> (<i>self</i>, QPainterPath <i>path</i>, Qt.ItemSelectionMode <i>mode</i> = Qt.IntersectsItemShape)</li><li><div class="fn" /><b><a href="qgraphicsview.html#keyPressEvent">keyPressEvent</a></b> (<i>self</i>, QKeyEvent <i>event</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#keyReleaseEvent">keyReleaseEvent</a></b> (<i>self</i>, QKeyEvent <i>event</i>)</li><li><div class="fn" />QPoint <b><a href="qgraphicsview.html#mapFromScene">mapFromScene</a></b> (<i>self</i>, QPointF <i>point</i>)</li><li><div class="fn" />QPolygon <b><a href="qgraphicsview.html#mapFromScene-2">mapFromScene</a></b> (<i>self</i>, QRectF <i>rect</i>)</li><li><div class="fn" />QPolygon <b><a href="qgraphicsview.html#mapFromScene-3">mapFromScene</a></b> (<i>self</i>, QPolygonF <i>polygon</i>)</li><li><div class="fn" />QPainterPath <b><a href="qgraphicsview.html#mapFromScene-4">mapFromScene</a></b> (<i>self</i>, QPainterPath <i>path</i>)</li><li><div class="fn" />QPoint <b><a href="qgraphicsview.html#mapFromScene-5">mapFromScene</a></b> (<i>self</i>, float <i>ax</i>, float <i>ay</i>)</li><li><div class="fn" />QPolygon <b><a href="qgraphicsview.html#mapFromScene-6">mapFromScene</a></b> (<i>self</i>, float <i>ax</i>, float <i>ay</i>, float <i>w</i>, float <i>h</i>)</li><li><div class="fn" />QPointF <b><a href="qgraphicsview.html#mapToScene">mapToScene</a></b> (<i>self</i>, QPoint <i>point</i>)</li><li><div class="fn" />QPolygonF <b><a href="qgraphicsview.html#mapToScene-2">mapToScene</a></b> (<i>self</i>, QRect <i>rect</i>)</li><li><div class="fn" />QPolygonF <b><a href="qgraphicsview.html#mapToScene-3">mapToScene</a></b> (<i>self</i>, QPolygon <i>polygon</i>)</li><li><div class="fn" />QPainterPath <b><a href="qgraphicsview.html#mapToScene-4">mapToScene</a></b> (<i>self</i>, QPainterPath <i>path</i>)</li><li><div class="fn" />QPointF <b><a href="qgraphicsview.html#mapToScene-5">mapToScene</a></b> (<i>self</i>, int <i>ax</i>, int <i>ay</i>)</li><li><div class="fn" />QPolygonF <b><a href="qgraphicsview.html#mapToScene-6">mapToScene</a></b> (<i>self</i>, int <i>ax</i>, int <i>ay</i>, int <i>w</i>, int <i>h</i>)</li><li><div class="fn" />QMatrix <b><a href="qgraphicsview.html#matrix">matrix</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#mouseDoubleClickEvent">mouseDoubleClickEvent</a></b> (<i>self</i>, QMouseEvent <i>event</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#mouseMoveEvent">mouseMoveEvent</a></b> (<i>self</i>, QMouseEvent <i>event</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#mousePressEvent">mousePressEvent</a></b> (<i>self</i>, QMouseEvent <i>event</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#mouseReleaseEvent">mouseReleaseEvent</a></b> (<i>self</i>, QMouseEvent <i>event</i>)</li><li><div class="fn" />OptimizationFlags <b><a href="qgraphicsview.html#optimizationFlags">optimizationFlags</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#paintEvent">paintEvent</a></b> (<i>self</i>, QPaintEvent <i>event</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#render">render</a></b> (<i>self</i>, QPainter <i>painter</i>, QRectF <i>target</i> = QRectF(), QRect <i>source</i> = QRect(), Qt.AspectRatioMode <i>mode</i> = Qt.KeepAspectRatio)</li><li><div class="fn" />QPainter.RenderHints <b><a href="qgraphicsview.html#renderHints">renderHints</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#resetCachedContent">resetCachedContent</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#resetMatrix">resetMatrix</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#resetTransform">resetTransform</a></b> (<i>self</i>)</li><li><div class="fn" />ViewportAnchor <b><a href="qgraphicsview.html#resizeAnchor">resizeAnchor</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#resizeEvent">resizeEvent</a></b> (<i>self</i>, QResizeEvent <i>event</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#rotate">rotate</a></b> (<i>self</i>, float <i>angle</i>)</li><li><div class="fn" />Qt.ItemSelectionMode <b><a href="qgraphicsview.html#rubberBandSelectionMode">rubberBandSelectionMode</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#scale">scale</a></b> (<i>self</i>, float <i>sx</i>, float <i>sy</i>)</li><li><div class="fn" />QGraphicsScene <b><a href="qgraphicsview.html#scene">scene</a></b> (<i>self</i>)</li><li><div class="fn" />QRectF <b><a href="qgraphicsview.html#sceneRect">sceneRect</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#scrollContentsBy">scrollContentsBy</a></b> (<i>self</i>, int <i>dx</i>, int <i>dy</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setAlignment">setAlignment</a></b> (<i>self</i>, Qt.Alignment <i>alignment</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setBackgroundBrush">setBackgroundBrush</a></b> (<i>self</i>, QBrush <i>brush</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setCacheMode">setCacheMode</a></b> (<i>self</i>, CacheMode <i>mode</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setDragMode">setDragMode</a></b> (<i>self</i>, DragMode <i>mode</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setForegroundBrush">setForegroundBrush</a></b> (<i>self</i>, QBrush <i>brush</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setInteractive">setInteractive</a></b> (<i>self</i>, bool <i>allowed</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setMatrix">setMatrix</a></b> (<i>self</i>, QMatrix <i>matrix</i>, bool <i>combine</i> = False)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setOptimizationFlag">setOptimizationFlag</a></b> (<i>self</i>, OptimizationFlag <i>flag</i>, bool <i>enabled</i> = True)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setOptimizationFlags">setOptimizationFlags</a></b> (<i>self</i>, OptimizationFlags <i>flags</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setRenderHint">setRenderHint</a></b> (<i>self</i>, QPainter.RenderHint <i>hint</i>, bool <i>on</i> = True)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setRenderHints">setRenderHints</a></b> (<i>self</i>, QPainter.RenderHints <i>hints</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setResizeAnchor">setResizeAnchor</a></b> (<i>self</i>, ViewportAnchor <i>anchor</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setRubberBandSelectionMode">setRubberBandSelectionMode</a></b> (<i>self</i>, Qt.ItemSelectionMode <i>mode</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setScene">setScene</a></b> (<i>self</i>, QGraphicsScene <i>scene</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setSceneRect">setSceneRect</a></b> (<i>self</i>, QRectF <i>rect</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setSceneRect-2">setSceneRect</a></b> (<i>self</i>, float <i>ax</i>, float <i>ay</i>, float <i>aw</i>, float <i>ah</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setTransform">setTransform</a></b> (<i>self</i>, QTransform <i>matrix</i>, bool <i>combine</i> = False)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setTransformationAnchor">setTransformationAnchor</a></b> (<i>self</i>, ViewportAnchor <i>anchor</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setupViewport">setupViewport</a></b> (<i>self</i>, QWidget <i>widget</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#setViewportUpdateMode">setViewportUpdateMode</a></b> (<i>self</i>, ViewportUpdateMode <i>mode</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#shear">shear</a></b> (<i>self</i>, float <i>sh</i>, float <i>sv</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#showEvent">showEvent</a></b> (<i>self</i>, QShowEvent <i>event</i>)</li><li><div class="fn" />QSize <b><a href="qgraphicsview.html#sizeHint">sizeHint</a></b> (<i>self</i>)</li><li><div class="fn" />QTransform <b><a href="qgraphicsview.html#transform">transform</a></b> (<i>self</i>)</li><li><div class="fn" />ViewportAnchor <b><a href="qgraphicsview.html#transformationAnchor">transformationAnchor</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#translate">translate</a></b> (<i>self</i>, float <i>dx</i>, float <i>dy</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#updateScene">updateScene</a></b> (<i>self</i>, list-of-QRectF <i>rects</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#updateSceneRect">updateSceneRect</a></b> (<i>self</i>, QRectF <i>rect</i>)</li><li><div class="fn" />bool <b><a href="qgraphicsview.html#viewportEvent">viewportEvent</a></b> (<i>self</i>, QEvent <i>event</i>)</li><li><div class="fn" />QTransform <b><a href="qgraphicsview.html#viewportTransform">viewportTransform</a></b> (<i>self</i>)</li><li><div class="fn" />ViewportUpdateMode <b><a href="qgraphicsview.html#viewportUpdateMode">viewportUpdateMode</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicsview.html#wheelEvent">wheelEvent</a></b> (<i>self</i>, QWheelEvent <i>event</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QGraphicsView class provides a widget for displaying the contents of a <a href="qgraphicsscene.html">QGraphicsScene</a>.</p> <p>QGraphicsView visualizes the contents of a <a href="qgraphicsscene.html">QGraphicsScene</a> in a scrollable viewport. To create a scene with geometrical items, see <a href="qgraphicsscene.html">QGraphicsScene</a>'s documentation. QGraphicsView is part of the <a href="graphicsview.html">Graphics View Framework</a>.</p> <p>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 <a href="qgraphicsview.html#setScene">setScene</a>() to set the scene at a later point. After you call <a href="qwidget.html#show">show</a>(), the view will by default scroll to the center of the scene and display any items that are visible at this point. For example:</p> <pre class="cpp"> <span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span> scene; scene<span class="operator">.</span>addText(<span class="string">"Hello, world!"</span>); <span class="type">QGraphicsView</span> view(<span class="operator">&</span>scene); view<span class="operator">.</span><a href="qwidget.html#show">show</a>(); </pre> <p>You can explicitly scroll to any position on the scene by using the scroll bars, or by calling <a href="qgraphicsview.html#centerOn">centerOn</a>(). By passing a point to <a href="qgraphicsview.html#centerOn">centerOn</a>(), QGraphicsView will scroll its viewport to ensure that the point is centered in the view. An overload is provided for scrolling to a <a href="qgraphicsitem.html">QGraphicsItem</a>, 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 <a href="qgraphicsview.html#ensureVisible">ensureVisible</a>() instead.</p> <p>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 <a href="qgraphicsscene.html#itemsBoundingRect">QGraphicsScene.itemsBoundingRect</a>()). To set the visualized area rectangle yourself, you can call <a href="qgraphicsview.html#sceneRect-prop">setSceneRect</a>(). 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).</p> <p>QGraphicsView visualizes the scene by calling <a href="qgraphicsview.html#render">render</a>(). By default, the items are drawn onto the viewport by using a regular <a href="qpainter.html">QPainter</a>, and using default render hints. To change the default render hints that QGraphicsView passes to <a href="qpainter.html">QPainter</a> when painting items, you can call <a href="qgraphicsview.html#renderHints-prop">setRenderHints</a>().</p> <p>By default, QGraphicsView provides a regular <a href="qwidget.html">QWidget</a> for the viewport widget. You can access this widget by calling <a href="qabstractscrollarea.html#viewport">viewport</a>(), or you can replace it by calling <a href="qabstractscrollarea.html#setViewport">setViewport</a>(). To render using OpenGL, simply call setViewport(new <a href="qglwidget.html">QGLWidget</a>). QGraphicsView takes ownership of the viewport widget.</p> <p>QGraphicsView supports affine transformations, using <a href="qtransform.html">QTransform</a>. You can either pass a matrix to <a href="qgraphicsview.html#setTransform">setTransform</a>(), or you can call one of the convenience functions <a href="qgraphicsview.html#rotate">rotate</a>(), <a href="qgraphicsview.html#scale">scale</a>(), <a href="qgraphicsview.html#translate">translate</a>() or <a href="qgraphicsview.html#shear">shear</a>(). 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.</p> <p>You can interact with the items on the scene by using the mouse and keyboard. QGraphicsView translates the mouse and key events into <i>scene</i> events, (events that inherit <a href="qgraphicssceneevent.html">QGraphicsSceneEvent</a>,), 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 <a href="qgraphicsview.html#interactive-prop">setInteractive</a>().</p> <p>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 <a href="qgraphicsview.html#mapToScene">mapToScene</a>() and <a href="qgraphicsview.html#mapFromScene">mapFromScene</a>(), and the item accessors <a href="qgraphicsview.html#items">items</a>() and <a href="qgraphicsview.html#itemAt">itemAt</a>(). 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.</p> <p class="centerAlign"><img alt="" src="images/graphicsview-view.png" /></p> <hr /><h2>Type Documentation</h2><h3 class="fn"><a name="CacheModeFlag-enum" />QGraphicsView.CacheModeFlag</h3><p>This enum describes the flags that you can set for a <a href="qgraphicsview.html">QGraphicsView</a>'s cache mode.</p> <table class="valuelist"> <tr class="odd" valign="top"> <th class="tblConst">Constant</th> <th class="tblval">Value</th> <th class="tbldscr">Description</th> </tr> <tr> <td class="topAlign"><tt>QGraphicsView.CacheNone</tt></td> <td class="topAlign"><tt>0x0</tt></td> <td class="topAlign">All painting is done directly onto the viewport.</td> </tr> <tr> <td class="topAlign"><tt>QGraphicsView.CacheBackground</tt></td> <td class="topAlign"><tt>0x1</tt></td> <td class="topAlign">The background is cached. This affects both custom backgrounds, and backgrounds based on the <a href="qgraphicsview.html#backgroundBrush-prop">backgroundBrush</a> property. When this flag is enabled, <a href="qgraphicsview.html">QGraphicsView</a> will allocate one pixmap with the full size of the viewport.</td> </tr> </table> <p>The CacheMode type is a typedef for <a href="qflags.html">QFlags</a><CacheModeFlag>. It stores an OR combination of CacheModeFlag values.</p> <p><b>See also</b> <a href="qgraphicsview.html#cacheMode-prop">cacheMode</a>.</p> <h3 class="fn"><a name="DragMode-enum" />QGraphicsView.DragMode</h3><p>This enum describes the default action for the view when pressing and dragging the mouse over the viewport.</p> <table class="valuelist"> <tr class="odd" valign="top"> <th class="tblConst">Constant</th> <th class="tblval">Value</th> <th class="tbldscr">Description</th> </tr> <tr> <td class="topAlign"><tt>QGraphicsView.NoDrag</tt></td> <td class="topAlign"><tt>0</tt></td> <td class="topAlign">Nothing happens; the mouse event is ignored.</td> </tr> <tr> <td class="topAlign"><tt>QGraphicsView.ScrollHandDrag</tt></td> <td class="topAlign"><tt>1</tt></td> <td class="topAlign">The cursor changes into a pointing hand, and dragging the mouse around will scroll the scrolbars. This mode works both in <a href="qgraphicsview.html#interactive-prop">interactive</a> and non-interactive mode.</td> </tr> <tr> <td class="topAlign"><tt>QGraphicsView.RubberBandDrag</tt></td> <td class="topAlign"><tt>2</tt></td> <td class="topAlign">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.</td> </tr> </table> <p><b>See also</b> <a href="qgraphicsview.html#dragMode-prop">dragMode</a> and <a href="qgraphicsscene.html#setSelectionArea">QGraphicsScene.setSelectionArea</a>().</p> <h3 class="fn"><a name="OptimizationFlag-enum" />QGraphicsView.OptimizationFlag</h3><p>This enum describes flags that you can enable to improve rendering performance in <a href="qgraphicsview.html">QGraphicsView</a>. 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.</p> <table class="valuelist"> <tr class="odd" valign="top"> <th class="tblConst">Constant</th> <th class="tblval">Value</th> <th class="tbldscr">Description</th> </tr> <tr> <td class="topAlign"><tt>QGraphicsView.DontClipPainter</tt></td> <td class="topAlign"><tt>0x1</tt></td> <td class="topAlign">This value is obsolete and has no effect.</td> </tr> <tr> <td class="topAlign"> <tt>QGraphicsView.DontSavePainterState</tt></td> <td class="topAlign"><tt>0x2</tt></td> <td class="topAlign">When rendering, <a href="qgraphicsview.html">QGraphicsView</a> protects the painter state (see <a href="qpainter.html#save">QPainter.save</a>()) 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 <a href="qpainter.html#setPen">QPainter.setPen</a>() or <a href="qpainter.html#setBrush">QPainter.setBrush</a>() without restoring the state after painting). However, if the items consistently do restore the state, you should enable this flag to prevent <a href="qgraphicsview.html">QGraphicsView</a> from doing the same.</td> </tr> <tr> <td class="topAlign"> <tt>QGraphicsView.DontAdjustForAntialiasing</tt></td> <td class="topAlign"><tt>0x4</tt></td> <td class="topAlign">Disables <a href="qgraphicsview.html">QGraphicsView</a>'s antialiasing auto-adjustment of exposed areas. Items that render antialiased lines on the boundaries of their <a href="qgraphicsitem.html#boundingRect">QGraphicsItem.boundingRect</a>() can end up rendering parts of the line outside. To prevent rendering artifacts, <a href="qgraphicsview.html">QGraphicsView</a> expands all exposed regions by 2 pixels in all directions. If you enable this flag, <a href="qgraphicsview.html">QGraphicsView</a> 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.</td> </tr> <tr> <td class="topAlign"><tt>QGraphicsView.IndirectPainting</tt></td> <td class="topAlign"><tt>0x8</tt></td> <td class="topAlign">Since Qt 4.6, restore the old painting algorithm that calls <a class="obsolete" href="qgraphicsview-obsolete.html#drawItems">QGraphicsView.drawItems</a>() and <a class="obsolete" href="qgraphicsscene-obsolete.html#drawItems">QGraphicsScene.drawItems</a>(). To be used only for compatibility with old code.</td> </tr> </table> <p>This enum was introduced or modified in Qt 4.3.</p> <p>The OptimizationFlags type is a typedef for <a href="qflags.html">QFlags</a><OptimizationFlag>. It stores an OR combination of OptimizationFlag values.</p> <h3 class="fn"><a name="ViewportAnchor-enum" />QGraphicsView.ViewportAnchor</h3><p>This enums describe the possible anchors that <a href="qgraphicsview.html">QGraphicsView</a> can use when the user resizes the view or when the view is transformed.</p> <table class="valuelist"> <tr class="odd" valign="top"> <th class="tblConst">Constant</th> <th class="tblval">Value</th> <th class="tbldscr">Description</th> </tr> <tr> <td class="topAlign"><tt>QGraphicsView.NoAnchor</tt></td> <td class="topAlign"><tt>0</tt></td> <td class="topAlign">No anchor, i.e. the view leaves the scene's position unchanged.</td> </tr> <tr> <td class="topAlign"><tt>QGraphicsView.AnchorViewCenter</tt></td> <td class="topAlign"><tt>1</tt></td> <td class="topAlign">The scene point at the center of the view is used as the anchor.</td> </tr> <tr> <td class="topAlign"><tt>QGraphicsView.AnchorUnderMouse</tt></td> <td class="topAlign"><tt>2</tt></td> <td class="topAlign">The point under the mouse is used as the anchor.</td> </tr> </table> <p><b>See also</b> <a href="qgraphicsview.html#resizeAnchor-prop">resizeAnchor</a> and <a href="qgraphicsview.html#transformationAnchor-prop">transformationAnchor</a>.</p> <h3 class="fn"><a name="ViewportUpdateMode-enum" />QGraphicsView.ViewportUpdateMode</h3><p>This enum describes how <a href="qgraphicsview.html">QGraphicsView</a> updates its viewport when the scene contents change or are exposed.</p> <table class="valuelist"> <tr class="odd" valign="top"> <th class="tblConst">Constant</th> <th class="tblval">Value</th> <th class="tbldscr">Description</th> </tr> <tr> <td class="topAlign"> <tt>QGraphicsView.FullViewportUpdate</tt></td> <td class="topAlign"><tt>0</tt></td> <td class="topAlign">When any visible part of the scene changes or is reexposed, <a href="qgraphicsview.html">QGraphicsView</a> will update the entire viewport. This approach is fastest when <a href="qgraphicsview.html">QGraphicsView</a> 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 <a href="qglwidget.html">QGLWidget</a>, and for viewports that need to disable scroll optimization.</td> </tr> <tr> <td class="topAlign"> <tt>QGraphicsView.MinimalViewportUpdate</tt></td> <td class="topAlign"><tt>1</tt></td> <td class="topAlign"><a href="qgraphicsview.html">QGraphicsView</a> 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 <a href="qgraphicsview.html">QGraphicsView</a>'s default mode. Although this approach provides the best performance in general, if there are many small visible changes on the scene, <a href="qgraphicsview.html">QGraphicsView</a> might end up spending more time finding the minimal approach than it will spend drawing.</td> </tr> <tr> <td class="topAlign"> <tt>QGraphicsView.SmartViewportUpdate</tt></td> <td class="topAlign"><tt>2</tt></td> <td class="topAlign"><a href="qgraphicsview.html">QGraphicsView</a> will attempt to find an optimal update mode by analyzing the areas that require a redraw.</td> </tr> <tr> <td class="topAlign"> <tt>QGraphicsView.BoundingRectViewportUpdate</tt></td> <td class="topAlign"><tt>4</tt></td> <td class="topAlign">The bounding rectangle of all changes in the viewport will be redrawn. This mode has the advantage that <a href="qgraphicsview.html">QGraphicsView</a> 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.</td> </tr> <tr> <td class="topAlign"><tt>QGraphicsView.NoViewportUpdate</tt></td> <td class="topAlign"><tt>3</tt></td> <td class="topAlign"><a href="qgraphicsview.html">QGraphicsView</a> 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 <a href="qgraphicsview.html">QGraphicsView</a>, and is suitable for scenes that either require a fixed frame rate, or where the viewport is otherwise updated externally.</td> </tr> </table> <p>This enum was introduced or modified in Qt 4.3.</p> <p><b>See also</b> <a href="qgraphicsview.html#viewportUpdateMode-prop">viewportUpdateMode</a>.</p> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QGraphicsView" />QGraphicsView.__init__ (<i>self</i>, <a href="qwidget.html">QWidget</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qgraphicsview.html">QGraphicsView</a>. <i>parent</i> is passed to <a href="qwidget.html">QWidget</a>'s constructor.</p> <h3 class="fn"><a name="QGraphicsView-2" />QGraphicsView.__init__ (<i>self</i>, <a href="qgraphicsscene.html">QGraphicsScene</a> <i>scene</i>, <a href="qwidget.html">QWidget</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qgraphicsview.html">QGraphicsView</a> and sets the visualized scene to <i>scene</i>. <i>parent</i> is passed to <a href="qwidget.html">QWidget</a>'s constructor.</p> <h3 class="fn"><a name="alignment" /><a href="qt-alignment.html">Qt.Alignment</a> QGraphicsView.alignment (<i>self</i>)</h3><h3 class="fn"><a name="backgroundBrush" /><a href="qbrush.html">QBrush</a> QGraphicsView.backgroundBrush (<i>self</i>)</h3><h3 class="fn"><a name="cacheMode" /><a href="qgraphicsview-cachemode.html">CacheMode</a> QGraphicsView.cacheMode (<i>self</i>)</h3><h3 class="fn"><a name="centerOn" />QGraphicsView.centerOn (<i>self</i>, <a href="qpointf.html">QPointF</a> <i>pos</i>)</h3><p>Scrolls the contents of the viewport to ensure that the scene coordinate <i>pos</i>, is centered in the view.</p> <p>Because <i>pos</i> is a floating point coordinate, and the scroll bars operate on integer coordinates, the centering is only an approximation.</p> <p><b>Note:</b> If the item is close to or outside the border, it will be visible in the view, but not centered.</p> <p><b>See also</b> <a href="qgraphicsview.html#ensureVisible">ensureVisible</a>().</p> <h3 class="fn"><a name="centerOn-2" />QGraphicsView.centerOn (<i>self</i>, <a href="qgraphicsitem.html">QGraphicsItem</a> <i>item</i>)</h3><p>This is an overloaded function.</p> <p>This function is provided for convenience. It's equivalent to calling centerOn(<a href="qpointf.html">QPointF</a>(<i>x</i>, <i>y</i>)).</p> <h3 class="fn"><a name="centerOn-3" />QGraphicsView.centerOn (<i>self</i>, float <i>ax</i>, float <i>ay</i>)</h3><p>This is an overloaded function.</p> <p>Scrolls the contents of the viewport to ensure that <i>item</i> is centered in the view.</p> <p><b>See also</b> <a href="qgraphicsview.html#ensureVisible">ensureVisible</a>().</p> <h3 class="fn"><a name="contextMenuEvent" />QGraphicsView.contextMenuEvent (<i>self</i>, <a href="qcontextmenuevent.html">QContextMenuEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#contextMenuEvent">QWidget.contextMenuEvent</a>().</p> <h3 class="fn"><a name="dragEnterEvent" />QGraphicsView.dragEnterEvent (<i>self</i>, <a href="qdragenterevent.html">QDragEnterEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#dragEnterEvent">QWidget.dragEnterEvent</a>().</p> <h3 class="fn"><a name="dragLeaveEvent" />QGraphicsView.dragLeaveEvent (<i>self</i>, <a href="qdragleaveevent.html">QDragLeaveEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#dragLeaveEvent">QWidget.dragLeaveEvent</a>().</p> <h3 class="fn"><a name="dragMode" /><a href="qgraphicsview.html#DragMode-enum">DragMode</a> QGraphicsView.dragMode (<i>self</i>)</h3><h3 class="fn"><a name="dragMoveEvent" />QGraphicsView.dragMoveEvent (<i>self</i>, <a href="qdragmoveevent.html">QDragMoveEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#dragMoveEvent">QWidget.dragMoveEvent</a>().</p> <h3 class="fn"><a name="drawBackground" />QGraphicsView.drawBackground (<i>self</i>, <a href="qpainter.html">QPainter</a> <i>painter</i>, <a href="qrectf.html">QRectF</a> <i>rect</i>)</h3><p>Draws the background of the scene using <i>painter</i>, before any items and the foreground are drawn. Reimplement this function to provide a custom background for this view.</p> <p>If all you want is to define a color, texture or gradient for the background, you can call <a href="qgraphicsview.html#backgroundBrush-prop">setBackgroundBrush</a>() instead.</p> <p>All painting is done in <i>scene</i> coordinates. <i>rect</i> is the exposed rectangle.</p> <p>The default implementation fills <i>rect</i> using the view's <a href="qgraphicsview.html#backgroundBrush-prop">backgroundBrush</a>. If no such brush is defined (the default), the scene's drawBackground() function is called instead.</p> <p><b>See also</b> <a href="qgraphicsview.html#drawForeground">drawForeground</a>() and <a href="qgraphicsscene.html#drawBackground">QGraphicsScene.drawBackground</a>().</p> <h3 class="fn"><a name="drawForeground" />QGraphicsView.drawForeground (<i>self</i>, <a href="qpainter.html">QPainter</a> <i>painter</i>, <a href="qrectf.html">QRectF</a> <i>rect</i>)</h3><p>Draws the foreground of the scene using <i>painter</i>, after the background and all items are drawn. Reimplement this function to provide a custom foreground for this view.</p> <p>If all you want is to define a color, texture or gradient for the foreground, you can call <a href="qgraphicsview.html#foregroundBrush-prop">setForegroundBrush</a>() instead.</p> <p>All painting is done in <i>scene</i> coordinates. <i>rect</i> is the exposed rectangle.</p> <p>The default implementation fills <i>rect</i> using the view's <a href="qgraphicsview.html#foregroundBrush-prop">foregroundBrush</a>. If no such brush is defined (the default), the scene's drawForeground() function is called instead.</p> <p><b>See also</b> <a href="qgraphicsview.html#drawBackground">drawBackground</a>() and <a href="qgraphicsscene.html#drawForeground">QGraphicsScene.drawForeground</a>().</p> <h3 class="fn"><a name="drawItems" />QGraphicsView.drawItems (<i>self</i>, <a href="qpainter.html">QPainter</a> <i>painter</i>, list-of-QGraphicsItem <i>items</i>, list-of-QStyleOptionGraphicsItem <i>options</i>)</h3><h3 class="fn"><a name="dropEvent" />QGraphicsView.dropEvent (<i>self</i>, <a href="qdropevent.html">QDropEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#dropEvent">QWidget.dropEvent</a>().</p> <h3 class="fn"><a name="ensureVisible" />QGraphicsView.ensureVisible (<i>self</i>, <a href="qrectf.html">QRectF</a> <i>rect</i>, int <i>xMargin</i> = 50, int <i>yMargin</i> = 50)</h3><p>Scrolls the contents of the viewport so that the scene rectangle <i>rect</i> is visible, with margins specified in pixels by <i>xmargin</i> and <i>ymargin</i>. 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.</p> <p><b>See also</b> <a href="qgraphicsview.html#centerOn">centerOn</a>().</p> <h3 class="fn"><a name="ensureVisible-2" />QGraphicsView.ensureVisible (<i>self</i>, <a href="qgraphicsitem.html">QGraphicsItem</a> <i>item</i>, int <i>xMargin</i> = 50, int <i>yMargin</i> = 50)</h3><p>This is an overloaded function.</p> <p>This function is provided for convenience. It's equivalent to calling ensureVisible(<a href="qrectf.html">QRectF</a>(<i>x</i>, <i>y</i>, <i>w</i>, <i>h</i>), <i>xmargin</i>, <i>ymargin</i>).</p> <h3 class="fn"><a name="ensureVisible-3" />QGraphicsView.ensureVisible (<i>self</i>, float <i>x</i>, float <i>y</i>, float <i>w</i>, float <i>h</i>, int <i>xMargin</i> = 50, int <i>yMargin</i> = 50)</h3><p>This is an overloaded function.</p> <p>Scrolls the contents of the viewport so that the center of item <i>item</i> is visible, with margins specified in pixels by <i>xmargin</i> and <i>ymargin</i>. 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.</p> <p><b>See also</b> <a href="qgraphicsview.html#centerOn">centerOn</a>().</p> <h3 class="fn"><a name="event" />bool QGraphicsView.event (<i>self</i>, <a href="qevent.html">QEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qobject.html#event">QObject.event</a>().</p> <h3 class="fn"><a name="fitInView" />QGraphicsView.fitInView (<i>self</i>, <a href="qrectf.html">QRectF</a> <i>rect</i>, <a href="qt.html#AspectRatioMode-enum">Qt.AspectRatioMode</a> <i>mode</i> = Qt.IgnoreAspectRatio)</h3><p>Scales the view matrix and scrolls the scroll bars to ensure that the scene rectangle <i>rect</i> fits inside the viewport. <i>rect</i> must be inside the scene rect; otherwise, fitInView() cannot guarantee that the whole rect is visible.</p> <p>This function keeps the view's rotation, translation, or shear. The view is scaled according to <i>aspectRatioMode</i>. <i>rect</i> will be centered in the view if it does not fit tightly.</p> <p>It's common to call fitInView() from inside a reimplementation of <a href="qgraphicsview.html#resizeEvent">resizeEvent</a>(), 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 <a href="qgraphicsview.html#resizeEvent">resizeEvent</a>() 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 <a href="qabstractscrollarea.html#horizontalScrollBarPolicy-prop">horizontalScrollBarPolicy</a>() and <a href="qabstractscrollarea.html#verticalScrollBarPolicy-prop">verticalScrollBarPolicy</a>()).</p> <p>If <i>rect</i> is empty, or if the viewport is too small, this function will do nothing.</p> <p><b>See also</b> <a href="qgraphicsview.html#setTransform">setTransform</a>(), <a href="qgraphicsview.html#ensureVisible">ensureVisible</a>(), and <a href="qgraphicsview.html#centerOn">centerOn</a>().</p> <h3 class="fn"><a name="fitInView-2" />QGraphicsView.fitInView (<i>self</i>, <a href="qgraphicsitem.html">QGraphicsItem</a> <i>item</i>, <a href="qt.html#AspectRatioMode-enum">Qt.AspectRatioMode</a> <i>mode</i> = Qt.IgnoreAspectRatio)</h3><p>This is an overloaded function.</p> <p>This convenience function is equivalent to calling fitInView(<a href="qrectf.html">QRectF</a>(<i>x</i>, <i>y</i>, <i>w</i>, <i>h</i>), <i>aspectRatioMode</i>).</p> <p><b>See also</b> <a href="qgraphicsview.html#ensureVisible">ensureVisible</a>() and <a href="qgraphicsview.html#centerOn">centerOn</a>().</p> <h3 class="fn"><a name="fitInView-3" />QGraphicsView.fitInView (<i>self</i>, float <i>x</i>, float <i>y</i>, float <i>w</i>, float <i>h</i>, <a href="qt.html#AspectRatioMode-enum">Qt.AspectRatioMode</a> <i>mode</i> = Qt.IgnoreAspectRatio)</h3><p>This is an overloaded function.</p> <p>Ensures that <i>item</i> fits tightly inside the view, scaling the view according to <i>aspectRatioMode</i>.</p> <p><b>See also</b> <a href="qgraphicsview.html#ensureVisible">ensureVisible</a>() and <a href="qgraphicsview.html#centerOn">centerOn</a>().</p> <h3 class="fn"><a name="focusInEvent" />QGraphicsView.focusInEvent (<i>self</i>, <a href="qfocusevent.html">QFocusEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#focusInEvent">QWidget.focusInEvent</a>().</p> <h3 class="fn"><a name="focusNextPrevChild" />bool QGraphicsView.focusNextPrevChild (<i>self</i>, bool <i>next</i>)</h3><p>Reimplemented from <a href="qwidget.html#focusNextPrevChild">QWidget.focusNextPrevChild</a>().</p> <h3 class="fn"><a name="focusOutEvent" />QGraphicsView.focusOutEvent (<i>self</i>, <a href="qfocusevent.html">QFocusEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#focusOutEvent">QWidget.focusOutEvent</a>().</p> <h3 class="fn"><a name="foregroundBrush" /><a href="qbrush.html">QBrush</a> QGraphicsView.foregroundBrush (<i>self</i>)</h3><h3 class="fn"><a name="inputMethodEvent" />QGraphicsView.inputMethodEvent (<i>self</i>, <a href="qinputmethodevent.html">QInputMethodEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#inputMethodEvent">QWidget.inputMethodEvent</a>().</p> <h3 class="fn"><a name="inputMethodQuery" />QVariant QGraphicsView.inputMethodQuery (<i>self</i>, <a href="qt.html#InputMethodQuery-enum">Qt.InputMethodQuery</a> <i>query</i>)</h3><p>Reimplemented from <a href="qwidget.html#inputMethodQuery">QWidget.inputMethodQuery</a>().</p> <h3 class="fn"><a name="invalidateScene" />QGraphicsView.invalidateScene (<i>self</i>, <a href="qrectf.html">QRectF</a> <i>rect</i> = QRectF(), <a href="qgraphicsscene-scenelayers.html">QGraphicsScene.SceneLayers</a> <i>layers</i> = QGraphicsScene.AllLayers)</h3><p>This method is also a Qt slot with the C++ signature <tt>void invalidateScene(const QRectF& = QRectF(),QGraphicsScene::SceneLayers = QGraphicsScene.AllLayers)</tt>.</p><p>Invalidates and schedules a redraw of <i>layers</i> inside <i>rect</i>. <i>rect</i> is in scene coordinates. Any cached content for <i>layers</i> inside <i>rect</i> is unconditionally invalidated and redrawn.</p> <p>You can call this function to notify <a href="qgraphicsview.html">QGraphicsView</a> 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 <a href="qgraphicsview.html">QGraphicsView</a> has enabled background caching.</p> <p>Note that <a href="qgraphicsview.html">QGraphicsView</a> currently supports background caching only (see <a href="qgraphicsview.html#CacheModeFlag-enum">QGraphicsView.CacheBackground</a>). This function is equivalent to calling <a href="qwidget.html#update">update</a>() if any layer but <a href="qgraphicsscene.html#SceneLayer-enum">QGraphicsScene.BackgroundLayer</a> is passed.</p> <p><b>See also</b> <a href="qgraphicsscene.html#invalidate">QGraphicsScene.invalidate</a>() and <a href="qwidget.html#update">update</a>().</p> <h3 class="fn"><a name="isInteractive" />bool QGraphicsView.isInteractive (<i>self</i>)</h3><h3 class="fn"><a name="isTransformed" />bool QGraphicsView.isTransformed (<i>self</i>)</h3><p>Returns true if the view is transformed (i.e., a non-identity transform has been assigned, or the scrollbars are adjusted).</p> <p>This function was introduced in Qt 4.6.</p> <p><b>See also</b> <a href="qgraphicsview.html#setTransform">setTransform</a>(), <a href="qabstractscrollarea.html#horizontalScrollBar">horizontalScrollBar</a>(), and <a href="qabstractscrollarea.html#verticalScrollBar">verticalScrollBar</a>().</p> <h3 class="fn"><a name="itemAt" /><a href="qgraphicsitem.html">QGraphicsItem</a> QGraphicsView.itemAt (<i>self</i>, <a href="qpoint.html">QPoint</a> <i>pos</i>)</h3><p>Returns the item at position <i>pos</i>, which is in viewport coordinates. If there are several items at this position, this function returns the topmost item.</p> <p>Example:</p> <pre class="cpp"> <span class="type">void</span> CustomView<span class="operator">.</span>mousePressEvent(<span class="type"><a href="qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>event) { <span class="keyword">if</span> (<span class="type"><a href="qgraphicsitem.html">QGraphicsItem</a></span> <span class="operator">*</span>item <span class="operator">=</span> itemAt(event<span class="operator">-</span><span class="operator">></span>pos())) { <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator"><</span><span class="operator"><</span> <span class="string">"You clicked on item"</span> <span class="operator"><</span><span class="operator"><</span> item; } <span class="keyword">else</span> { <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator"><</span><span class="operator"><</span> <span class="string">"You didn't click on an item."</span>; } } </pre> <p><b>See also</b> <a href="qgraphicsview.html#items">items</a>() and <a href="qgraphicsitem.html#sorting">Sorting</a>.</p> <h3 class="fn"><a name="itemAt-2" /><a href="qgraphicsitem.html">QGraphicsItem</a> QGraphicsView.itemAt (<i>self</i>, int <i>ax</i>, int <i>ay</i>)</h3><p>This is an overloaded function.</p> <p>This function is provided for convenience. It's equivalent to calling itemAt(<a href="qpoint.html">QPoint</a>(<i>x</i>, <i>y</i>)).</p> <h3 class="fn"><a name="items" />list-of-QGraphicsItem QGraphicsView.items (<i>self</i>)</h3><p>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).</p> <p><b>See also</b> <a href="qgraphicsscene.html#items">QGraphicsScene.items</a>() and <a href="qgraphicsitem.html#sorting">Sorting</a>.</p> <h3 class="fn"><a name="items-2" />list-of-QGraphicsItem QGraphicsView.items (<i>self</i>, <a href="qpoint.html">QPoint</a> <i>pos</i>)</h3><p>Returns a list of all the items at the position <i>pos</i> 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). <i>pos</i> is in viewport coordinates.</p> <p>This function is most commonly called from within mouse event handlers in a subclass in <a href="qgraphicsview.html">QGraphicsView</a>. <i>pos</i> is in untransformed viewport coordinates, just like <a href="qmouseevent.html#pos">QMouseEvent.pos</a>().</p> <pre class="cpp"> <span class="type">void</span> CustomView<span class="operator">.</span>mousePressEvent(<span class="type"><a href="qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>event) { <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator"><</span><span class="operator"><</span> <span class="string">"There are"</span> <span class="operator"><</span><span class="operator"><</span> items(event<span class="operator">-</span><span class="operator">></span>pos())<span class="operator">.</span>size() <span class="operator"><</span><span class="operator"><</span> <span class="string">"items at position"</span> <span class="operator"><</span><span class="operator"><</span> mapToScene(event<span class="operator">-</span><span class="operator">></span>pos()); } </pre> <p><b>See also</b> <a href="qgraphicsscene.html#items">QGraphicsScene.items</a>() and <a href="qgraphicsitem.html#sorting">Sorting</a>.</p> <h3 class="fn"><a name="items-3" />list-of-QGraphicsItem QGraphicsView.items (<i>self</i>, int <i>ax</i>, int <i>ay</i>)</h3><p>This function is provided for convenience. It's equivalent to calling items(<a href="qpoint.html">QPoint</a>(<i>x</i>, <i>y</i>)).</p> <h3 class="fn"><a name="items-4" />list-of-QGraphicsItem QGraphicsView.items (<i>self</i>, int <i>x</i>, int <i>y</i>, int <i>w</i>, int <i>h</i>, <a href="qt.html#ItemSelectionMode-enum">Qt.ItemSelectionMode</a> <i>mode</i> = Qt.IntersectsItemShape)</h3><p>This convenience function is equivalent to calling items(<a href="qrectf.html">QRectF</a>(<i>x</i>, <i>y</i>, <i>w</i>, <i>h</i>), <i>mode</i>).</p> <p>This function was introduced in Qt 4.3.</p> <h3 class="fn"><a name="items-5" />list-of-QGraphicsItem QGraphicsView.items (<i>self</i>, <a href="qrect.html">QRect</a> <i>rect</i>, <a href="qt.html#ItemSelectionMode-enum">Qt.ItemSelectionMode</a> <i>mode</i> = Qt.IntersectsItemShape)</h3><p>This is an overloaded function.</p> <p>Returns a list of all the items that, depending on <i>mode</i>, are either contained by or intersect with <i>rect</i>. <i>rect</i> is in viewport coordinates.</p> <p>The default value for <i>mode</i> is <a href="qt.html#ItemSelectionMode-enum">Qt.IntersectsItemShape</a>; all items whose exact shape intersects with or is contained by <i>rect</i> are returned.</p> <p>The items are sorted in descending stacking order (i.e., the first item in the returned list is the uppermost item).</p> <p><b>See also</b> <a href="qgraphicsview.html#itemAt">itemAt</a>(), <a href="qgraphicsview.html#items">items</a>(), <a href="qgraphicsview.html#mapToScene">mapToScene</a>(), and <a href="qgraphicsitem.html#sorting">Sorting</a>.</p> <h3 class="fn"><a name="items-6" />list-of-QGraphicsItem QGraphicsView.items (<i>self</i>, <a href="qpolygon.html">QPolygon</a> <i>polygon</i>, <a href="qt.html#ItemSelectionMode-enum">Qt.ItemSelectionMode</a> <i>mode</i> = Qt.IntersectsItemShape)</h3><p>This is an overloaded function.</p> <p>Returns a list of all the items that, depending on <i>mode</i>, are either contained by or intersect with <i>polygon</i>. <i>polygon</i> is in viewport coordinates.</p> <p>The default value for <i>mode</i> is <a href="qt.html#ItemSelectionMode-enum">Qt.IntersectsItemShape</a>; all items whose exact shape intersects with or is contained by <i>polygon</i> are returned.</p> <p>The items are sorted by descending stacking order (i.e., the first item in the returned list is the uppermost item).</p> <p><b>See also</b> <a href="qgraphicsview.html#itemAt">itemAt</a>(), <a href="qgraphicsview.html#items">items</a>(), <a href="qgraphicsview.html#mapToScene">mapToScene</a>(), and <a href="qgraphicsitem.html#sorting">Sorting</a>.</p> <h3 class="fn"><a name="items-7" />list-of-QGraphicsItem QGraphicsView.items (<i>self</i>, <a href="qpainterpath.html">QPainterPath</a> <i>path</i>, <a href="qt.html#ItemSelectionMode-enum">Qt.ItemSelectionMode</a> <i>mode</i> = Qt.IntersectsItemShape)</h3><p>This is an overloaded function.</p> <p>Returns a list of all the items that, depending on <i>mode</i>, are either contained by or intersect with <i>path</i>. <i>path</i> is in viewport coordinates.</p> <p>The default value for <i>mode</i> is <a href="qt.html#ItemSelectionMode-enum">Qt.IntersectsItemShape</a>; all items whose exact shape intersects with or is contained by <i>path</i> are returned.</p> <p><b>See also</b> <a href="qgraphicsview.html#itemAt">itemAt</a>(), <a href="qgraphicsview.html#items">items</a>(), <a href="qgraphicsview.html#mapToScene">mapToScene</a>(), and <a href="qgraphicsitem.html#sorting">Sorting</a>.</p> <h3 class="fn"><a name="keyPressEvent" />QGraphicsView.keyPressEvent (<i>self</i>, <a href="qkeyevent.html">QKeyEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#keyPressEvent">QWidget.keyPressEvent</a>().</p> <h3 class="fn"><a name="keyReleaseEvent" />QGraphicsView.keyReleaseEvent (<i>self</i>, <a href="qkeyevent.html">QKeyEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#keyReleaseEvent">QWidget.keyReleaseEvent</a>().</p> <h3 class="fn"><a name="mapFromScene" /><a href="qpoint.html">QPoint</a> QGraphicsView.mapFromScene (<i>self</i>, <a href="qpointf.html">QPointF</a> <i>point</i>)</h3><p>Returns the scene coordinate <i>point</i> to viewport coordinates.</p> <p><b>See also</b> <a href="qgraphicsview.html#mapToScene">mapToScene</a>().</p> <h3 class="fn"><a name="mapFromScene-2" /><a href="qpolygon.html">QPolygon</a> QGraphicsView.mapFromScene (<i>self</i>, <a href="qrectf.html">QRectF</a> <i>rect</i>)</h3><p>Returns the scene rectangle <i>rect</i> to a viewport coordinate polygon.</p> <p><b>See also</b> <a href="qgraphicsview.html#mapToScene">mapToScene</a>().</p> <h3 class="fn"><a name="mapFromScene-3" /><a href="qpolygon.html">QPolygon</a> QGraphicsView.mapFromScene (<i>self</i>, <a href="qpolygonf.html">QPolygonF</a> <i>polygon</i>)</h3><p>Returns the scene coordinate polygon <i>polygon</i> to a viewport coordinate polygon.</p> <p><b>See also</b> <a href="qgraphicsview.html#mapToScene">mapToScene</a>().</p> <h3 class="fn"><a name="mapFromScene-4" /><a href="qpainterpath.html">QPainterPath</a> QGraphicsView.mapFromScene (<i>self</i>, <a href="qpainterpath.html">QPainterPath</a> <i>path</i>)</h3><p>Returns the scene coordinate painter path <i>path</i> to a viewport coordinate painter path.</p> <p><b>See also</b> <a href="qgraphicsview.html#mapToScene">mapToScene</a>().</p> <h3 class="fn"><a name="mapFromScene-5" /><a href="qpoint.html">QPoint</a> QGraphicsView.mapFromScene (<i>self</i>, float <i>ax</i>, float <i>ay</i>)</h3><p>This function is provided for convenience. It's equivalent to calling mapFromScene(<a href="qpointf.html">QPointF</a>(<i>x</i>, <i>y</i>)).</p> <h3 class="fn"><a name="mapFromScene-6" /><a href="qpolygon.html">QPolygon</a> QGraphicsView.mapFromScene (<i>self</i>, float <i>ax</i>, float <i>ay</i>, float <i>w</i>, float <i>h</i>)</h3><p>This function is provided for convenience. It's equivalent to calling mapFromScene(<a href="qrectf.html">QRectF</a>(<i>x</i>, <i>y</i>, <i>w</i>, <i>h</i>)).</p> <h3 class="fn"><a name="mapToScene" /><a href="qpointf.html">QPointF</a> QGraphicsView.mapToScene (<i>self</i>, <a href="qpoint.html">QPoint</a> <i>point</i>)</h3><p>Returns the viewport coordinate <i>point</i> mapped to scene coordinates.</p> <p>Note: It can be useful to map the whole rectangle covered by the pixel at <i>point</i> instead of the point itself. To do this, you can call mapToScene(<a href="qrect.html">QRect</a>(<i>point</i>, <a href="qsize.html">QSize</a>(2, 2))).</p> <p><b>See also</b> <a href="qgraphicsview.html#mapFromScene">mapFromScene</a>().</p> <h3 class="fn"><a name="mapToScene-2" /><a href="qpolygonf.html">QPolygonF</a> QGraphicsView.mapToScene (<i>self</i>, <a href="qrect.html">QRect</a> <i>rect</i>)</h3><p>Returns the viewport rectangle <i>rect</i> mapped to a scene coordinate polygon.</p> <p><b>See also</b> <a href="qgraphicsview.html#mapFromScene">mapFromScene</a>().</p> <h3 class="fn"><a name="mapToScene-3" /><a href="qpolygonf.html">QPolygonF</a> QGraphicsView.mapToScene (<i>self</i>, <a href="qpolygon.html">QPolygon</a> <i>polygon</i>)</h3><p>Returns the viewport polygon <i>polygon</i> mapped to a scene coordinate polygon.</p> <p><b>See also</b> <a href="qgraphicsview.html#mapFromScene">mapFromScene</a>().</p> <h3 class="fn"><a name="mapToScene-4" /><a href="qpainterpath.html">QPainterPath</a> QGraphicsView.mapToScene (<i>self</i>, <a href="qpainterpath.html">QPainterPath</a> <i>path</i>)</h3><p>Returns the viewport painter path <i>path</i> mapped to a scene coordinate painter path.</p> <p><b>See also</b> <a href="qgraphicsview.html#mapFromScene">mapFromScene</a>().</p> <h3 class="fn"><a name="mapToScene-5" /><a href="qpointf.html">QPointF</a> QGraphicsView.mapToScene (<i>self</i>, int <i>ax</i>, int <i>ay</i>)</h3><p>This function is provided for convenience. It's equivalent to calling mapToScene(<a href="qpoint.html">QPoint</a>(<i>x</i>, <i>y</i>)).</p> <h3 class="fn"><a name="mapToScene-6" /><a href="qpolygonf.html">QPolygonF</a> QGraphicsView.mapToScene (<i>self</i>, int <i>ax</i>, int <i>ay</i>, int <i>w</i>, int <i>h</i>)</h3><p>This function is provided for convenience. It's equivalent to calling mapToScene(<a href="qrect.html">QRect</a>(<i>x</i>, <i>y</i>, <i>w</i>, <i>h</i>)).</p> <h3 class="fn"><a name="matrix" /><a href="qmatrix.html">QMatrix</a> QGraphicsView.matrix (<i>self</i>)</h3><p>Returns the current transformation matrix for the view. If no current transformation is set, the identity matrix is returned.</p> <p><b>See also</b> <a href="qgraphicsview.html#setMatrix">setMatrix</a>(), <a href="qgraphicsview.html#transform">transform</a>(), <a href="qgraphicsview.html#rotate">rotate</a>(), <a href="qgraphicsview.html#scale">scale</a>(), <a href="qgraphicsview.html#shear">shear</a>(), and <a href="qgraphicsview.html#translate">translate</a>().</p> <h3 class="fn"><a name="mouseDoubleClickEvent" />QGraphicsView.mouseDoubleClickEvent (<i>self</i>, <a href="qmouseevent.html">QMouseEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#mouseDoubleClickEvent">QWidget.mouseDoubleClickEvent</a>().</p> <h3 class="fn"><a name="mouseMoveEvent" />QGraphicsView.mouseMoveEvent (<i>self</i>, <a href="qmouseevent.html">QMouseEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#mouseMoveEvent">QWidget.mouseMoveEvent</a>().</p> <h3 class="fn"><a name="mousePressEvent" />QGraphicsView.mousePressEvent (<i>self</i>, <a href="qmouseevent.html">QMouseEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#mousePressEvent">QWidget.mousePressEvent</a>().</p> <h3 class="fn"><a name="mouseReleaseEvent" />QGraphicsView.mouseReleaseEvent (<i>self</i>, <a href="qmouseevent.html">QMouseEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#mouseReleaseEvent">QWidget.mouseReleaseEvent</a>().</p> <h3 class="fn"><a name="optimizationFlags" /><a href="qgraphicsview-optimizationflags.html">OptimizationFlags</a> QGraphicsView.optimizationFlags (<i>self</i>)</h3><h3 class="fn"><a name="paintEvent" />QGraphicsView.paintEvent (<i>self</i>, <a href="qpaintevent.html">QPaintEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#paintEvent">QWidget.paintEvent</a>().</p> <h3 class="fn"><a name="render" />QGraphicsView.render (<i>self</i>, <a href="qpainter.html">QPainter</a> <i>painter</i>, <a href="qrectf.html">QRectF</a> <i>target</i> = QRectF(), <a href="qrect.html">QRect</a> <i>source</i> = QRect(), <a href="qt.html#AspectRatioMode-enum">Qt.AspectRatioMode</a> <i>mode</i> = Qt.KeepAspectRatio)</h3><p>Renders the <i>source</i> rect, which is in view coordinates, from the scene into <i>target</i>, which is in paint device coordinates, using <i>painter</i>. This function is useful for capturing the contents of the view onto a paint device, such as a <a href="qimage.html">QImage</a> (e.g., to take a screenshot), or for printing to <a href="qprinter.html">QPrinter</a>. For example:</p> <pre class="cpp"> <span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span> scene; scene<span class="operator">.</span>addItem(<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span> view(<span class="operator">&</span>scene); view<span class="operator">.</span>show(); <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> <span class="type"><a href="qprinter.html">QPrinter</a></span> printer(<span class="type"><a href="qprinter.html">QPrinter</a></span><span class="operator">.</span>HighResolution); printer<span class="operator">.</span>setPageSize(<span class="type"><a href="qprinter.html">QPrinter</a></span><span class="operator">.</span>A4); <span class="type"><a href="qpainter.html">QPainter</a></span> painter(<span class="operator">&</span>printer); <span class="comment">// print, fitting the viewport contents into a full page</span> view<span class="operator">.</span>render(<span class="operator">&</span>painter); <span class="comment">// print the upper half of the viewport into the lower.</span> <span class="comment">// half of the page.</span> <span class="type"><a href="qrect.html">QRect</a></span> viewport <span class="operator">=</span> view<span class="operator">.</span>viewport()<span class="operator">-</span><span class="operator">></span>rect(); view<span class="operator">.</span>render(<span class="operator">&</span>painter<span class="operator">,</span> <span class="type"><a href="qrectf.html">QRectF</a></span>(<span class="number">0</span><span class="operator">,</span> printer<span class="operator">.</span>height() <span class="operator">/</span> <span class="number">2</span><span class="operator">,</span> printer<span class="operator">.</span>width()<span class="operator">,</span> printer<span class="operator">.</span>height() <span class="operator">/</span> <span class="number">2</span>)<span class="operator">,</span> viewport<span class="operator">.</span>adjusted(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="operator">-</span>viewport<span class="operator">.</span>height() <span class="operator">/</span> <span class="number">2</span>)); </pre> <p>If <i>source</i> is a null rect, this function will use <a href="qabstractscrollarea.html#viewport">viewport</a>()-><a href="qwidget.html#rect-prop">rect</a>() to determine what to draw. If <i>target</i> is a null rect, the full dimensions of <i>painter</i>'s paint device (e.g., for a <a href="qprinter.html">QPrinter</a>, the page size) will be used.</p> <p>The source rect contents will be transformed according to <i>aspectRatioMode</i> to fit into the target rect. By default, the aspect ratio is kept, and <i>source</i> is scaled to fit in <i>target</i>.</p> <p><b>See also</b> <a href="qgraphicsscene.html#render">QGraphicsScene.render</a>().</p> <h3 class="fn"><a name="renderHints" /><a href="qpainter-renderhints.html">QPainter.RenderHints</a> QGraphicsView.renderHints (<i>self</i>)</h3><h3 class="fn"><a name="resetCachedContent" />QGraphicsView.resetCachedContent (<i>self</i>)</h3><p>Resets any cached content. Calling this function will clear <a href="qgraphicsview.html">QGraphicsView</a>'s cache. If the current cache mode is <a href="qgraphicsview.html#CacheModeFlag-enum">CacheNone</a>, this function does nothing.</p> <p>This function is called automatically for you when the <a href="qgraphicsview.html#backgroundBrush-prop">backgroundBrush</a> or <a href="qgraphicsscene.html#backgroundBrush-prop">QGraphicsScene.backgroundBrush</a> properties change; you only need to call this function if you have reimplemented <a href="qgraphicsscene.html#drawBackground">QGraphicsScene.drawBackground</a>() or <a href="qgraphicsview.html#drawBackground">QGraphicsView.drawBackground</a>() to draw a custom background, and need to trigger a full redraw.</p> <p><b>See also</b> <a href="qgraphicsview.html#cacheMode-prop">cacheMode</a>().</p> <h3 class="fn"><a name="resetMatrix" />QGraphicsView.resetMatrix (<i>self</i>)</h3><p>Resets the view transformation matrix to the identity matrix.</p> <p><b>See also</b> <a href="qgraphicsview.html#resetTransform">resetTransform</a>().</p> <h3 class="fn"><a name="resetTransform" />QGraphicsView.resetTransform (<i>self</i>)</h3><p>Resets the view transformation to the identity matrix.</p> <p><b>See also</b> <a href="qgraphicsview.html#transform">transform</a>() and <a href="qgraphicsview.html#setTransform">setTransform</a>().</p> <h3 class="fn"><a name="resizeAnchor" /><a href="qgraphicsview.html#ViewportAnchor-enum">ViewportAnchor</a> QGraphicsView.resizeAnchor (<i>self</i>)</h3><h3 class="fn"><a name="resizeEvent" />QGraphicsView.resizeEvent (<i>self</i>, <a href="qresizeevent.html">QResizeEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#resizeEvent">QWidget.resizeEvent</a>().</p> <h3 class="fn"><a name="rotate" />QGraphicsView.rotate (<i>self</i>, float <i>angle</i>)</h3><p>Rotates the current view transformation <i>angle</i> degrees clockwise.</p> <p><b>See also</b> <a href="qgraphicsview.html#setTransform">setTransform</a>(), <a href="qgraphicsview.html#transform">transform</a>(), <a href="qgraphicsview.html#scale">scale</a>(), <a href="qgraphicsview.html#shear">shear</a>(), and <a href="qgraphicsview.html#translate">translate</a>().</p> <h3 class="fn"><a name="rubberBandSelectionMode" /><a href="qt.html#ItemSelectionMode-enum">Qt.ItemSelectionMode</a> QGraphicsView.rubberBandSelectionMode (<i>self</i>)</h3><h3 class="fn"><a name="scale" />QGraphicsView.scale (<i>self</i>, float <i>sx</i>, float <i>sy</i>)</h3><p>Scales the current view transformation by (<i>sx</i>, <i>sy</i>).</p> <p><b>See also</b> <a href="qgraphicsview.html#setTransform">setTransform</a>(), <a href="qgraphicsview.html#transform">transform</a>(), <a href="qgraphicsview.html#rotate">rotate</a>(), <a href="qgraphicsview.html#shear">shear</a>(), and <a href="qgraphicsview.html#translate">translate</a>().</p> <h3 class="fn"><a name="scene" /><a href="qgraphicsscene.html">QGraphicsScene</a> QGraphicsView.scene (<i>self</i>)</h3><p>Returns a pointer to the scene that is currently visualized in the view. If no scene is currently visualized, 0 is returned.</p> <p><b>See also</b> <a href="qgraphicsview.html#setScene">setScene</a>().</p> <h3 class="fn"><a name="sceneRect" /><a href="qrectf.html">QRectF</a> QGraphicsView.sceneRect (<i>self</i>)</h3><h3 class="fn"><a name="scrollContentsBy" />QGraphicsView.scrollContentsBy (<i>self</i>, int <i>dx</i>, int <i>dy</i>)</h3><p>Reimplemented from <a href="qabstractscrollarea.html#scrollContentsBy">QAbstractScrollArea.scrollContentsBy</a>().</p> <h3 class="fn"><a name="setAlignment" />QGraphicsView.setAlignment (<i>self</i>, <a href="qt-alignment.html">Qt.Alignment</a> <i>alignment</i>)</h3><h3 class="fn"><a name="setBackgroundBrush" />QGraphicsView.setBackgroundBrush (<i>self</i>, <a href="qbrush.html">QBrush</a> <i>brush</i>)</h3><h3 class="fn"><a name="setCacheMode" />QGraphicsView.setCacheMode (<i>self</i>, <a href="qgraphicsview-cachemode.html">CacheMode</a> <i>mode</i>)</h3><h3 class="fn"><a name="setDragMode" />QGraphicsView.setDragMode (<i>self</i>, <a href="qgraphicsview.html#DragMode-enum">DragMode</a> <i>mode</i>)</h3><h3 class="fn"><a name="setForegroundBrush" />QGraphicsView.setForegroundBrush (<i>self</i>, <a href="qbrush.html">QBrush</a> <i>brush</i>)</h3><h3 class="fn"><a name="setInteractive" />QGraphicsView.setInteractive (<i>self</i>, bool <i>allowed</i>)</h3><h3 class="fn"><a name="setMatrix" />QGraphicsView.setMatrix (<i>self</i>, <a href="qmatrix.html">QMatrix</a> <i>matrix</i>, bool <i>combine</i> = False)</h3><p>Sets the view's current transformation matrix to <i>matrix</i>.</p> <p>If <i>combine</i> is true, then <i>matrix</i> is combined with the current matrix; otherwise, <i>matrix</i> <i>replaces</i> the current matrix. <i>combine</i> is false by default.</p> <p>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).</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span> scene; scene<span class="operator">.</span>addText(<span class="string">"GraphicsView rotated clockwise"</span>); <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span> view(<span class="operator">&</span>scene); view<span class="operator">.</span><a href="qgraphicsview.html#rotate">rotate</a>(<span class="number">90</span>); <span class="comment">// the text is rendered with a 90 degree clockwise rotation</span> view<span class="operator">.</span><a href="qwidget.html#show">show</a>(); </pre> <p>To simplify interation with items using a transformed view, <a href="qgraphicsview.html">QGraphicsView</a> provides mapTo... and mapFrom... functions that can translate between scene and view coordinates. For example, you can call <a href="qgraphicsview.html#mapToScene">mapToScene</a>() to map a view coordinate to a floating point scene coordinate, or <a href="qgraphicsview.html#mapFromScene">mapFromScene</a>() to map from floating point scene coordinates to view coordinates.</p> <p><b>See also</b> <a href="qgraphicsview.html#matrix">matrix</a>(), <a href="qgraphicsview.html#setTransform">setTransform</a>(), <a href="qgraphicsview.html#rotate">rotate</a>(), <a href="qgraphicsview.html#scale">scale</a>(), <a href="qgraphicsview.html#shear">shear</a>(), and <a href="qgraphicsview.html#translate">translate</a>().</p> <h3 class="fn"><a name="setOptimizationFlag" />QGraphicsView.setOptimizationFlag (<i>self</i>, <a href="qgraphicsview.html#OptimizationFlag-enum">OptimizationFlag</a> <i>flag</i>, bool <i>enabled</i> = True)</h3><p>Enables <i>flag</i> if <i>enabled</i> is true; otherwise disables <i>flag</i>.</p> <p><b>See also</b> <a href="qgraphicsview.html#optimizationFlags-prop">optimizationFlags</a>.</p> <h3 class="fn"><a name="setOptimizationFlags" />QGraphicsView.setOptimizationFlags (<i>self</i>, <a href="qgraphicsview-optimizationflags.html">OptimizationFlags</a> <i>flags</i>)</h3><h3 class="fn"><a name="setRenderHint" />QGraphicsView.setRenderHint (<i>self</i>, <a href="qpainter.html#RenderHint-enum">QPainter.RenderHint</a> <i>hint</i>, bool <i>on</i> = True)</h3><p>If <i>enabled</i> is true, the render hint <i>hint</i> is enabled; otherwise it is disabled.</p> <p><b>See also</b> <a href="qgraphicsview.html#renderHints-prop">renderHints</a>.</p> <h3 class="fn"><a name="setRenderHints" />QGraphicsView.setRenderHints (<i>self</i>, <a href="qpainter-renderhints.html">QPainter.RenderHints</a> <i>hints</i>)</h3><h3 class="fn"><a name="setResizeAnchor" />QGraphicsView.setResizeAnchor (<i>self</i>, <a href="qgraphicsview.html#ViewportAnchor-enum">ViewportAnchor</a> <i>anchor</i>)</h3><h3 class="fn"><a name="setRubberBandSelectionMode" />QGraphicsView.setRubberBandSelectionMode (<i>self</i>, <a href="qt.html#ItemSelectionMode-enum">Qt.ItemSelectionMode</a> <i>mode</i>)</h3><h3 class="fn"><a name="setScene" />QGraphicsView.setScene (<i>self</i>, <a href="qgraphicsscene.html">QGraphicsScene</a> <i>scene</i>)</h3><p>Sets the current scene to <i>scene</i>. If <i>scene</i> is already being viewed, this function does nothing.</p> <p>When a scene is set on a view, the <a href="qgraphicsscene.html#changed">QGraphicsScene.changed</a>() signal is automatically connected to this view's <a href="qgraphicsview.html#updateScene">updateScene</a>() slot, and the view's scroll bars are adjusted to fit the size of the scene.</p> <p><b>See also</b> <a href="qgraphicsview.html#scene">scene</a>().</p> <h3 class="fn"><a name="setSceneRect" />QGraphicsView.setSceneRect (<i>self</i>, <a href="qrectf.html">QRectF</a> <i>rect</i>)</h3><h3 class="fn"><a name="setSceneRect-2" />QGraphicsView.setSceneRect (<i>self</i>, float <i>ax</i>, float <i>ay</i>, float <i>aw</i>, float <i>ah</i>)</h3><h3 class="fn"><a name="setTransform" />QGraphicsView.setTransform (<i>self</i>, <a href="qtransform.html">QTransform</a> <i>matrix</i>, bool <i>combine</i> = False)</h3><p>Sets the view's current transformation matrix to <i>matrix</i>.</p> <p>If <i>combine</i> is true, then <i>matrix</i> is combined with the current matrix; otherwise, <i>matrix</i> <i>replaces</i> the current matrix. <i>combine</i> is false by default.</p> <p>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).</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span> scene; scene<span class="operator">.</span>addText(<span class="string">"GraphicsView rotated clockwise"</span>); <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span> view(<span class="operator">&</span>scene); view<span class="operator">.</span>rotate(<span class="number">90</span>); <span class="comment">// the text is rendered with a 90 degree clockwise rotation</span> view<span class="operator">.</span>show(); </pre> <p>To simplify interation with items using a transformed view, <a href="qgraphicsview.html">QGraphicsView</a> provides mapTo... and mapFrom... functions that can translate between scene and view coordinates. For example, you can call <a href="qgraphicsview.html#mapToScene">mapToScene</a>() to map a view coordiate to a floating point scene coordinate, or <a href="qgraphicsview.html#mapFromScene">mapFromScene</a>() to map from floating point scene coordinates to view coordinates.</p> <p><b>See also</b> <a href="qgraphicsview.html#transform">transform</a>(), <a href="qgraphicsview.html#rotate">rotate</a>(), <a href="qgraphicsview.html#scale">scale</a>(), <a href="qgraphicsview.html#shear">shear</a>(), and <a href="qgraphicsview.html#translate">translate</a>().</p> <h3 class="fn"><a name="setTransformationAnchor" />QGraphicsView.setTransformationAnchor (<i>self</i>, <a href="qgraphicsview.html#ViewportAnchor-enum">ViewportAnchor</a> <i>anchor</i>)</h3><h3 class="fn"><a name="setupViewport" />QGraphicsView.setupViewport (<i>self</i>, <a href="qwidget.html">QWidget</a> <i>widget</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void setupViewport(QWidget *)</tt>.</p><p>This slot is called by <a href="qabstractscrollarea.html">QAbstractScrollArea</a> after <a href="qabstractscrollarea.html#setViewport">setViewport</a>() has been called. Reimplement this function in a subclass of <a href="qgraphicsview.html">QGraphicsView</a> to initialize the new viewport <i>widget</i> before it is used.</p> <p><b>See also</b> <a href="qabstractscrollarea.html#setViewport">setViewport</a>().</p> <h3 class="fn"><a name="setViewportUpdateMode" />QGraphicsView.setViewportUpdateMode (<i>self</i>, <a href="qgraphicsview.html#ViewportUpdateMode-enum">ViewportUpdateMode</a> <i>mode</i>)</h3><h3 class="fn"><a name="shear" />QGraphicsView.shear (<i>self</i>, float <i>sh</i>, float <i>sv</i>)</h3><p>Shears the current view transformation by (<i>sh</i>, <i>sv</i>).</p> <p><b>See also</b> <a href="qgraphicsview.html#setTransform">setTransform</a>(), <a href="qgraphicsview.html#transform">transform</a>(), <a href="qgraphicsview.html#rotate">rotate</a>(), <a href="qgraphicsview.html#scale">scale</a>(), and <a href="qgraphicsview.html#translate">translate</a>().</p> <h3 class="fn"><a name="showEvent" />QGraphicsView.showEvent (<i>self</i>, <a href="qshowevent.html">QShowEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#showEvent">QWidget.showEvent</a>().</p> <h3 class="fn"><a name="sizeHint" /><a href="qsize.html">QSize</a> QGraphicsView.sizeHint (<i>self</i>)</h3><p>Reimplemented from <a href="qwidget.html#sizeHint-prop">QWidget.sizeHint</a>().</p> <h3 class="fn"><a name="transform" /><a href="qtransform.html">QTransform</a> QGraphicsView.transform (<i>self</i>)</h3><p>Returns the current transformation matrix for the view. If no current transformation is set, the identity matrix is returned.</p> <p><b>See also</b> <a href="qgraphicsview.html#setTransform">setTransform</a>(), <a href="qgraphicsview.html#rotate">rotate</a>(), <a href="qgraphicsview.html#scale">scale</a>(), <a href="qgraphicsview.html#shear">shear</a>(), and <a href="qgraphicsview.html#translate">translate</a>().</p> <h3 class="fn"><a name="transformationAnchor" /><a href="qgraphicsview.html#ViewportAnchor-enum">ViewportAnchor</a> QGraphicsView.transformationAnchor (<i>self</i>)</h3><h3 class="fn"><a name="translate" />QGraphicsView.translate (<i>self</i>, float <i>dx</i>, float <i>dy</i>)</h3><p>Translates the current view transformation by (<i>dx</i>, <i>dy</i>).</p> <p><b>See also</b> <a href="qgraphicsview.html#setTransform">setTransform</a>(), <a href="qgraphicsview.html#transform">transform</a>(), <a href="qgraphicsview.html#rotate">rotate</a>(), and <a href="qgraphicsview.html#shear">shear</a>().</p> <h3 class="fn"><a name="updateScene" />QGraphicsView.updateScene (<i>self</i>, list-of-QRectF <i>rects</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void updateScene(const QList<QRectF>&)</tt>.</p><p>Schedules an update of the scene rectangles <i>rects</i>.</p> <p><b>See also</b> <a href="qgraphicsscene.html#changed">QGraphicsScene.changed</a>().</p> <h3 class="fn"><a name="updateSceneRect" />QGraphicsView.updateSceneRect (<i>self</i>, <a href="qrectf.html">QRectF</a> <i>rect</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void updateSceneRect(const QRectF&)</tt>.</p><p>Notifies <a href="qgraphicsview.html">QGraphicsView</a> that the scene's scene rect has changed. <i>rect</i> is the new scene rect. If the view already has an explicitly set scene rect, this function does nothing.</p> <p><b>See also</b> <a href="qgraphicsview.html#sceneRect-prop">sceneRect</a> and <a href="qgraphicsscene.html#sceneRectChanged">QGraphicsScene.sceneRectChanged</a>().</p> <h3 class="fn"><a name="viewportEvent" />bool QGraphicsView.viewportEvent (<i>self</i>, <a href="qevent.html">QEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qabstractscrollarea.html#viewportEvent">QAbstractScrollArea.viewportEvent</a>().</p> <h3 class="fn"><a name="viewportTransform" /><a href="qtransform.html">QTransform</a> QGraphicsView.viewportTransform (<i>self</i>)</h3><p>Returns a matrix that maps viewport coordinates to scene coordinates.</p> <p><b>See also</b> <a href="qgraphicsview.html#mapToScene">mapToScene</a>() and <a href="qgraphicsview.html#mapFromScene">mapFromScene</a>().</p> <h3 class="fn"><a name="viewportUpdateMode" /><a href="qgraphicsview.html#ViewportUpdateMode-enum">ViewportUpdateMode</a> QGraphicsView.viewportUpdateMode (<i>self</i>)</h3><h3 class="fn"><a name="wheelEvent" />QGraphicsView.wheelEvent (<i>self</i>, <a href="qwheelevent.html">QWheelEvent</a> <i>event</i>)</h3><p>Reimplemented from <a href="qwidget.html#wheelEvent">QWidget.wheelEvent</a>().</p> <address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>