Inherited by: QDeclarativeView
The PySide.QtGui.QGraphicsView class provides a widget for displaying the contents of a PySide.QtGui.QGraphicsScene .
PySide.QtGui.QGraphicsView visualizes the contents of a PySide.QtGui.QGraphicsScene in a scrollable viewport. To create a scene with geometrical items, see PySide.QtGui.QGraphicsScene ‘s documentation. PySide.QtGui.QGraphicsView is part of the Graphics View Framework .
To visualize a scene, you start by constructing a PySide.QtGui.QGraphicsView object, passing the address of the scene you want to visualize to PySide.QtGui.QGraphicsView ‘s constructor. Alternatively, you can call PySide.QtGui.QGraphicsView.setScene() to set the scene at a later point. After you call PySide.QtGui.QWidget.show() , the view will by default scroll to the center of the scene and display any items that are visible at this point. For example:
scene = 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 PySide.QtGui.QGraphicsView.centerOn() . By passing a point to PySide.QtGui.QGraphicsView.centerOn() , PySide.QtGui.QGraphicsView will scroll its viewport to ensure that the point is centered in the view. An overload is provided for scrolling to a PySide.QtGui.QGraphicsItem , in which case PySide.QtGui.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 PySide.QtGui.QGraphicsView.ensureVisible() instead.
PySide.QtGui.QGraphicsView can be used to visualize a whole scene, or only parts of it. The visualized area is by default detected automatically when the view is displayed for the first time (by calling QGraphicsScene.itemsBoundingRect() ). To set the visualized area rectangle yourself, you can call PySide.QtGui.QGraphicsView.setSceneRect() . This will adjust the scroll bars’ ranges appropriately. Note that although the scene supports a virtually unlimited size, the range of the scroll bars will never exceed the range of an integer (INT_MIN, INT_MAX).
PySide.QtGui.QGraphicsView visualizes the scene by calling PySide.QtGui.QGraphicsView.render() . By default, the items are drawn onto the viewport by using a regular PySide.QtGui.QPainter , and using default render hints. To change the default render hints that PySide.QtGui.QGraphicsView passes to PySide.QtGui.QPainter when painting items, you can call PySide.QtGui.QGraphicsView.setRenderHints() .
By default, PySide.QtGui.QGraphicsView provides a regular PySide.QtGui.QWidget for the viewport widget. You can access this widget by calling PySide.QtGui.QAbstractScrollArea.viewport() , or you can replace it by calling PySide.QtGui.QAbstractScrollArea.setViewport() . To render using OpenGL, simply call setViewport(new PySide.QtOpenGL.QGLWidget ). PySide.QtGui.QGraphicsView takes ownership of the viewport widget.
PySide.QtGui.QGraphicsView supports affine transformations, using PySide.QtGui.QTransform . You can either pass a matrix to PySide.QtGui.QGraphicsView.setTransform() , or you can call one of the convenience functions PySide.QtGui.QGraphicsView.rotate() , PySide.QtGui.QGraphicsView.scale() , PySide.QtGui.QGraphicsView.translate() or PySide.QtGui.QGraphicsView.shear() . The most two common transformations are scaling, which is used to implement zooming, and rotation. PySide.QtGui.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. PySide.QtGui.QGraphicsView translates the mouse and key events into scene events, (events that inherit PySide.QtGui.QGraphicsSceneEvent ,), and forward them to the visualized scene. In the end, it’s the individual item that handles the events and reacts to them. For example, if you click on a selectable item, the item will typically let the scene know that it has been selected, and it will also redraw itself to display a selection rectangle. Similiary, if you click and drag the mouse to move a movable item, it’s the item that handles the mouse moves and moves itself. Item interaction is enabled by default, and you can toggle it by calling PySide.QtGui.QGraphicsView.setInteractive() .
You can also provide your own custom scene interaction, by creating a subclass of PySide.QtGui.QGraphicsView , and reimplementing the mouse and key event handlers. To simplify how you programmatically interact with items in the view, PySide.QtGui.QGraphicsView provides the mapping functions PySide.QtGui.QGraphicsView.mapToScene() and PySide.QtGui.QGraphicsView.mapFromScene() , and the item accessors PySide.QtGui.QGraphicsView.items() and PySide.QtGui.QGraphicsView.itemAt() . These functions allow you to map points, rectangles, polygons and paths between view coordinates and scene coordinates, and to find items on the scene using view coordinates.
Parameters: |
|
---|
Constructs a PySide.QtGui.QGraphicsView and sets the visualized scene to scene . parent is passed to PySide.QtGui.QWidget ‘s constructor.
Constructs a PySide.QtGui.QGraphicsView . parent is passed to PySide.QtGui.QWidget ‘s constructor.
This enum describes flags that you can enable to improve rendering performance in PySide.QtGui.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, PySide.QtGui.QGraphicsView protects the painter state (see QPainter.save() ) when rendering the background or foreground, and when rendering each item. This allows you to leave the painter in an altered state (i.e., you can call QPainter.setPen() or QPainter.setBrush() without restoring the state after painting). However, if the items consistently do restore the state, you should enable this flag to prevent PySide.QtGui.QGraphicsView from doing the same. |
QGraphicsView.DontAdjustForAntialiasing | Disables PySide.QtGui.QGraphicsView ‘s antialiasing auto-adjustment of exposed areas. Items that render antialiased lines on the boundaries of their QGraphicsItem.boundingRect() can end up rendering parts of the line outside. To prevent rendering artifacts, PySide.QtGui.QGraphicsView expands all exposed regions by 2 pixels in all directions. If you enable this flag, PySide.QtGui.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 QGraphicsView.drawItems() and QGraphicsScene.drawItems() . To be used only for compatibility with old code. |
This enums describe the possible anchors that PySide.QtGui.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. |
This enum describes how PySide.QtGui.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, PySide.QtGui.QGraphicsView will update the entire viewport. This approach is fastest when PySide.QtGui.QGraphicsView spends more time figuring out what to draw than it would spend drawing (e.g., when very many small items are repeatedly updated). This is the preferred update mode for viewports that do not support partial updates, such as PySide.QtOpenGL.QGLWidget , and for viewports that need to disable scroll optimization. |
QGraphicsView.MinimalViewportUpdate | PySide.QtGui.QGraphicsView will determine the minimal viewport region that requires a redraw, minimizing the time spent drawing by avoiding a redraw of areas that have not changed. This is PySide.QtGui.QGraphicsView ‘s default mode. Although this approach provides the best performance in general, if there are many small visible changes on the scene, PySide.QtGui.QGraphicsView might end up spending more time finding the minimal approach than it will spend drawing. |
QGraphicsView.SmartViewportUpdate | PySide.QtGui.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 PySide.QtGui.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 | PySide.QtGui.QGraphicsView will never update its viewport when the scene changes; the user is expected to control all updates. This mode disables all (potentially slow) item visibility testing in PySide.QtGui.QGraphicsView , and is suitable for scenes that either require a fixed frame rate, or where the viewport is otherwise updated externally. |
This enum describes the flags that you can set for a PySide.QtGui.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 PySide.QtGui.QGraphicsView.backgroundBrush() property. When this flag is enabled, PySide.QtGui.QGraphicsView will allocate one pixmap with the full size of the viewport. |
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 PySide.QtGui.QGraphicsView.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. |
Return type: | PySide.QtCore.Qt.Alignment |
---|
This property holds the alignment of the scene in the view when the whole scene is visible..
If the whole scene is visible in the view, (i.e., there are no visible scroll bars,) the view’s alignment will decide where the scene will be rendered in the view. For example, if the alignment is Qt.AlignCenter , which is default, the scene will be centered in the view, and if the alignment is ( Qt.AlignLeft | Qt.AlignTop ), the scene will be rendered in the top-left corner of the view.
Return type: | PySide.QtGui.QBrush |
---|
This property holds the background brush of the scene..
This property sets the background brush for the scene in this view. It is used to override the scene’s own background, and defines the behavior of PySide.QtGui.QGraphicsView.drawBackground() . To provide custom background drawing for this view, you can reimplement PySide.QtGui.QGraphicsView.drawBackground() instead.
By default, this property contains a brush with the Qt.NoBrush pattern.
Return type: | PySide.QtGui.QGraphicsView.CacheMode |
---|
This property holds which parts of the view are cached.
PySide.QtGui.QGraphicsView can cache pre-rendered content in a PySide.QtGui.QPixmap , which is then drawn onto the viewport. The purpose of such caching is to speed up the total rendering time for areas that are slow to render. Texture, gradient and alpha blended backgrounds, for example, can be notibly slow to render; especially with a transformed view. The CacheBackground flag enables caching of the view’s background. For example:
view = QGraphicsView()
view.setBackgroundBrush(QImage(":/images/backgroundtile.png"))
view.setCacheMode(QGraphicsView.CacheBackground)
The cache is invalidated every time the view is transformed. However, when scrolling, only partial invalidation is required.
By default, nothing is cached.
Parameters: |
|
---|
This is an overloaded function.
This function is provided for convenience. It’s equivalent to calling centerOn( PySide.QtCore.QPointF (x , y )).
Parameters: | item – PySide.QtGui.QGraphicsItem |
---|
This is an overloaded function.
Scrolls the contents of the viewport to ensure that item is centered in the view.
Parameters: | pos – PySide.QtCore.QPointF |
---|
Scrolls the contents of the viewport to ensure that the scene coordinate pos , is centered in the view.
Because pos is a floating point coordinate, and the scroll bars operate on integer coordinates, the centering is only an approximation.
Note
If the item is close to or outside the border, it will be visible in the view, but not centered.
Return type: | PySide.QtGui.QGraphicsView.DragMode |
---|
This property holds the behavior for dragging the mouse over the scene while the left mouse button is pressed..
This property defines what should happen when the user clicks on the scene background and drags the mouse (e.g., scrolling the viewport contents using a pointing hand cursor, or selecting multiple items with a rubber band). The default value, NoDrag , does nothing.
This behavior only affects mouse clicks that are not handled by any item. You can define a custom behavior by creating a subclass of PySide.QtGui.QGraphicsView and reimplementing PySide.QtGui.QGraphicsView.mouseMoveEvent() .
Parameters: |
|
---|
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 PySide.QtGui.QGraphicsView.setBackgroundBrush() instead.
All painting is done in scene coordinates. rect is the exposed rectangle.
The default implementation fills rect using the view’s PySide.QtGui.QGraphicsView.backgroundBrush() . If no such brush is defined (the default), the scene’s PySide.QtGui.QGraphicsView.drawBackground() function is called instead.
Parameters: |
|
---|
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 PySide.QtGui.QGraphicsView.setForegroundBrush() instead.
All painting is done in scene coordinates. rect is the exposed rectangle.
The default implementation fills rect using the view’s PySide.QtGui.QGraphicsView.foregroundBrush() . If no such brush is defined (the default), the scene’s PySide.QtGui.QGraphicsView.drawForeground() function is called instead.
Parameters: |
|
---|
Parameters: |
|
---|
Scrolls the contents of the viewport so that the scene rectangle rect is visible, with margins specified in pixels by xmargin and ymargin . If the specified rect cannot be reached, the contents are scrolled to the nearest valid position. The default value for both margins is 50 pixels.
Parameters: |
|
---|
This is an overloaded function.
This function is provided for convenience. It’s equivalent to calling ensureVisible( PySide.QtCore.QRectF (x , y , w , h ), xmargin , ymargin ).
Parameters: |
|
---|
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 by xmargin and ymargin . 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.
Parameters: |
|
---|
Parameters: |
|
---|
Parameters: |
|
---|
Return type: | PySide.QtGui.QBrush |
---|
This property holds the foreground brush of the scene..
This property sets the foreground brush for the scene in this view. It is used to override the scene’s own foreground, and defines the behavior of PySide.QtGui.QGraphicsView.drawForeground() . To provide custom foreground drawing for this view, you can reimplement PySide.QtGui.QGraphicsView.drawForeground() instead.
By default, this property contains a brush with the Qt.NoBrush pattern.
Parameters: |
|
---|
Return type: | PySide.QtCore.bool |
---|
This property holds whether the view allowed scene interaction..
If enabled, this view is set to allow scene interaction. Otherwise, this view will not allow interaction, and any mouse or key events are ignored (i.e., it will act as a read-only view).
By default, this property is true.
Return type: | PySide.QtCore.bool |
---|
Returns true if the view is transformed (i.e., a non-identity transform has been assigned, or the scrollbars are adjusted).
Parameters: |
|
---|---|
Return type: |
This is an overloaded function.
This function is provided for convenience. It’s equivalent to calling itemAt( PySide.QtCore.QPoint (x , y )).
Parameters: | pos – PySide.QtCore.QPoint |
---|---|
Return type: | PySide.QtGui.QGraphicsItem |
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
Parameters: |
|
---|---|
Return type: |
This function is provided for convenience. It’s equivalent to calling items( PySide.QtCore.QPoint (x , y )).
Parameters: |
|
---|---|
Return type: |
Parameters: |
|
---|---|
Return type: |
Parameters: |
|
---|---|
Return type: |
Parameters: |
|
---|---|
Return type: |
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
QGraphicsScene.items() Sorting
Parameters: | pos – PySide.QtCore.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 PySide.QtGui.QGraphicsView . pos is in untransformed viewport coordinates, just like QMouseEvent.pos() .
def mousePressEvent(self, event):
print "There are", items(event->pos()).size(), "items at position", mapToScene(event->pos())
See also
QGraphicsScene.items() Sorting
Parameters: |
|
---|---|
Return type: |
This function is provided for convenience. It’s equivalent to calling mapFromScene( PySide.QtCore.QPointF (x , y )).
Parameters: | rect – PySide.QtCore.QRectF |
---|---|
Return type: | PySide.QtGui.QPolygon |
Returns the scene rectangle rect to a viewport coordinate polygon.
Parameters: |
|
---|---|
Return type: |
This function is provided for convenience. It’s equivalent to calling mapFromScene( PySide.QtCore.QRectF (x , y , w , h )).
Parameters: | path – PySide.QtGui.QPainterPath |
---|---|
Return type: | PySide.QtGui.QPainterPath |
Returns the scene coordinate painter path path to a viewport coordinate painter path.
Parameters: | polygon – PySide.QtGui.QPolygonF |
---|---|
Return type: | PySide.QtGui.QPolygon |
Returns the scene coordinate polygon polygon to a viewport coordinate polygon.
Parameters: | point – PySide.QtCore.QPointF |
---|---|
Return type: | PySide.QtCore.QPoint |
Returns the scene coordinate point to viewport coordinates.
Parameters: |
|
---|---|
Return type: |
This function is provided for convenience. It’s equivalent to calling mapToScene( PySide.QtCore.QRect (x , y , w , h )).
Parameters: |
|
---|---|
Return type: |
This function is provided for convenience. It’s equivalent to calling mapToScene( PySide.QtCore.QPoint (x , y )).
Parameters: | rect – PySide.QtCore.QRect |
---|---|
Return type: | PySide.QtGui.QPolygonF |
Returns the viewport rectangle rect mapped to a scene coordinate polygon.
Parameters: | point – PySide.QtCore.QPoint |
---|---|
Return type: | PySide.QtCore.QPointF |
Returns the viewport coordinate point mapped to scene coordinates.
Note: It can be useful to map the whole rectangle covered by the pixel at point instead of the point itself. To do this, you can call mapToScene( PySide.QtCore.QRect (point , PySide.QtCore.QSize (2, 2))).
Parameters: | polygon – PySide.QtGui.QPolygon |
---|---|
Return type: | PySide.QtGui.QPolygonF |
Returns the viewport polygon polygon mapped to a scene coordinate polygon.
Parameters: | path – PySide.QtGui.QPainterPath |
---|---|
Return type: | PySide.QtGui.QPainterPath |
Returns the viewport painter path path mapped to a scene coordinate painter path.
Return type: | PySide.QtGui.QMatrix |
---|
Returns the current transformation matrix for the view. If no current transformation is set, the identity matrix is returned.
Return type: | PySide.QtGui.QGraphicsView.OptimizationFlags |
---|
This property holds flags that can be used to tune PySide.QtGui.QGraphicsView ‘s performance..
PySide.QtGui.QGraphicsView uses clipping, extra bounding rect adjustments, and certain other aids to improve rendering quality and performance for the common case graphics scene. However, depending on the target platform, the scene, and the viewport in use, some of these operations can degrade performance.
The effect varies from flag to flag; see the OptimizationFlags documentation for details.
By default, no optimization flags are enabled.
Parameters: |
|
---|
Return type: | PySide.QtGui.QPainter.RenderHints |
---|
This property holds the default render hints for the view.
These hints are used to initialize PySide.QtGui.QPainter before each visible item is drawn. PySide.QtGui.QPainter uses render hints to toggle rendering features such as antialiasing and smooth pixmap transformation.
QPainter.TextAntialiasing is enabled by default.
Example:
scene = QGraphicsScene()
scene.addRect(QRectF(-10, -10, 20, 20))
view = QGraphicsView(scene)
view.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
view.show()
Resets any cached content. Calling this function will clear PySide.QtGui.QGraphicsView ‘s cache. If the current cache mode is CacheNone , this function does nothing.
This function is called automatically for you when the PySide.QtGui.QGraphicsView.backgroundBrush() or QGraphicsScene.backgroundBrush properties change; you only need to call this function if you have reimplemented QGraphicsScene.drawBackground() or QGraphicsView.drawBackground() to draw a custom background, and need to trigger a full redraw.
Resets the view transformation matrix to the identity matrix.
Resets the view transformation to the identity matrix.
Return type: | PySide.QtGui.QGraphicsView.ViewportAnchor |
---|
This property holds how the view should position the scene when the view is resized..
PySide.QtGui.QGraphicsView uses this property to decide how to position the scene in the viewport when the viewport widget’s size changes. The default behavior, NoAnchor , leaves the scene’s position unchanged during a resize; the top-left corner of the view will appear to be anchored while resizing.
Note that the effect of this property is noticeable when only a part of the scene is visible (i.e., when there are scroll bars). Otherwise, if the whole scene fits in the view, PySide.QtGui.QGraphicsScene uses the view PySide.QtGui.QGraphicsView.alignment() to position the scene in the view.
See also
PySide.QtGui.QGraphicsView.alignment() PySide.QtGui.QGraphicsView.transformationAnchor() Qt.WNorthWestGravity
Parameters: | angle – PySide.QtCore.qreal |
---|
Rotates the current view transformation angle degrees clockwise.
Return type: | PySide.QtCore.Qt.ItemSelectionMode |
---|
This property holds the behavior for selecting items with a rubber band selection rectangle..
This property defines how items are selected when using the RubberBandDrag drag mode.
The default value is Qt.IntersectsItemShape ; all items whose shape intersects with or is contained by the rubber band are selected.
Parameters: |
|
---|
Scales the current view transformation by (sx , sy ).
Return type: | PySide.QtGui.QGraphicsScene |
---|
Returns a pointer to the scene that is currently visualized in the view. If no scene is currently visualized, 0 is returned.
Return type: | PySide.QtCore.QRectF |
---|
This property holds the area of the scene visualized by this view..
The scene rectangle defines the extent of the scene, and in the view’s case, this means the area of the scene that you can navigate using the scroll bars.
If unset, or if a null PySide.QtCore.QRectF is set, this property has the same value as QGraphicsScene.sceneRect , and it changes with QGraphicsScene.sceneRect . Otherwise, the view’s scene rect is unaffected by the scene.
Note that, although the scene supports a virtually unlimited size, the range of the scroll bars will never exceed the range of an integer (INT_MIN, INT_MAX). When the scene is larger than the scroll bars’ values, you can choose to use PySide.QtGui.QGraphicsView.translate() to navigate the scene instead.
By default, this property contains a rectangle at the origin with zero width and height.
See also
Parameters: | alignment – PySide.QtCore.Qt.Alignment |
---|
This property holds the alignment of the scene in the view when the whole scene is visible..
If the whole scene is visible in the view, (i.e., there are no visible scroll bars,) the view’s alignment will decide where the scene will be rendered in the view. For example, if the alignment is Qt.AlignCenter , which is default, the scene will be centered in the view, and if the alignment is ( Qt.AlignLeft | Qt.AlignTop ), the scene will be rendered in the top-left corner of the view.
Parameters: | brush – PySide.QtGui.QBrush |
---|
This property holds the background brush of the scene..
This property sets the background brush for the scene in this view. It is used to override the scene’s own background, and defines the behavior of PySide.QtGui.QGraphicsView.drawBackground() . To provide custom background drawing for this view, you can reimplement PySide.QtGui.QGraphicsView.drawBackground() instead.
By default, this property contains a brush with the Qt.NoBrush pattern.
Parameters: | mode – PySide.QtGui.QGraphicsView.CacheMode |
---|
This property holds which parts of the view are cached.
PySide.QtGui.QGraphicsView can cache pre-rendered content in a PySide.QtGui.QPixmap , which is then drawn onto the viewport. The purpose of such caching is to speed up the total rendering time for areas that are slow to render. Texture, gradient and alpha blended backgrounds, for example, can be notibly slow to render; especially with a transformed view. The CacheBackground flag enables caching of the view’s background. For example:
view = QGraphicsView()
view.setBackgroundBrush(QImage(":/images/backgroundtile.png"))
view.setCacheMode(QGraphicsView.CacheBackground)
The cache is invalidated every time the view is transformed. However, when scrolling, only partial invalidation is required.
By default, nothing is cached.
Parameters: | mode – PySide.QtGui.QGraphicsView.DragMode |
---|
This property holds the behavior for dragging the mouse over the scene while the left mouse button is pressed..
This property defines what should happen when the user clicks on the scene background and drags the mouse (e.g., scrolling the viewport contents using a pointing hand cursor, or selecting multiple items with a rubber band). The default value, NoDrag , does nothing.
This behavior only affects mouse clicks that are not handled by any item. You can define a custom behavior by creating a subclass of PySide.QtGui.QGraphicsView and reimplementing PySide.QtGui.QGraphicsView.mouseMoveEvent() .
Parameters: | brush – PySide.QtGui.QBrush |
---|
This property holds the foreground brush of the scene..
This property sets the foreground brush for the scene in this view. It is used to override the scene’s own foreground, and defines the behavior of PySide.QtGui.QGraphicsView.drawForeground() . To provide custom foreground drawing for this view, you can reimplement PySide.QtGui.QGraphicsView.drawForeground() instead.
By default, this property contains a brush with the Qt.NoBrush pattern.
Parameters: | allowed – PySide.QtCore.bool |
---|
This property holds whether the view allowed scene interaction..
If enabled, this view is set to allow scene interaction. Otherwise, this view will not allow interaction, and any mouse or key events are ignored (i.e., it will act as a read-only view).
By default, this property is true.
Parameters: |
|
---|
Sets the view’s current transformation matrix to matrix .
If combine is true, then matrix is combined with the current matrix; otherwise, matrixreplaces 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, PySide.QtGui.QGraphicsView provides mapTo... and mapFrom... functions that can translate between scene and view coordinates. For example, you can call PySide.QtGui.QGraphicsView.mapToScene() to map a view coordinate to a floating point scene coordinate, or PySide.QtGui.QGraphicsView.mapFromScene() to map from floating point scene coordinates to view coordinates.
Parameters: |
|
---|
Enables flag if enabled is true; otherwise disables flag .
Parameters: | flags – PySide.QtGui.QGraphicsView.OptimizationFlags |
---|
This property holds flags that can be used to tune PySide.QtGui.QGraphicsView ‘s performance..
PySide.QtGui.QGraphicsView uses clipping, extra bounding rect adjustments, and certain other aids to improve rendering quality and performance for the common case graphics scene. However, depending on the target platform, the scene, and the viewport in use, some of these operations can degrade performance.
The effect varies from flag to flag; see the OptimizationFlags documentation for details.
By default, no optimization flags are enabled.
Parameters: |
|
---|
Parameters: | hints – PySide.QtGui.QPainter.RenderHints |
---|
This property holds the default render hints for the view.
These hints are used to initialize PySide.QtGui.QPainter before each visible item is drawn. PySide.QtGui.QPainter uses render hints to toggle rendering features such as antialiasing and smooth pixmap transformation.
QPainter.TextAntialiasing is enabled by default.
Example:
scene = QGraphicsScene()
scene.addRect(QRectF(-10, -10, 20, 20))
view = QGraphicsView(scene)
view.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
view.show()
Parameters: | anchor – PySide.QtGui.QGraphicsView.ViewportAnchor |
---|
This property holds how the view should position the scene when the view is resized..
PySide.QtGui.QGraphicsView uses this property to decide how to position the scene in the viewport when the viewport widget’s size changes. The default behavior, NoAnchor , leaves the scene’s position unchanged during a resize; the top-left corner of the view will appear to be anchored while resizing.
Note that the effect of this property is noticeable when only a part of the scene is visible (i.e., when there are scroll bars). Otherwise, if the whole scene fits in the view, PySide.QtGui.QGraphicsScene uses the view PySide.QtGui.QGraphicsView.alignment() to position the scene in the view.
See also
PySide.QtGui.QGraphicsView.alignment() PySide.QtGui.QGraphicsView.transformationAnchor() Qt.WNorthWestGravity
Parameters: | mode – PySide.QtCore.Qt.ItemSelectionMode |
---|
This property holds the behavior for selecting items with a rubber band selection rectangle..
This property defines how items are selected when using the RubberBandDrag drag mode.
The default value is Qt.IntersectsItemShape ; all items whose shape intersects with or is contained by the rubber band are selected.
Parameters: | scene – PySide.QtGui.QGraphicsScene |
---|
Sets the current scene to scene . If scene is already being viewed, this function does nothing.
When a scene is set on a view, the QGraphicsScene.changed() signal is automatically connected to this view’s PySide.QtGui.QGraphicsView.updateScene() slot, and the view’s scroll bars are adjusted to fit the size of the scene.
See also
Parameters: |
|
---|
Parameters: | rect – PySide.QtCore.QRectF |
---|
This property holds the area of the scene visualized by this view..
The scene rectangle defines the extent of the scene, and in the view’s case, this means the area of the scene that you can navigate using the scroll bars.
If unset, or if a null PySide.QtCore.QRectF is set, this property has the same value as QGraphicsScene.sceneRect , and it changes with QGraphicsScene.sceneRect . Otherwise, the view’s scene rect is unaffected by the scene.
Note that, although the scene supports a virtually unlimited size, the range of the scroll bars will never exceed the range of an integer (INT_MIN, INT_MAX). When the scene is larger than the scroll bars’ values, you can choose to use PySide.QtGui.QGraphicsView.translate() to navigate the scene instead.
By default, this property contains a rectangle at the origin with zero width and height.
See also
Parameters: |
|
---|
Sets the view’s current transformation matrix to matrix .
If combine is true, then matrix is combined with the current matrix; otherwise, matrixreplaces 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, PySide.QtGui.QGraphicsView provides mapTo... and mapFrom... functions that can translate between scene and view coordinates. For example, you can call PySide.QtGui.QGraphicsView.mapToScene() to map a view coordiate to a floating point scene coordinate, or PySide.QtGui.QGraphicsView.mapFromScene() to map from floating point scene coordinates to view coordinates.
Parameters: | anchor – PySide.QtGui.QGraphicsView.ViewportAnchor |
---|
This property holds how the view should position the scene during transformations..
PySide.QtGui.QGraphicsView uses this property to decide how to position the scene in the viewport when the transformation matrix changes, and the coordinate system of the view is transformed. The default behavior, AnchorViewCenter , ensures that the scene point at the center of the view remains unchanged during transformations (e.g., when rotating, the scene will appear to rotate around the center of the view).
Note that the effect of this property is noticeable when only a part of the scene is visible (i.e., when there are scroll bars). Otherwise, if the whole scene fits in the view, PySide.QtGui.QGraphicsScene uses the view PySide.QtGui.QGraphicsView.alignment() to position the scene in the view.
Parameters: | mode – PySide.QtGui.QGraphicsView.ViewportUpdateMode |
---|
This property holds how the viewport should update its contents..
PySide.QtGui.QGraphicsView uses this property to decide how to update areas of the scene that have been reexposed or changed. Usually you do not need to modify this property, but there are some cases where doing so can improve rendering performance. See the QGraphicsView.ViewportUpdateMode documentation for specific details.
The default value is MinimalViewportUpdate , where PySide.QtGui.QGraphicsView will update as small an area of the viewport as possible when the contents change.
See also
QGraphicsView.ViewportUpdateMode PySide.QtGui.QGraphicsView.cacheMode()
Parameters: |
|
---|
Shears the current view transformation by (sh , sv ).
Return type: | PySide.QtGui.QTransform |
---|
Returns the current transformation matrix for the view. If no current transformation is set, the identity matrix is returned.
Return type: | PySide.QtGui.QGraphicsView.ViewportAnchor |
---|
This property holds how the view should position the scene during transformations..
PySide.QtGui.QGraphicsView uses this property to decide how to position the scene in the viewport when the transformation matrix changes, and the coordinate system of the view is transformed. The default behavior, AnchorViewCenter , ensures that the scene point at the center of the view remains unchanged during transformations (e.g., when rotating, the scene will appear to rotate around the center of the view).
Note that the effect of this property is noticeable when only a part of the scene is visible (i.e., when there are scroll bars). Otherwise, if the whole scene fits in the view, PySide.QtGui.QGraphicsScene uses the view PySide.QtGui.QGraphicsView.alignment() to position the scene in the view.
Parameters: |
|
---|
Translates the current view transformation by (dx , dy ).
Parameters: | rects – |
---|
Parameters: | rect – PySide.QtCore.QRectF |
---|
Notifies PySide.QtGui.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.
Return type: | PySide.QtGui.QTransform |
---|
Returns a matrix that maps viewport coordinates to scene coordinates.
Return type: | PySide.QtGui.QGraphicsView.ViewportUpdateMode |
---|
This property holds how the viewport should update its contents..
PySide.QtGui.QGraphicsView uses this property to decide how to update areas of the scene that have been reexposed or changed. Usually you do not need to modify this property, but there are some cases where doing so can improve rendering performance. See the QGraphicsView.ViewportUpdateMode documentation for specific details.
The default value is MinimalViewportUpdate , where PySide.QtGui.QGraphicsView will update as small an area of the viewport as possible when the contents change.
See also
QGraphicsView.ViewportUpdateMode PySide.QtGui.QGraphicsView.cacheMode()