QGraphicsView¶
The
QGraphicsView
class provides a widget for displaying the contents of aQGraphicsScene
. More…
Inherited by: QtCharts.QChartView
Synopsis¶
Functions¶
def
alignment
()def
backgroundBrush
()def
cacheMode
()def
centerOn
(item)def
centerOn
(pos)def
centerOn
(x, y)def
dragMode
()def
ensureVisible
(item[, xmargin=50[, ymargin=50]])def
ensureVisible
(rect[, xmargin=50[, ymargin=50]])def
ensureVisible
(x, y, w, h[, xmargin=50[, ymargin=50]])def
fitInView
(item[, aspectRadioMode=Qt.IgnoreAspectRatio])def
fitInView
(rect[, aspectRadioMode=Qt.IgnoreAspectRatio])def
fitInView
(x, y, w, h[, aspectRadioMode=Qt.IgnoreAspectRatio])def
foregroundBrush
()def
isInteractive
()def
isTransformed
()def
itemAt
(pos)def
itemAt
(x, y)def
items
()def
items
(path[, mode=Qt.IntersectsItemShape])def
items
(polygon[, mode=Qt.IntersectsItemShape])def
items
(pos)def
items
(rect[, mode=Qt.IntersectsItemShape])def
items
(x, y)def
items
(x, y, w, h[, mode=Qt.IntersectsItemShape])def
mapFromScene
(path)def
mapFromScene
(point)def
mapFromScene
(polygon)def
mapFromScene
(rect)def
mapFromScene
(x, y)def
mapFromScene
(x, y, w, h)def
mapToScene
(path)def
mapToScene
(point)def
mapToScene
(polygon)def
mapToScene
(rect)def
mapToScene
(x, y)def
mapToScene
(x, y, w, h)def
matrix
()def
optimizationFlags
()def
render
(painter[, target=QRectF()[, source=QRect()[, aspectRatioMode=Qt.KeepAspectRatio]]])def
renderHints
()def
resetCachedContent
()def
resetMatrix
()def
resetTransform
()def
resizeAnchor
()def
rotate
(angle)def
rubberBandRect
()def
rubberBandSelectionMode
()def
scale
(sx, sy)def
scene
()def
sceneRect
()def
setAlignment
(alignment)def
setBackgroundBrush
(brush)def
setCacheMode
(mode)def
setDragMode
(mode)def
setForegroundBrush
(brush)def
setInteractive
(allowed)def
setMatrix
(matrix[, combine=false])def
setOptimizationFlag
(flag[, enabled=true])def
setOptimizationFlags
(flags)def
setRenderHint
(hint[, enabled=true])def
setRenderHints
(hints)def
setResizeAnchor
(anchor)def
setRubberBandSelectionMode
(mode)def
setScene
(scene)def
setSceneRect
(rect)def
setSceneRect
(x, y, w, h)def
setTransform
(matrix[, combine=false])def
setTransformationAnchor
(anchor)def
setViewportUpdateMode
(mode)def
shear
(sh, sv)def
transform
()def
transformationAnchor
()def
translate
(dx, dy)def
viewportTransform
()def
viewportUpdateMode
()
Virtual functions¶
def
drawBackground
(painter, rect)def
drawForeground
(painter, rect)def
drawItems
(painter, items, options)
Slots¶
def
invalidateScene
([rect=QRectF()[, layers=QGraphicsScene.AllLayers]])def
updateScene
(rects)def
updateSceneRect
(rect)
Signals¶
def
rubberBandChanged
(viewportRect, fromScenePoint, toScenePoint)
Detailed Description¶
QGraphicsView
visualizes the contents of aQGraphicsScene
in a scrollable viewport. To create a scene with geometrical items, seeQGraphicsScene
‘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 toQGraphicsView
‘s constructor. Alternatively, you can callsetScene()
to set the scene at a later point. After you callshow()
, 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 = QGraphicsScene() scene.addText("Hello, world!") view = QGraphicsView(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 tocenterOn()
,QGraphicsView
will scroll its viewport to ensure that the point is centered in the view. An overload is provided for scrolling to aQGraphicsItem
, in which caseQGraphicsView
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 callensureVisible()
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 callingitemsBoundingRect()
). To set the visualized area rectangle yourself, you can callsetSceneRect()
. 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 callingrender()
. By default, the items are drawn onto the viewport by using a regularQPainter
, and using default render hints. To change the default render hints thatQGraphicsView
passes toQPainter
when painting items, you can callsetRenderHints()
.By default,
QGraphicsView
provides a regularQWidget
for the viewport widget. You can access this widget by callingviewport()
, or you can replace it by callingsetViewport()
. To render using OpenGL, simply callsetViewport
(newQGLWidget
).QGraphicsView
takes ownership of the viewport widget.
QGraphicsView
supports affine transformations, usingQTransform
. You can either pass a matrix tosetTransform()
, or you can call one of the convenience functionsrotate()
,scale()
,translate()
orshear()
. 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 inheritQGraphicsSceneEvent
,), 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 callingsetInteractive()
.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 functionsmapToScene()
andmapFromScene()
, and the item accessorsitems()
anditemAt()
. 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.
-
class
QGraphicsView
(scene[, parent=None])¶ QGraphicsView([parent=None])
- param parent
- param scene
Constructs a
QGraphicsView
and sets the visualized scene toscene
.parent
is passed toQWidget
‘s constructor.Constructs a
QGraphicsView
.parent
is passed toQWidget
‘s constructor.
-
PySide2.QtWidgets.QGraphicsView.
ViewportAnchor
¶ This enums describe the possible anchors that
QGraphicsView
can use when the user resizes the view or when the view is transformed.Constant
Description
QGraphicsView.NoAnchor
No anchor, i.e. the view leaves the scene’s position unchanged.
QGraphicsView.AnchorViewCenter
The scene point at the center of the view is used as the anchor.
QGraphicsView.AnchorUnderMouse
The point under the mouse is used as the anchor.
See also
-
PySide2.QtWidgets.QGraphicsView.
CacheModeFlag
¶ This enum describes the flags that you can set for a
QGraphicsView
‘s cache mode.Constant
Description
QGraphicsView.CacheNone
All painting is done directly onto the viewport.
QGraphicsView.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
-
PySide2.QtWidgets.QGraphicsView.
DragMode
¶ This enum describes the default action for the view when pressing and dragging the mouse over the viewport.
Constant
Description
QGraphicsView.NoDrag
Nothing happens; the mouse event is ignored.
QGraphicsView.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.QGraphicsView.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
-
PySide2.QtWidgets.QGraphicsView.
ViewportUpdateMode
¶ This enum describes how
QGraphicsView
updates its viewport when the scene contents change or are exposed.Constant
Description
QGraphicsView.FullViewportUpdate
When any visible part of the scene changes or is reexposed,
QGraphicsView
will update the entire viewport. This approach is fastest whenQGraphicsView
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 asQGLWidget
, and for viewports that need to disable scroll optimization.QGraphicsView.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 isQGraphicsView
‘s default mode. Although this approach provides the best performance in general, if there are many small visible changes on the scene,QGraphicsView
might end up spending more time finding the minimal approach than it will spend drawing.QGraphicsView.SmartViewportUpdate
QGraphicsView
will attempt to find an optimal update mode by analyzing the areas that require a redraw.QGraphicsView.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.QGraphicsView.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 inQGraphicsView
, and is suitable for scenes that either require a fixed frame rate, or where the viewport is otherwise updated externally.See also
-
PySide2.QtWidgets.QGraphicsView.
OptimizationFlag
¶ This enum describes flags that you can enable to improve rendering performance in
QGraphicsView
. 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.Constant
Description
QGraphicsView.DontClipPainter
This value is obsolete and has no effect.
QGraphicsView.DontSavePainterState
When rendering,
QGraphicsView
protects the painter state (seesave()
) 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 callsetPen()
orsetBrush()
without restoring the state after painting). However, if the items consistently do restore the state, you should enable this flag to preventQGraphicsView
from doing the same.QGraphicsView.DontAdjustForAntialiasing
Disables
QGraphicsView
‘s antialiasing auto-adjustment of exposed areas. Items that render antialiased lines on the boundaries of theirboundingRect()
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.QGraphicsView.IndirectPainting
Since Qt 4.6, restore the old painting algorithm that calls
drawItems()
anddrawItems()
. To be used only for compatibility with old code.
-
PySide2.QtWidgets.QGraphicsView.
alignment
()¶ - Return type
Alignment
See also
-
PySide2.QtWidgets.QGraphicsView.
backgroundBrush
()¶ - Return type
QBrush
See also
-
PySide2.QtWidgets.QGraphicsView.
cacheMode
()¶ - Return type
CacheMode
See also
-
PySide2.QtWidgets.QGraphicsView.
centerOn
(pos)¶ - Parameters
pos –
QPointF
-
PySide2.QtWidgets.QGraphicsView.
centerOn
(x, y) - Parameters
x –
qreal
y –
qreal
This is an overloaded function.
This function is provided for convenience. It’s equivalent to calling
centerOn
(QPointF
(x
,y
)).
-
PySide2.QtWidgets.QGraphicsView.
centerOn
(item) - Parameters
item –
QGraphicsItem
This is an overloaded function.
Scrolls the contents of the viewport to ensure that
item
is centered in the view.See also
-
PySide2.QtWidgets.QGraphicsView.
dragMode
()¶ - Return type
See also
-
PySide2.QtWidgets.QGraphicsView.
drawBackground
(painter, rect)¶ - Parameters
painter –
QPainter
rect –
QRectF
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’sbackgroundBrush
. If no such brush is defined (the default), the scene’s function is called instead.See also
-
PySide2.QtWidgets.QGraphicsView.
drawForeground
(painter, rect)¶ - Parameters
painter –
QPainter
rect –
QRectF
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’sforegroundBrush
. If no such brush is defined (the default), the scene’s function is called instead.See also
-
PySide2.QtWidgets.QGraphicsView.
drawItems
(painter, items, options)¶ - Parameters
painter –
QPainter
items –
QGraphicsItem[]
options –
QStyleOptionGraphicsItem[]
Draws the items
items
in the scene usingpainter
, after the background and before the foreground are drawn.numItems
is the number of items initems
and options inoptions
.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 function.
Since Qt 4.6, this function is not called anymore unless the
IndirectPainting
flag is given as an Optimization flag.See also
drawForeground()
drawBackground()
drawItems()
-
PySide2.QtWidgets.QGraphicsView.
ensureVisible
(item[, xmargin=50[, ymargin=50]])¶ - Parameters
item –
QGraphicsItem
xmargin –
int
ymargin –
int
This is an overloaded function.
Scrolls the contents of the viewport so that the center of item
item
is visible, with margins specified in pixels byxmargin
andymargin
. 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
-
PySide2.QtWidgets.QGraphicsView.
ensureVisible
(rect[, xmargin=50[, ymargin=50]]) - Parameters
rect –
QRectF
xmargin –
int
ymargin –
int
-
PySide2.QtWidgets.QGraphicsView.
ensureVisible
(x, y, w, h[, xmargin=50[, ymargin=50]]) - Parameters
x –
qreal
y –
qreal
w –
qreal
h –
qreal
xmargin –
int
ymargin –
int
This is an overloaded function.
This function is provided for convenience. It’s equivalent to calling
ensureVisible
(QRectF
(x
,y
,w
,h
),xmargin
,ymargin
).
-
PySide2.QtWidgets.QGraphicsView.
fitInView
(x, y, w, h[, aspectRadioMode=Qt.IgnoreAspectRatio])¶ - Parameters
x –
qreal
y –
qreal
w –
qreal
h –
qreal
aspectRadioMode –
AspectRatioMode
This is an overloaded function.
This convenience function is equivalent to calling
fitInView
(QRectF
(x
,y
,w
,h
),aspectRatioMode
).See also
-
PySide2.QtWidgets.QGraphicsView.
fitInView
(rect[, aspectRadioMode=Qt.IgnoreAspectRatio]) - Parameters
rect –
QRectF
aspectRadioMode –
AspectRatioMode
-
PySide2.QtWidgets.QGraphicsView.
fitInView
(item[, aspectRadioMode=Qt.IgnoreAspectRatio]) - Parameters
item –
QGraphicsItem
aspectRadioMode –
AspectRatioMode
This is an overloaded function.
Ensures that
item
fits tightly inside the view, scaling the view according toaspectRatioMode
.See also
-
PySide2.QtWidgets.QGraphicsView.
foregroundBrush
()¶ - Return type
QBrush
See also
-
PySide2.QtWidgets.QGraphicsView.
invalidateScene
([rect=QRectF()[, layers=QGraphicsScene.AllLayers]])¶ - Parameters
rect –
QRectF
layers –
SceneLayers
Invalidates and schedules a redraw of
layers
insiderect
.rect
is in scene coordinates. Any cached content forlayers
insiderect
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 whenQGraphicsView
has enabled background caching.Note that
QGraphicsView
currently supports background caching only (seeCacheBackground
). This function is equivalent to callingupdate()
if any layer butBackgroundLayer
is passed.See also
-
PySide2.QtWidgets.QGraphicsView.
isInteractive
()¶ - Return type
bool
-
PySide2.QtWidgets.QGraphicsView.
isTransformed
()¶ - Return type
bool
Returns
true
if the view is transformed (i.e., a non-identity transform has been assigned, or the scrollbars are adjusted).
-
PySide2.QtWidgets.QGraphicsView.
itemAt
(pos)¶ - Parameters
pos –
QPoint
- Return type
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:
def mousePressEvent(self, event): if (item = itemAt(event.pos()): print "You clicked on item", item else: print "You didn't click on an item."
See also
items()
Sorting
-
PySide2.QtWidgets.QGraphicsView.
itemAt
(x, y) - Parameters
x –
int
y –
int
- Return type
This is an overloaded function.
This function is provided for convenience. It’s equivalent to calling
itemAt
(QPoint
(x
,y
)).
-
PySide2.QtWidgets.QGraphicsView.
items
()¶ - Return type
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
items()
Sorting
-
PySide2.QtWidgets.QGraphicsView.
items
(path[, mode=Qt.IntersectsItemShape]) - Parameters
path –
QPainterPath
mode –
ItemSelectionMode
- Return type
-
PySide2.QtWidgets.QGraphicsView.
items
(pos) - Parameters
pos –
QPoint
- Return type
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 likepos()
.def mousePressEvent(self, event): print "There are", items(event->pos()).size(), "items at position", mapToScene(event->pos())
See also
items()
Sorting
-
PySide2.QtWidgets.QGraphicsView.
items
(polygon[, mode=Qt.IntersectsItemShape]) - Parameters
polygon –
QPolygon
mode –
ItemSelectionMode
- Return type
-
PySide2.QtWidgets.QGraphicsView.
items
(rect[, mode=Qt.IntersectsItemShape]) - Parameters
rect –
QRect
mode –
ItemSelectionMode
- Return type
-
PySide2.QtWidgets.QGraphicsView.
items
(x, y) - Parameters
x –
int
y –
int
- Return type
This function is provided for convenience. It’s equivalent to calling items(
QPoint
(x
,y
)).
-
PySide2.QtWidgets.QGraphicsView.
items
(x, y, w, h[, mode=Qt.IntersectsItemShape]) - Parameters
x –
int
y –
int
w –
int
h –
int
mode –
ItemSelectionMode
- Return type
This convenience function is equivalent to calling items(
QRectF
(x
,y
,w
,h
),mode
).
-
PySide2.QtWidgets.QGraphicsView.
mapFromScene
(path)¶ - Parameters
path –
QPainterPath
- Return type
QPainterPath
-
PySide2.QtWidgets.QGraphicsView.
mapFromScene
(x, y, w, h) - Parameters
x –
qreal
y –
qreal
w –
qreal
h –
qreal
- Return type
QPolygon
This function is provided for convenience. It’s equivalent to calling
mapFromScene
(QRectF
(x
,y
,w
,h
)).
-
PySide2.QtWidgets.QGraphicsView.
mapFromScene
(x, y) - Parameters
x –
qreal
y –
qreal
- Return type
QPoint
This function is provided for convenience. It’s equivalent to calling
mapFromScene
(QPointF
(x
,y
)).
-
PySide2.QtWidgets.QGraphicsView.
mapFromScene
(polygon) - Parameters
polygon –
QPolygonF
- Return type
QPolygon
-
PySide2.QtWidgets.QGraphicsView.
mapFromScene
(point) - Parameters
point –
QPointF
- Return type
QPoint
-
PySide2.QtWidgets.QGraphicsView.
mapFromScene
(rect) - Parameters
rect –
QRectF
- Return type
QPolygon
-
PySide2.QtWidgets.QGraphicsView.
mapToScene
(x, y, w, h)¶ - Parameters
x –
int
y –
int
w –
int
h –
int
- Return type
QPolygonF
This function is provided for convenience. It’s equivalent to calling
mapToScene
(QRect
(x
,y
,w
,h
)).
-
PySide2.QtWidgets.QGraphicsView.
mapToScene
(x, y) - Parameters
x –
int
y –
int
- Return type
QPointF
This function is provided for convenience. It’s equivalent to calling
mapToScene
(QPoint
(x
,y
)).
-
PySide2.QtWidgets.QGraphicsView.
mapToScene
(rect) - Parameters
rect –
QRect
- Return type
QPolygonF
-
PySide2.QtWidgets.QGraphicsView.
mapToScene
(polygon) - Parameters
polygon –
QPolygon
- Return type
QPolygonF
-
PySide2.QtWidgets.QGraphicsView.
mapToScene
(point) - Parameters
point –
QPoint
- Return type
QPointF
-
PySide2.QtWidgets.QGraphicsView.
mapToScene
(path) - Parameters
path –
QPainterPath
- Return type
QPainterPath
-
PySide2.QtWidgets.QGraphicsView.
matrix
()¶ - Return type
QMatrix
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()
-
PySide2.QtWidgets.QGraphicsView.
optimizationFlags
()¶ - Return type
OptimizationFlags
See also
-
PySide2.QtWidgets.QGraphicsView.
render
(painter[, target=QRectF()[, source=QRect()[, aspectRatioMode=Qt.KeepAspectRatio]]])¶ - Parameters
painter –
QPainter
target –
QRectF
source –
QRect
aspectRatioMode –
AspectRatioMode
Renders the
source
rect, which is in view coordinates, from the scene intotarget
, which is in paint device coordinates, usingpainter
. This function is useful for capturing the contents of the view onto a paint device, such as aQImage
(e.g., to take a screenshot), or for printing toQPrinter
. For example:scene = QGraphicsScene() scene.addItem(... ... view = QGraphicsView(scene) view.show() ... printer = QPrinter(QPrinter.HighResolution) printer.setPageSize(QPrinter.A4) painter = QPainter(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. 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 useviewport()
->rect()
to determine what to draw. Iftarget
is a null rect, the full dimensions ofpainter
‘s paint device (e.g., for aQPrinter
, 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, andsource
is scaled to fit intarget
.See also
-
PySide2.QtWidgets.QGraphicsView.
renderHints
()¶ - Return type
RenderHints
See also
-
PySide2.QtWidgets.QGraphicsView.
resetCachedContent
()¶ Resets any cached content. Calling this function will clear
QGraphicsView
‘s cache. If the current cache mode isCacheNone
, this function does nothing.This function is called automatically for you when the
backgroundBrush
orbackgroundBrush
properties change; you only need to call this function if you have reimplementeddrawBackground()
ordrawBackground()
to draw a custom background, and need to trigger a full redraw.See also
-
PySide2.QtWidgets.QGraphicsView.
resetMatrix
()¶ Resets the view transformation matrix to the identity matrix.
See also
-
PySide2.QtWidgets.QGraphicsView.
resetTransform
()¶ Resets the view transformation to the identity matrix.
See also
-
PySide2.QtWidgets.QGraphicsView.
resizeAnchor
()¶ - Return type
See also
-
PySide2.QtWidgets.QGraphicsView.
rotate
(angle)¶ - Parameters
angle –
qreal
Rotates the current view transformation
angle
degrees clockwise.See also
-
PySide2.QtWidgets.QGraphicsView.
rubberBandChanged
(viewportRect, fromScenePoint, toScenePoint)¶ - Parameters
viewportRect –
QRect
fromScenePoint –
QPointF
toScenePoint –
QPointF
-
PySide2.QtWidgets.QGraphicsView.
rubberBandRect
()¶ - Return type
QRect
This functions returns the current rubber band area (in viewport coordinates) if the user is currently doing an itemselection with rubber band. When the user is not using the rubber band this functions returns (a null) QRectF().
Notice that part of this
QRect
can be outise the visual viewport. It can e.g contain negative values.
-
PySide2.QtWidgets.QGraphicsView.
rubberBandSelectionMode
()¶ - Return type
ItemSelectionMode
See also
-
PySide2.QtWidgets.QGraphicsView.
scale
(sx, sy)¶ - Parameters
sx –
qreal
sy –
qreal
Scales the current view transformation by (
sx
,sy
).See also
-
PySide2.QtWidgets.QGraphicsView.
scene
()¶ - Return type
Returns a pointer to the scene that is currently visualized in the view. If no scene is currently visualized, 0 is returned.
See also
-
PySide2.QtWidgets.QGraphicsView.
sceneRect
()¶ - Return type
QRectF
See also
-
PySide2.QtWidgets.QGraphicsView.
setAlignment
(alignment)¶ - Parameters
alignment –
Alignment
See also
-
PySide2.QtWidgets.QGraphicsView.
setBackgroundBrush
(brush)¶ - Parameters
brush –
QBrush
See also
-
PySide2.QtWidgets.QGraphicsView.
setCacheMode
(mode)¶ - Parameters
mode –
CacheMode
See also
-
PySide2.QtWidgets.QGraphicsView.
setForegroundBrush
(brush)¶ - Parameters
brush –
QBrush
See also
-
PySide2.QtWidgets.QGraphicsView.
setInteractive
(allowed)¶ - Parameters
allowed –
bool
See also
-
PySide2.QtWidgets.QGraphicsView.
setMatrix
(matrix[, combine=false])¶ - Parameters
matrix –
QMatrix
combine –
bool
Sets the view’s current transformation matrix to
matrix
.If
combine
is true, thenmatrix
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 = QGraphicsScene() scene.addText("GraphicsView rotated clockwise") view = QGraphicsView(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
providesmapTo
… andmapFrom
… functions that can translate between scene and view coordinates. For example, you can callmapToScene()
to map a view coordinate to a floating point scene coordinate, ormapFromScene()
to map from floating point scene coordinates to view coordinates.See also
matrix()
setTransform()
rotate()
scale()
shear()
translate()
-
PySide2.QtWidgets.QGraphicsView.
setOptimizationFlag
(flag[, enabled=true])¶ - Parameters
flag –
OptimizationFlag
enabled –
bool
Enables
flag
ifenabled
is true; otherwise disablesflag
.See also
-
PySide2.QtWidgets.QGraphicsView.
setOptimizationFlags
(flags)¶ - Parameters
flags –
OptimizationFlags
See also
-
PySide2.QtWidgets.QGraphicsView.
setRenderHint
(hint[, enabled=true])¶ - Parameters
hint –
RenderHint
enabled –
bool
If
enabled
is true, the render hinthint
is enabled; otherwise it is disabled.See also
-
PySide2.QtWidgets.QGraphicsView.
setRenderHints
(hints)¶ - Parameters
hints –
RenderHints
See also
-
PySide2.QtWidgets.QGraphicsView.
setResizeAnchor
(anchor)¶ - Parameters
anchor –
ViewportAnchor
See also
-
PySide2.QtWidgets.QGraphicsView.
setRubberBandSelectionMode
(mode)¶ - Parameters
mode –
ItemSelectionMode
See also
-
PySide2.QtWidgets.QGraphicsView.
setScene
(scene)¶ - Parameters
scene –
QGraphicsScene
Sets the current scene to
scene
. Ifscene
is already being viewed, this function does nothing.When a scene is set on a view, the
changed()
signal is automatically connected to this view’supdateScene()
slot, and the view’s scroll bars are adjusted to fit the size of the scene.The view does not take ownership of
scene
.See also
-
PySide2.QtWidgets.QGraphicsView.
setSceneRect
(rect)¶ - Parameters
rect –
QRectF
See also
-
PySide2.QtWidgets.QGraphicsView.
setSceneRect
(x, y, w, h) - Parameters
x –
qreal
y –
qreal
w –
qreal
h –
qreal
-
PySide2.QtWidgets.QGraphicsView.
setTransform
(matrix[, combine=false])¶ - Parameters
matrix –
QTransform
combine –
bool
Sets the view’s current transformation matrix to
matrix
.If
combine
is true, thenmatrix
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 = QGraphicsScene() scene.addText("GraphicsView rotated clockwise") view = QGraphicsView(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
providesmapTo
… andmapFrom
… functions that can translate between scene and view coordinates. For example, you can callmapToScene()
to map a view coordiate to a floating point scene coordinate, ormapFromScene()
to map from floating point scene coordinates to view coordinates.See also
-
PySide2.QtWidgets.QGraphicsView.
setTransformationAnchor
(anchor)¶ - Parameters
anchor –
ViewportAnchor
See also
-
PySide2.QtWidgets.QGraphicsView.
setViewportUpdateMode
(mode)¶ - Parameters
mode –
ViewportUpdateMode
See also
-
PySide2.QtWidgets.QGraphicsView.
shear
(sh, sv)¶ - Parameters
sh –
qreal
sv –
qreal
Shears the current view transformation by (
sh
,sv
).See also
-
PySide2.QtWidgets.QGraphicsView.
transform
()¶ - Return type
QTransform
Returns the current transformation matrix for the view. If no current transformation is set, the identity matrix is returned.
See also
-
PySide2.QtWidgets.QGraphicsView.
transformationAnchor
()¶ - Return type
See also
-
PySide2.QtWidgets.QGraphicsView.
translate
(dx, dy)¶ - Parameters
dx –
qreal
dy –
qreal
Translates the current view transformation by (
dx
,dy
).See also
-
PySide2.QtWidgets.QGraphicsView.
updateScene
(rects)¶ - Parameters
rects –
Schedules an update of the scene rectangles
rects
.See also
-
PySide2.QtWidgets.QGraphicsView.
updateSceneRect
(rect)¶ - Parameters
rect –
QRectF
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
-
PySide2.QtWidgets.QGraphicsView.
viewportTransform
()¶ - Return type
QTransform
Returns a matrix that maps scene coordinates to viewport coordinates.
See also
-
PySide2.QtWidgets.QGraphicsView.
viewportUpdateMode
()¶ - Return type
See also
© 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.