QGraphicsView Class Reference

[ QtGui module]

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

继承 QAbstractScrollArea .

Inherited by QDeclarativeView .

类型

方法


详细描述

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

QGraphicsView 可视化内容,为 QGraphicsScene in a scrollable viewport. To create a scene with geometrical items, see QGraphicsScene 's documentation. QGraphicsView is part of the 图形 View Framework .

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

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

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

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

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

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

QGraphicsView supports affine transformations, using QTransform . You can either pass a matrix to setTransform (),或 you can call one of the convenience functions rotate (), scale (), translate () 或 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 函数 mapToScene () and mapFromScene (), and the item accessors items () 和 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.


类型文档编制

QGraphicsView.CacheModeFlag

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

常量 描述
QGraphicsView.CacheNone 0x0 All painting is done directly onto the viewport.
QGraphicsView.CacheBackground 0x1 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.

The CacheMode type is a typedef for QFlags <CacheModeFlag>. It stores an OR combination of CacheModeFlag values.

另请参阅 cacheMode .

QGraphicsView.DragMode

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

常量 描述
QGraphicsView.NoDrag 0 Nothing happens; the mouse event is ignored.
QGraphicsView.ScrollHandDrag 1 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 2 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.

另请参阅 dragMode and QGraphicsScene.setSelectionArea ().

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 平台。

常量 描述
QGraphicsView.DontClipPainter 0x1 此值已过时且不起作用。
QGraphicsView.DontSavePainterState 0x2 When rendering, QGraphicsView protects the painter state (见 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 () 或 QPainter.setBrush () without restoring the state after painting). However, if the items consistently do restore the state, you should enable this flag to prevent QGraphicsView from doing the same.
QGraphicsView.DontAdjustForAntialiasing 0x4 Disables QGraphicsView 's antialiasing auto-adjustment of exposed areas. Items that render antialiased lines on the boundaries of their QGraphicsItem.boundingRect () can end up rendering parts of the line outside. To prevent rendering artifacts, QGraphicsView expands all exposed regions by 2 pixels in all directions. If you enable this flag, QGraphicsView will no longer perform these adjustments, minimizing the areas that require redrawing, which improves performance. A common side effect is that items that do draw with antialiasing can leave painting traces behind on the scene as they are moved.
QGraphicsView.IndirectPainting 0x8 Since Qt 4.6, restore the old painting algorithm that calls QGraphicsView.drawItems () 和 QGraphicsScene.drawItems (). To be used only for compatibility with old code.

该枚举在 Qt 4.3 引入或被修改。

The OptimizationFlags type is a typedef for QFlags <OptimizationFlag>. It stores an OR combination of OptimizationFlag values.

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 0 No anchor, i.e. the view leaves the scene's position unchanged.
QGraphicsView.AnchorViewCenter 1 The scene point at the center of the view is used as the anchor.
QGraphicsView.AnchorUnderMouse 2 The point under the mouse is used as the anchor.

另请参阅 resizeAnchor and transformationAnchor .

QGraphicsView.ViewportUpdateMode

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

常量 描述
QGraphicsView.FullViewportUpdate 0 When any visible part of the scene changes or is reexposed, QGraphicsView will update the entire viewport. This approach is fastest when QGraphicsView spends more time figuring out what to draw than it would spend drawing (e.g., when very many small items are repeatedly updated). This is the preferred update mode for viewports that do not support partial updates, such as QGLWidget , and for viewports that need to disable scroll optimization.
QGraphicsView.MinimalViewportUpdate 1 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 2 QGraphicsView will attempt to find an optimal update mode by analyzing the areas that require a redraw.
QGraphicsView.BoundingRectViewportUpdate 4 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 3 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.

该枚举在 Qt 4.3 引入或被修改。

另请参阅 viewportUpdateMode .


方法文档编制

QGraphicsView.__init__ ( self , QWidget   parent  = None)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

构造 QGraphicsView . parent 会被传递给 QWidget 's 构造函数。

QGraphicsView.__init__ ( self , QGraphicsScene   scene , QWidget   parent  = None)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

构造 QGraphicsView and sets the visualized scene to scene . parent is passed to QWidget 的构造函数。

Qt.Alignment QGraphicsView.alignment ( self )

