内容表

上一话题

QGraphicsTransform

下一话题

QGraphicsWidget

QGraphicsView

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

Inheritance diagram of PySide2.QtWidgets.QGraphicsView

继承者: QtCharts.QChartView

概要

函数

虚函数

信号

详细描述

QGraphicsView visualizes the contents of a QGraphicsScene 在可卷动视口。要创建带几何项的场景,见 QGraphicsScene ‘s documentation. QGraphicsView 属于 图形视图框架 .

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

scene = 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 to centerOn() , QGraphicsView will scroll its viewport to ensure that the point is centered in the view. An overload is provided for scrolling to a QGraphicsItem , in which case QGraphicsView will see to that the center of the item is centered in the view. If all you want is to ensure that a certain area is visible, (but not necessarily centered,) you can call ensureVisible() 代替。

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 itemsBoundingRect() ). To set the visualized area rectangle yourself, you can call setSceneRect() . This will adjust the scroll bars’ ranges appropriately. Note that although the scene supports a virtually unlimited size, the range of the scroll bars will never exceed the range of an integer (INT_MIN, INT_MAX).

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

默认情况下, QGraphicsView provides a regular QWidget for the viewport widget. You can access this widget by calling viewport() , or you can replace it by calling setViewport() . To render using OpenGL, simply call setViewport (new QOpenGLWidget ). QGraphicsView takes ownership of the viewport widget.

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

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

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

../../_images/graphicsview-view.png

注意

Using an OpenGL viewport limits the ability to use QGraphicsProxyWidget . Not all combinations of widgets and styles can be supported with such a setup. You should carefully test your UI and make the necessary adjustments.

class QGraphicsView ( scene [ , parent=None ] )

QGraphicsView([parent=None])

param parent

QWidget

param scene

QGraphicsScene

构造 QGraphicsView and sets the visualized scene to scene . parent 会被传递给 QWidget ‘s constructor.

构造 QGraphicsView . parent 会被传递给 QWidget ‘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.

常量

描述

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.

PySide2.QtWidgets.QGraphicsView. CacheModeFlag

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

常量

描述

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.

另请参阅

cacheMode

PySide2.QtWidgets.QGraphicsView. DragMode

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

常量

描述

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.

PySide2.QtWidgets.QGraphicsView. ViewportUpdateMode

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

常量

描述

QGraphicsView.FullViewportUpdate

When any visible part of the scene changes or is reexposed, QGraphicsView will update the entire viewport. This approach is fastest when QGraphicsView spends more time figuring out what to draw than it would spend drawing (e.g., when very many small items are repeatedly updated). This is the preferred update mode for viewports that do not support partial updates, such as QOpenGLWidget , 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 is QGraphicsView ‘s default mode. Although this approach provides the best performance in general, if there are many small visible changes on the scene, QGraphicsView might end up spending more time finding the minimal approach than it will spend drawing.

QGraphicsView.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 in QGraphicsView , and is suitable for scenes that either require a fixed frame rate, or where the viewport is otherwise updated externally.

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.

常量

描述

QGraphicsView.DontClipPainter

此值已过时且不起作用。

QGraphicsView.DontSavePainterState

When rendering, QGraphicsView protects the painter state (see 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 setPen() or setBrush() without restoring the state after painting). However, if the items consistently do restore the state, you should enable this flag to prevent QGraphicsView from doing the same.

QGraphicsView.DontAdjustForAntialiasing

Disables QGraphicsView ‘s antialiasing auto-adjustment of exposed areas. Items that render antialiased lines on the boundaries of their boundingRect() can end up rendering parts of the line outside. To prevent rendering artifacts, QGraphicsView expands all exposed regions by 2 pixels in all directions. If you enable this flag, QGraphicsView will no longer perform these adjustments, minimizing the areas that require redrawing, which improves performance. A common side effect is that items that do draw with antialiasing can leave painting traces behind on the scene as they are moved.

QGraphicsView.IndirectPainting

Since Qt 4.6, restore the old painting algorithm that calls drawItems() and drawItems() . To be used only for compatibility with old code.

