Bases: GraphicsWidget
Box that allows internal scaling/panning of children by mouse drag. This class is usually created automatically as part of a PlotItem or Canvas or with GraphicsLayout.addViewBox().
Features:
- Scaling contents by mouse or auto-scale when contents change
- View linking–multiple views display the same data ranges
- Configurable by context menu
- Item coordinate mapping methods
Not really compatible with GraphicsView having the same functionality.
Arguments | |
parent | (QGraphicsWidget) Optional parent widget |
border | (QPen) Do draw a border around the view, give any single argument accepted by mkPen |
lockAspect | (False or float) The aspect ratio to lock the view coorinates to. (or False to allow the ratio to change) |
enableMouse | (bool) Whether mouse can be used to scale/pan the view |
invertY | (bool) See invertY |
Add a QGraphicsItem to this view. The view will include this item when determining how to set its range automatically unless ignoreBounds is True.
Return a list of all children and grandchildren of this ViewBox
Set the range of the view box to make all children visible. Note that this is not the same as enableAutoRange, which causes the view to automatically auto-range whenever its contents are changed.
Return the transform that maps from child(item in the childGroup) coordinates to local coordinates. (This maps from inside the viewbox to outside)
Return the bounding range of all children. [[xmin, xmax], [ymin, ymax]] Values may be None if there are no specific bounds for an axis.
Disables auto-range. (See enableAutoRange)
Enable (or disable) auto-range for axis, which may be ViewBox.XAxis, ViewBox.YAxis, or ViewBox.XYAxes for both (if axis is omitted, both axes will be changed). When enabled, the axis will automatically rescale when items are added/removed or change their shape. The argument enable may optionally be a float (0.0-1.0) which indicates the fraction of the data that should be visible (this only works with items implementing a dataRange method, such as PlotDataItem).
Return the current state of the ViewBox. Linked views are always converted to view names in the returned state.
By default, the positive y-axis points upward on the screen. Use invertY(True) to reverse the y-axis.
Return the bounding rect of the item in view coordinates
This routine should capture key presses in the current view box. Key presses are used only when mouse mode is RectMode The following events are implemented: ctrl-A : zooms out to the default “full” view of the plot ctrl-+ : moves forward in the zooming stack (if it exists) ctrl– : moves backward in the zooming stack (if it exists)
Link X or Y axes of two views and unlink any previously connected axes. axis must be ViewBox.XAxis or ViewBox.YAxis. If view is None, the axis is left unlinked.
Temporarily display the bounding rect of an item and lines connecting to the center of the view. This is useful for determining the location of items that may be out of the range of the ViewBox. if allChildren is True, then the bounding rect of all item’s children will be shown instead.
Maps obj from the local coordinate system of item to the view coordinates
Maps from the coordinate system displayed inside the ViewBox to the local coordinates of the ViewBox
Maps obj from view coordinates to the local coordinate system of item.
Maps from scene coordinates to the coordinate system displayed inside the ViewBox
Maps from the local coordinates of the ViewBox to the coordinate system displayed inside the ViewBox
Maps from the coordinate system displayed inside the ViewBox to scene coordinates
Add this ViewBox to the registered list of views. name will appear in the drop-down lists for axis linking in all other views. The same can be accomplished by initializing the ViewBox with the name attribute.
Remove an item from this view.
Scale by s around given center point (or center of view). s may be a Point or tuple (x, y)
return the screen geometry of the viewbox
If the aspect ratio is locked, view scaling must always preserve the aspect ratio. By default, the ratio is set to 1; x and y both have the same scaling. This ratio can be overridden (width/height), or use None to lock in the current ratio.
Set whether each axis is enabled for mouse interaction. x, y arguments must be True or False. This allows the user to pan/scale one axis of the view while leaving the other axis unchanged.
Set the mouse interaction mode. mode must be either ViewBox.PanMode or ViewBox.RectMode. In PanMode, the left mouse button pans the view and the right button scales. In RectMode, the left button draws a rectangle which updates the visible region (this mode is more suitable for single-button mice)
Set the visible range of the ViewBox. Must specify at least one of range, xRange, or yRange.
Arguments | |
rect | (QRectF) The full range that should be visible in the view box. |
xRange | (min,max) The range that should be visible along the x-axis. |
yRange | (min,max) The range that should be visible along the y-axis. |
padding | (float) Expand the view by a fraction of the requested range. By default, this value is 0.02 (2%) |
Restore the state of this ViewBox. (see also getState)
Link this view’s X axis to another view. (see LinkView)
Set the visible X range of the view to [min, max]. The padding argument causes the range to be set larger by the fraction specified.
Link this view’s Y axis to another view. (see LinkView)
Set the visible Y range of the view to [min, max]. The padding argument causes the range to be set larger by the fraction specified.
Return the region which has been requested to be visible. (this is not necessarily the same as the region that is actually visible– resizing and aspect ratio constraints can cause targetRect() and viewRect() to differ)
Translate the view by t, which may be a Point or tuple (x, y).
Remove this ViewBox forom the list of linkable views. (see register())
Return the (width, height) of a screen pixel in view coordinates.
Return a the view’s visible range as a list: [[xmin, xmax], [ymin, ymax]]
Return a QRectF bounding the region visible within the ViewBox