QBrush QGraphicsView.backgroundBrush ( self )

CacheMode QGraphicsView.cacheMode ( self )

QGraphicsView.centerOn ( self , QPointF   pos )

Scrolls the contents of the viewport to ensure that the scene coordinate pos , is centered in the view.

因为 pos is a floating point coordinate, and the scroll bars operate on integer coordinates, the centering is only an approximation.

注意: If the item is close to or outside the border, it will be visible in the view, but not centered.

另请参阅 ensureVisible ().

QGraphicsView.centerOn ( self , QGraphicsItem   item )

这是重载函数。

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

QGraphicsView.centerOn ( self , float  ax , float  ay )

这是重载函数。

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

另请参阅 ensureVisible ().

QGraphicsView.contextMenuEvent ( self , QContextMenuEvent   event )

重实现自 QWidget.contextMenuEvent ().

QGraphicsView.dragEnterEvent ( self , QDragEnterEvent   event )

重实现自 QWidget.dragEnterEvent ().

QGraphicsView.dragLeaveEvent ( self , QDragLeaveEvent   event )

重实现自 QWidget.dragLeaveEvent ().

DragMode QGraphicsView.dragMode ( self )

QGraphicsView.dragMoveEvent ( self , QDragMoveEvent   event )

重实现自 QWidget.dragMoveEvent ().

QGraphicsView.drawBackground ( self , QPainter   painter , QRectF   rect )

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 。若 no such brush is defined (the default), the scene's drawBackground() function is called instead.

另请参阅 drawForeground () 和 QGraphicsScene.drawBackground ().

QGraphicsView.drawForeground ( self , QPainter   painter , QRectF   rect )

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 。若 no such brush is defined (the default), the scene's drawForeground() function is called instead.

另请参阅 drawBackground () 和 QGraphicsScene.drawForeground ().

QGraphicsView.drawItems ( self , QPainter   painter , list-of-QGraphicsItem  items , list-of-QStyleOptionGraphicsItem  options )

QGraphicsView.dropEvent ( self , QDropEvent   event )

重实现自 QWidget.dropEvent ().

QGraphicsView.ensureVisible ( self , QRectF   rect , int  xMargin  = 50, int  yMargin  = 50)

Scrolls the contents of the viewport so that the scene rectangle rect is visible, with margins specified in pixels by xmargin and ymargin . If the specified rect cannot be reached, the contents are scrolled to the nearest valid position. The default value for both margins is 50 pixels.

另请参阅 centerOn ().

QGraphicsView.ensureVisible ( self , QGraphicsItem   item , int  xMargin  = 50, int  yMargin  = 50)

这是重载函数。

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

QGraphicsView.ensureVisible ( self , float  x , float  y , float  w , float  h , int  xMargin  = 50, int  yMargin  = 50)

这是重载函数。

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

bool QGraphicsView.event ( self , QEvent   event )

重实现自 QObject.event ().

QGraphicsView.fitInView ( self , QRectF   rect , Qt.AspectRatioMode   mode  = Qt.IgnoreAspectRatio)

Scales the view matrix and scrolls the scroll bars to ensure that the scene rectangle rect fits inside the viewport. rect must be inside the scene rect; otherwise, fitInView() cannot guarantee that the whole rect is visible.

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

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

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

另请参阅 setTransform (), ensureVisible (),和 centerOn ().

QGraphicsView.fitInView ( self , QGraphicsItem   item , Qt.AspectRatioMode   mode  = Qt.IgnoreAspectRatio)

这是重载函数。

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

另请参阅 ensureVisible () 和 centerOn ().

QGraphicsView.fitInView ( self , float  x , float  y , float  w , float  h , Qt.AspectRatioMode   mode  = Qt.IgnoreAspectRatio)

这是重载函数。

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

另请参阅 ensureVisible () 和 centerOn ().

QGraphicsView.focusInEvent ( self , QFocusEvent   event )

重实现自 QWidget.focusInEvent ().

bool QGraphicsView.focusNextPrevChild ( self , bool  next )

重实现自 QWidget.focusNextPrevChild ().

QGraphicsView.focusOutEvent ( self , QFocusEvent   event )

重实现自 QWidget.focusOutEvent ().

QBrush QGraphicsView.foregroundBrush ( self )