PySide2.QtWidgets.QGraphicsView. alignment ( )
返回类型

Alignment

另请参阅

setAlignment()

PySide2.QtWidgets.QGraphicsView. backgroundBrush ( )
返回类型

QBrush

PySide2.QtWidgets.QGraphicsView. cacheMode ( )
返回类型

CacheMode

另请参阅

setCacheMode()

PySide2.QtWidgets.QGraphicsView. centerOn ( item )
参数

item QGraphicsItem

这是重载函数。

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

另请参阅

ensureVisible()

PySide2.QtWidgets.QGraphicsView. centerOn ( pos )
参数

pos QPointF

PySide2.QtWidgets.QGraphicsView. centerOn ( x , y )
参数
  • x qreal

  • y qreal

这是重载函数。

This function is provided for convenience. It’s equivalent to calling centerOn ( QPointF ( x , y )).

PySide2.QtWidgets.QGraphicsView. dragMode ( )
返回类型

DragMode

另请参阅

setDragMode()

PySide2.QtWidgets.QGraphicsView. drawBackground ( painter , rect )
参数
  • 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() 代替。

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

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

PySide2.QtWidgets.QGraphicsView. drawForeground ( painter , rect )
参数
  • 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() 代替。

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

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

PySide2.QtWidgets.QGraphicsView. drawItems ( painter , items , options )
参数
  • painter QPainter

  • items QGraphicsItem[]

  • options QStyleOptionGraphicsItem[]

Draws the items items in the scene using painter , after the background and before the foreground are drawn. numItems is the number of items in items and options in options . options is a list of styleoptions; one for each item. Reimplement this function to provide custom item drawing for this view.

The default implementation calls the scene’s function.

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

另请参阅

drawForeground() drawBackground() drawItems()

PySide2.QtWidgets.QGraphicsView. ensureVisible ( item [ , xmargin=50 [ , ymargin=50 ] ] )
参数

这是重载函数。

Scrolls the contents of the viewport so that the center of item item is visible, with margins specified in pixels by xmargin and ymargin . 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.

另请参阅

centerOn()

PySide2.QtWidgets.QGraphicsView. ensureVisible ( rect [ , xmargin=50 [ , ymargin=50 ] ] )
参数
  • rect QRectF

  • xmargin int

  • ymargin int

PySide2.QtWidgets.QGraphicsView. ensureVisible ( x , y , w , h [ , xmargin=50 [ , ymargin=50 ] ] )
参数
  • x qreal

  • y qreal

  • w qreal

  • h qreal

  • xmargin int

  • ymargin int

这是重载函数。

This function is provided for convenience. It’s equivalent to calling ensureVisible ( QRectF ( x , y , w , h ), xmargin , ymargin ).

PySide2.QtWidgets.QGraphicsView. fitInView ( item [ , aspectRadioMode=Qt.IgnoreAspectRatio ] )
参数

这是重载函数。

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

PySide2.QtWidgets.QGraphicsView. fitInView ( x , y , w , h [ , aspectRadioMode=Qt.IgnoreAspectRatio ] )
参数
  • x qreal

  • y qreal

  • w qreal

  • h qreal

  • aspectRadioMode AspectRatioMode

这是重载函数。

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

PySide2.QtWidgets.QGraphicsView. fitInView ( rect [ , aspectRadioMode=Qt.IgnoreAspectRatio ] )
参数
  • rect QRectF

  • aspectRadioMode AspectRatioMode

PySide2.QtWidgets.QGraphicsView. foregroundBrush ( )
返回类型

QBrush

PySide2.QtWidgets.QGraphicsView. invalidateScene ( [ rect=QRectF() [ , layers=QGraphicsScene.AllLayers ] ] )
参数
  • rect QRectF

  • layers SceneLayers

Invalidates and schedules a redraw of layers inside rect . rect is in scene coordinates. Any cached content for layers inside rect is unconditionally invalidated and redrawn.

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