QGraphicsView.inputMethodEvent ( self , QInputMethodEvent   event )

重实现自 QWidget.inputMethodEvent ().

QVariant QGraphicsView.inputMethodQuery ( self , Qt.InputMethodQuery   query )

重实现自 QWidget.inputMethodQuery ().

QGraphicsView.invalidateScene ( self , QRectF   rect  = QRectF(), QGraphicsScene.SceneLayers   layers  = QGraphicsScene.AllLayers)

This method is also a Qt slot with the C++ signature void invalidateScene(const QRectF& = QRectF(),QGraphicsScene::SceneLayers = QGraphicsScene.AllLayers) .

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 QGraphicsView.CacheBackground ). 此函数相当于调用 update () if any layer but QGraphicsScene.BackgroundLayer 被传递。

另请参阅 QGraphicsScene.invalidate () and update ().

bool QGraphicsView.isInteractive ( self )

bool QGraphicsView.isTransformed ( self )

Returns true if the view is transformed (i.e., a non-identity transform has been assigned, or the scrollbars are adjusted).

该函数在 Qt 4.6 引入。

另请参阅 setTransform (), horizontalScrollBar (), and verticalScrollBar ().

QGraphicsItem QGraphicsView.itemAt ( self , QPoint   pos )

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.

范例:

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

另请参阅 items () and 排序 .

QGraphicsItem QGraphicsView.itemAt ( self , int  ax , int  ay )

这是重载函数。

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

list-of-QGraphicsItem QGraphicsView.items ( self )

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

另请参阅 QGraphicsScene.items () 和 排序 .

list-of-QGraphicsItem QGraphicsView.items ( self , QPoint   pos )

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 是在 untransformed viewport coordinates, just like QMouseEvent.pos ().

 void CustomView.mousePressEvent(QMouseEvent *event)
 {
     qDebug() << "There are" << items(event->pos()).size()
              << "items at position" << mapToScene(event->pos());
 }
			

另请参阅 QGraphicsScene.items () 和 排序 .

list-of-QGraphicsItem QGraphicsView.items ( self , int  ax , int  ay )

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

list-of-QGraphicsItem QGraphicsView.items ( self , int  x , int  y , int  w , int  h , Qt.ItemSelectionMode   mode  = Qt.IntersectsItemShape)

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

该函数在 Qt 4.3 引入。

list-of-QGraphicsItem QGraphicsView.items ( self , QRect   rect , Qt.ItemSelectionMode   mode  = Qt.IntersectsItemShape)

这是重载函数。

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

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

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

另请参阅 itemAt (), items (), mapToScene (),和 排序 .

list-of-QGraphicsItem QGraphicsView.items ( self , QPolygon   polygon , Qt.ItemSelectionMode   mode  = Qt.IntersectsItemShape)

这是重载函数。

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

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

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

另请参阅 itemAt (), items (), mapToScene (),和 排序 .

list-of-QGraphicsItem QGraphicsView.items ( self , QPainterPath   path , Qt.ItemSelectionMode   mode  = Qt.IntersectsItemShape)

这是重载函数。

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

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

另请参阅 itemAt (), items (), mapToScene (),和 排序 .

QGraphicsView.keyPressEvent ( self , QKeyEvent   event )

重实现自 QWidget.keyPressEvent ().

QGraphicsView.keyReleaseEvent ( self , QKeyEvent   event )

重实现自 QWidget.keyReleaseEvent ().

QPoint QGraphicsView.mapFromScene ( self , QPointF   point )

Returns the scene coordinate point to viewport coordinates.

另请参阅 mapToScene ().

QPolygon QGraphicsView.mapFromScene ( self , QRectF   rect )

Returns the scene rectangle rect to a viewport coordinate polygon.

另请参阅 mapToScene ().

QPolygon QGraphicsView.mapFromScene ( self , QPolygonF   polygon )

Returns the scene coordinate polygon polygon 到 viewport coordinate polygon.

另请参阅 mapToScene ().

QPainterPath QGraphicsView.mapFromScene ( self , QPainterPath   path )

Returns the scene coordinate painter path path 到 viewport coordinate painter path.

另请参阅 mapToScene ().

QPoint QGraphicsView.mapFromScene ( self , float  ax , float  ay )

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