注意: QGraphicsView currently supports background caching only (see CacheBackground ). This function is equivalent to calling update() if any layer but BackgroundLayer 被传递。

另请参阅

invalidate() update()

PySide2.QtWidgets.QGraphicsView. isInteractive ( )
返回类型

bool

PySide2.QtWidgets.QGraphicsView. isTransformed ( )
返回类型

bool

返回 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 )
参数

pos QPoint

返回类型

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.

范例:

def mousePressEvent(self, event):
    if (item = itemAt(event.pos()):
        print "You clicked on item", item
    else:
        print "You didn't click on an item."
											

另请参阅

items() 排序

PySide2.QtWidgets.QGraphicsView. itemAt ( x , y )
参数
  • x int

  • y int

返回类型

QGraphicsItem

这是重载函数。

This function is provided for convenience. It’s equivalent to calling itemAt ( QPoint ( x , y )).

PySide2.QtWidgets.QGraphicsView. items ( )
返回类型

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

另请参阅

items() 排序

PySide2.QtWidgets.QGraphicsView. items ( x , y , w , h [ , mode=Qt.IntersectsItemShape ] )
参数
  • x int

  • y int

  • w int

  • h int

  • mode ItemSelectionMode

返回类型

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

PySide2.QtWidgets.QGraphicsView. items ( x , y )
参数
  • x int

  • y int

返回类型

This function is provided for convenience. It’s equivalent to calling items( QPoint ( x , y )).

PySide2.QtWidgets.QGraphicsView. items ( rect [ , mode=Qt.IntersectsItemShape ] )
参数
  • rect QRect

  • mode ItemSelectionMode

返回类型

PySide2.QtWidgets.QGraphicsView. items ( polygon [ , mode=Qt.IntersectsItemShape ] )
参数
  • polygon QPolygon

  • mode ItemSelectionMode

返回类型

PySide2.QtWidgets.QGraphicsView. items ( pos )
参数

pos QPoint

返回类型

Returns a list of all the items at the position pos in the view. The items are listed in descending stacking order (i.e., the first item in the list is the uppermost item, and the last item is the lowermost item). pos is in viewport coordinates.

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

def mousePressEvent(self, event):
    print "There are", items(event->pos()).size(), "items at position", mapToScene(event->pos())
											

另请参阅

items() 排序

PySide2.QtWidgets.QGraphicsView. items ( path [ , mode=Qt.IntersectsItemShape ] )
参数
  • path QPainterPath

  • mode ItemSelectionMode

返回类型

PySide2.QtWidgets.QGraphicsView. mapFromScene ( path )
参数

path QPainterPath

返回类型

QPainterPath

PySide2.QtWidgets.QGraphicsView. mapFromScene ( point )
参数

point QPointF

返回类型

QPoint

PySide2.QtWidgets.QGraphicsView. mapFromScene ( polygon )
参数

polygon QPolygonF

返回类型

QPolygon

PySide2.QtWidgets.QGraphicsView. mapFromScene ( rect )
参数

rect QRectF

返回类型

QPolygon

PySide2.QtWidgets.QGraphicsView. mapFromScene ( x , y )
参数
  • x qreal

  • y qreal

返回类型

QPoint

This function is provided for convenience. It’s equivalent to calling mapFromScene ( QPointF ( x , y )).

PySide2.QtWidgets.QGraphicsView. mapFromScene ( x , y , w , h )
参数
  • x qreal

  • y qreal

  • w qreal

  • h qreal

返回类型

QPolygon

This function is provided for convenience. It’s equivalent to calling mapFromScene ( QRectF ( x , y , w , h )).

PySide2.QtWidgets.QGraphicsView. mapToScene ( polygon )
参数

polygon QPolygon

返回类型

QPolygonF

PySide2.QtWidgets.QGraphicsView. mapToScene ( x , y , w , h )
参数
  • x int

  • y int

  • w int

  • h int

返回类型

QPolygonF

This function is provided for convenience. It’s equivalent to calling mapToScene ( QRect ( x , y , w , h )).

PySide2.QtWidgets.QGraphicsView. mapToScene ( x , y )
参数
  • x int

  • y int

返回类型

QPointF

This function is provided for convenience. It’s equivalent to calling mapToScene ( QPoint ( x , y )).

PySide2.QtWidgets.QGraphicsView. mapToScene ( rect )
参数

rect QRect

返回类型

QPolygonF

PySide2.QtWidgets.QGraphicsView. mapToScene ( point )
参数

point QPoint

返回类型

QPointF

PySide2.QtWidgets.QGraphicsView. mapToScene ( path )
参数

path QPainterPath

返回类型

QPainterPath

PySide2.QtWidgets.QGraphicsView. matrix ( )
返回类型

QMatrix

注意

此函数被弃用。

使用 transform() 代替。

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

PySide2.QtWidgets.QGraphicsView. optimizationFlags ( )
返回类型

OptimizationFlags

PySide2.QtWidgets.QGraphicsView. render ( painter [ , target=QRectF() [ , source=QRect() [ , aspectRatioMode=Qt.KeepAspectRatio ] ] ] )
参数
  • painter QPainter

  • target QRectF

  • source QRect

  • aspectRatioMode AspectRatioMode

渲染 source rect, which is in view coordinates, from the scene into target , which is in paint device coordinates, using painter . This function is useful for capturing the contents of the view onto a paint device, such as a QImage (e.g., to take a screenshot), or for printing to QPrinter 。例如:

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

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

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

另请参阅

render()

PySide2.QtWidgets.QGraphicsView. renderHints ( )
返回类型

RenderHints

另请参阅

setRenderHints()

PySide2.QtWidgets.QGraphicsView. resetCachedContent ( )

Resets any cached content. Calling this function will clear QGraphicsView ‘s cache. If the current cache mode is CacheNone , this function does nothing.

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

另请参阅

cacheMode()

PySide2.QtWidgets.QGraphicsView. resetMatrix ( )

注意

此函数被弃用。

使用 resetTransform() 代替。

Resets the view transformation matrix to the identity matrix.

另请参阅

resetTransform()

PySide2.QtWidgets.QGraphicsView. resetTransform ( )

Resets the view transformation to the identity matrix.

PySide2.QtWidgets.QGraphicsView. resizeAnchor ( )
返回类型

ViewportAnchor

另请参阅

setResizeAnchor()

PySide2.QtWidgets.QGraphicsView. rotate ( angle )
参数

angle qreal

Rotates the current view transformation angle degrees clockwise.

PySide2.QtWidgets.QGraphicsView. rubberBandChanged ( viewportRect , fromScenePoint , toScenePoint )
参数
  • viewportRect QRect

  • fromScenePoint QPointF

  • toScenePoint QPointF

PySide2.QtWidgets.QGraphicsView. rubberBandRect ( )
返回类型

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 ( )
返回类型

ItemSelectionMode

PySide2.QtWidgets.QGraphicsView. scale ( sx , sy )
参数
  • sx qreal

  • sy qreal

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

PySide2.QtWidgets.QGraphicsView. scene ( )
返回类型

QGraphicsScene

Returns a pointer to the scene that is currently visualized in the view. If no scene is currently visualized, None 被返回。

另请参阅

setScene()

PySide2.QtWidgets.QGraphicsView. sceneRect ( )
返回类型

QRectF

另请参阅

setSceneRect()

PySide2.QtWidgets.QGraphicsView. setAlignment ( alignment )
参数

alignment Alignment

另请参阅

alignment()

PySide2.QtWidgets.QGraphicsView. setBackgroundBrush ( brush )
参数

brush QBrush

另请参阅

backgroundBrush()

PySide2.QtWidgets.QGraphicsView. setCacheMode ( mode )
参数

mode CacheMode

另请参阅

cacheMode()

PySide2.QtWidgets.QGraphicsView. setDragMode ( mode )
参数

mode DragMode

另请参阅

dragMode()

PySide2.QtWidgets.QGraphicsView. setForegroundBrush ( brush )
参数

brush QBrush

另请参阅

foregroundBrush()

PySide2.QtWidgets.QGraphicsView. setInteractive ( allowed )
参数

allowed bool

另请参阅

isInteractive()

PySide2.QtWidgets.QGraphicsView. setMatrix ( matrix [ , combine=false ] )
参数
  • matrix QMatrix

  • combine bool

注意

此函数被弃用。

使用 setTransform() 代替。

Sets the view’s current transformation matrix to matrix .

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

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

范例:

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 提供 mapTo … and mapFrom … functions that can translate between scene and view coordinates. For example, you can call mapToScene() to map a view coordinate to a floating point scene coordinate, or mapFromScene() to map from floating point scene coordinates to view coordinates.

PySide2.QtWidgets.QGraphicsView. setOptimizationFlag ( flag [ , enabled=true ] )
参数

Enables flag if enabled is true; otherwise disables flag .

另请参阅

optimizationFlags

PySide2.QtWidgets.QGraphicsView. setOptimizationFlags ( flags )
参数

flags OptimizationFlags

PySide2.QtWidgets.QGraphicsView. setRenderHint ( hint [ , enabled=true ] )
参数
  • hint RenderHint

  • enabled bool

enabled is true, the render hint hint 被启用;否则它被禁用。

另请参阅

renderHints

PySide2.QtWidgets.QGraphicsView. setRenderHints ( hints )
参数

hints RenderHints

另请参阅

renderHints()

PySide2.QtWidgets.QGraphicsView. setResizeAnchor ( anchor )
参数

anchor ViewportAnchor

另请参阅

resizeAnchor()

PySide2.QtWidgets.QGraphicsView. setRubberBandSelectionMode ( mode )
参数

mode ItemSelectionMode

PySide2.QtWidgets.QGraphicsView. setScene ( scene )
参数

scene QGraphicsScene

Sets the current scene to scene 。若 scene 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’s updateScene() slot, and the view’s scroll bars are adjusted to fit the size of the scene.

The view does not take ownership of scene .

另请参阅

scene()

PySide2.QtWidgets.QGraphicsView. setSceneRect ( rect )
参数

rect QRectF

另请参阅

sceneRect()

PySide2.QtWidgets.QGraphicsView. setSceneRect ( x , y , w , h )
参数
  • x qreal

  • y qreal

  • w qreal

  • h qreal

PySide2.QtWidgets.QGraphicsView. setTransform ( matrix [ , combine=false ] )
参数
  • matrix QTransform

  • combine bool

Sets the view’s current transformation matrix to matrix .

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

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

范例:

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 提供 mapTo … and mapFrom … functions that can translate between scene and view coordinates. For example, you can call mapToScene() to map a view coordiate to a floating point scene coordinate, or mapFromScene() to map from floating point scene coordinates to view coordinates.

PySide2.QtWidgets.QGraphicsView. setTransformationAnchor ( anchor )
参数

anchor ViewportAnchor

PySide2.QtWidgets.QGraphicsView. setViewportUpdateMode ( mode )
参数

mode ViewportUpdateMode

PySide2.QtWidgets.QGraphicsView. shear ( sh , sv )
参数
  • sh qreal

  • sv qreal

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

PySide2.QtWidgets.QGraphicsView. transform ( )
返回类型

QTransform

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

PySide2.QtWidgets.QGraphicsView. transformationAnchor ( )
返回类型

ViewportAnchor

PySide2.QtWidgets.QGraphicsView. translate ( dx , dy )
参数
  • dx qreal

  • dy qreal

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

PySide2.QtWidgets.QGraphicsView. updateScene ( rects )
参数

rects

Schedules an update of the scene rectangles rects .

另请参阅

changed()

PySide2.QtWidgets.QGraphicsView. updateSceneRect ( rect )
参数

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.

PySide2.QtWidgets.QGraphicsView. viewportTransform ( )
返回类型

QTransform

Returns a matrix that maps scene coordinates to viewport coordinates.

PySide2.QtWidgets.QGraphicsView. viewportUpdateMode ( )
返回类型

ViewportUpdateMode