QPolygon QGraphicsView.mapFromScene ( self , float  ax , float  ay , float  w , float  h )

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

QPointF QGraphicsView.mapToScene ( self , QPoint   point )

Returns the viewport coordinate point mapped to scene coordinates.

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

另请参阅 mapFromScene ().

QPolygonF QGraphicsView.mapToScene ( self , QRect   rect )

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

另请参阅 mapFromScene ().

QPolygonF QGraphicsView.mapToScene ( self , QPolygon   polygon )

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

另请参阅 mapFromScene ().

QPainterPath QGraphicsView.mapToScene ( self , QPainterPath   path )

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

另请参阅 mapFromScene ().

QPointF QGraphicsView.mapToScene ( self , int  ax , int  ay )

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

QPolygonF QGraphicsView.mapToScene ( self , int  ax , int  ay , int  w , int  h )

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

QMatrix QGraphicsView.matrix ( self )

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

另请参阅 setMatrix (), transform (), rotate (), scale (), shear (),和 translate ().

QGraphicsView.mouseDoubleClickEvent ( self , QMouseEvent   event )

重实现自 QWidget.mouseDoubleClickEvent ().

QGraphicsView.mouseMoveEvent ( self , QMouseEvent   event )

重实现自 QWidget.mouseMoveEvent ().

QGraphicsView.mousePressEvent ( self , QMouseEvent   event )

重实现自 QWidget.mousePressEvent ().

QGraphicsView.mouseReleaseEvent ( self , QMouseEvent   event )

重实现自 QWidget.mouseReleaseEvent ().

OptimizationFlags QGraphicsView.optimizationFlags ( self )

QGraphicsView.paintEvent ( self , QPaintEvent   event )

重实现自 QWidget.paintEvent ().

QGraphicsView.render ( self , QPainter   painter , QRectF   target  = QRectF(), QRect   source  = QRect(), Qt.AspectRatioMode   mode  = Qt.KeepAspectRatio)

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

 QGraphicsScene scene;
 scene.addItem(...
 ...
 QGraphicsView view(&scene);
 view.show();
 ...
 QPrinter printer(QPrinter.HighResolution);
 printer.setPageSize(QPrinter.A4);
 QPainter painter(&printer);
 // print, fitting the viewport contents into a full page
 view.render(&painter);
 // print the upper half of the viewport into the lower.
 // half of the page.
 QRect viewport = view.viewport()->rect();
 view.render(&painter,
             QRectF(0, printer.height() / 2,
                    printer.width(), printer.height() / 2),
             viewport.adjusted(0, 0, 0, -viewport.height() / 2));
			

source is a null rect, this function will use 视口 ()-> 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 .

另请参阅 QGraphicsScene.render ().

QPainter.RenderHints QGraphicsView.renderHints ( self )

QGraphicsView.resetCachedContent ( self )

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

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

另请参阅 cacheMode ().

QGraphicsView.resetMatrix ( self )

Resets the view transformation matrix to the identity matrix.

另请参阅 resetTransform ().

QGraphicsView.resetTransform ( self )

Resets the view transformation to the identity matrix.

另请参阅 transform () 和 setTransform ().

ViewportAnchor QGraphicsView.resizeAnchor ( self )

QGraphicsView.resizeEvent ( self , QResizeEvent   event )

重实现自 QWidget.resizeEvent ().

QGraphicsView.rotate ( self , float  angle )

Rotates the current view transformation angle degrees clockwise.

另请参阅 setTransform (), transform (), scale (), shear (),和 translate ().

Qt.ItemSelectionMode QGraphicsView.rubberBandSelectionMode ( self )

QGraphicsView.scale ( self , float  sx , float  sy )

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

另请参阅 setTransform (), transform (), rotate (), shear (),和 translate ().

QGraphicsScene QGraphicsView.scene ( self )

Returns a pointer to the scene that is currently visualized in the view. If no scene is currently visualized, 0 is returned.

另请参阅 setScene ().

QRectF QGraphicsView.sceneRect ( self )

QGraphicsView.scrollContentsBy ( self , int  dx , int  dy )

重实现自 QAbstractScrollArea.scrollContentsBy ().

QGraphicsView.setAlignment ( self , Qt.Alignment   alignment )

QGraphicsView.setBackgroundBrush ( self , QBrush   brush )

QGraphicsView.setCacheMode ( self , CacheMode   mode )

QGraphicsView.setDragMode ( self , DragMode   mode )

QGraphicsView.setForegroundBrush ( self , QBrush   brush )

QGraphicsView.setInteractive ( self , bool  allowed )

QGraphicsView.setMatrix ( self , QMatrix   matrix , bool  combine  = False)

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

范例:

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

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

另请参阅 matrix (), setTransform (), rotate (), scale (), shear (),和 translate ().

QGraphicsView.setOptimizationFlag ( self , OptimizationFlag   flag , bool  enabled  = True)

Enables flag if enabled is true; otherwise disables flag .

另请参阅 optimizationFlags .

QGraphicsView.setOptimizationFlags ( self , OptimizationFlags   flags )

QGraphicsView.setRenderHint ( self , QPainter.RenderHint   hint , bool  on  = True)

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

另请参阅 renderHints .

QGraphicsView.setRenderHints ( self , QPainter.RenderHints   hints )

QGraphicsView.setResizeAnchor ( self , ViewportAnchor   anchor )

QGraphicsView.setRubberBandSelectionMode ( self , Qt.ItemSelectionMode   mode )

QGraphicsView.setScene ( self , QGraphicsScene   scene )

Sets the current scene to scene 。若 scene is already being viewed, this function does nothing.

When a scene is set on a view, the QGraphicsScene.changed () signal is automatically connected to this view's updateScene () slot, and the view's scroll bars are adjusted to fit the size of the scene.

另请参阅 scene ().

QGraphicsView.setSceneRect ( self , QRectF   rect )

QGraphicsView.setSceneRect ( self , float  ax , float  ay , float  aw , float  ah )

QGraphicsView.setTransform ( self , QTransform   matrix , bool  combine  = False)

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

范例:

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

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

另请参阅 transform (), rotate (), scale (), shear (),和 translate ().

QGraphicsView.setTransformationAnchor ( self , ViewportAnchor   anchor )

QGraphicsView.setupViewport ( self , QWidget   widget )

This method is also a Qt slot with the C++ signature void setupViewport(QWidget*) .

This slot is called by QAbstractScrollArea after setViewport () has been called. Reimplement this function in a subclass of QGraphicsView to initialize the new 视口 widget before it is used.

另请参阅 setViewport ().

QGraphicsView.setViewportUpdateMode ( self , ViewportUpdateMode   mode )

QGraphicsView.shear ( self , float  sh , float  sv )

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

另请参阅 setTransform (), transform (), rotate (), scale (),和 translate ().

QGraphicsView.showEvent ( self , QShowEvent   event )

重实现自 QWidget.showEvent ().

QSize QGraphicsView.sizeHint ( self )

重实现自 QWidget.sizeHint ().

QTransform QGraphicsView.transform ( self )

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

另请参阅 setTransform (), rotate (), scale (), shear (),和 translate ().

ViewportAnchor QGraphicsView.transformationAnchor ( self )

QGraphicsView.translate ( self , float  dx , float  dy )

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

另请参阅 setTransform (), transform (), rotate (),和 shear ().

QGraphicsView.updateScene ( self , list-of-QRectF  rects )

This method is also a Qt slot with the C++ signature void updateScene(const QList<QRectF>&) .

Schedules an update of the scene rectangles rects .

另请参阅 QGraphicsScene.changed ().

QGraphicsView.updateSceneRect ( self , QRectF   rect )

This method is also a Qt slot with the C++ signature void updateSceneRect(const 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.

另请参阅 sceneRect and QGraphicsScene.sceneRectChanged ().

bool QGraphicsView.viewportEvent ( self , QEvent   event )

重实现自 QAbstractScrollArea.viewportEvent ().

QTransform QGraphicsView.viewportTransform ( self )

Returns a matrix that maps viewport coordinates to scene coordinates.

另请参阅 mapToScene () 和 mapFromScene ().

ViewportUpdateMode QGraphicsView.viewportUpdateMode ( self )

QGraphicsView.wheelEvent ( self , QWheelEvent   event )

重实现自 QWidget.wheelEvent ().