class pyqtgraph.GraphicsItem[source]#

Bases: object

Abstract class providing useful methods to GraphicsObject and GraphicsWidget. (This is required because we cannot have multiple inheritance with QObject subclasses.)

A note about Qt’s GraphicsView framework:

The GraphicsView system places a lot of emphasis on the notion that the graphics within the scene should be device independent–you should be able to take the same graphics and display them on screens of different resolutions, printers, export to SVG, etc. This is nice in principle, but causes me a lot of headache in practice. It means that I have to circumvent all the device-independent expectations any time I want to operate in pixel coordinates rather than arbitrary scene coordinates. A lot of the code in GraphicsItem is devoted to this task–keeping track of view widgets and device transforms, computing the size and shape of a pixel in local item coordinates, etc. Note that in item coordinates, a pixel does not have to be square or even rectangular, so just asking how to increase a bounding rect by 2px can be a rather complex task.


Return list of the entire item tree descending from this item.


Called when the item’s parent has changed. This method handles connecting / disconnecting from ViewBox signals to make sure viewRangeChanged works properly. It should generally be extended, not overridden.


Return the union of the shapes of all descendants of this item in local coordinates.


Return the transform that converts local item coordinates to device coordinates (usually pixels). Extends deviceTransform to automatically determine the viewportTransform.


Method to override to manually specify the SVG writer mechanism.


nodes (dict[str, Element]) – Dictionary keyed by the name of graphics items and the XML representation of the the item that can be written as valid SVG.

Return type:

Optional[tuple[Element, list[Element]]]


  • tuple – First element is the top level group for this item. The second element is a list of xml Elements corresponding to the child nodes of the item.

  • None – Return None if no XML is needed for rendering


NotImplementedError – override method to implement in subclasses of GraphicsItem

See also


The generic and default implementation


Return a list of parents to this item that have child clipping enabled.


Return the first ViewBox or GraphicsView which bounds this item’s visible space. If this item is not contained within a ViewBox, then the GraphicsView is returned. If the item is contained inside nested ViewBoxes, then the inner-most ViewBox is returned. The result is cached; clear the cache with forgetViewBox()


Return the view widget for this item.

If the scene has multiple views, only the first view is returned. The return value is cached; clear the cached value with forgetViewWidget(). If the view has been deleted by Qt, return None.


Inform this item’s container ViewBox that the bounds of this item have changed. This is used by ViewBox to react if auto-range is enabled.


Return obj mapped from device coordinates (pixels) to local coordinates. If there is no device mapping available, return None.


Return rect mapped from device coordinates (pixels) to local coordinates. If there is no device mapping available, return None.


Return rect mapped from local coordinates to device coordinates (pixels). If there is no device mapping available, return None.


Return obj mapped from local coordinates to device coordinates (pixels). If there is no device mapping available, return None.

pixelLength(direction, ortho=False)[source]#

Return the length of one pixel in the direction indicated (in local coordinates) If ortho=True, then return the length of one pixel orthogonal to the direction indicated.

Return None if pixel size is not yet defined (usually because the item has not yet been displayed).


Return vectors in local coordinates representing the width and height of a view pixel. If direction is specified, then return vectors parallel and orthogonal to it.

Return (None, None) if pixel size is not yet defined (usually because the item has not yet been displayed) or if pixel size is below floating-point precision limit.

setExportMode(export, opts=None)[source]#

This method is called by exporters to inform items that they are being drawn for export with a specific set of options. Items access these via self._exportOptions. When exporting is complete, _exportOptions is set to False.


Return the rotation produced by this item’s transform (this assumes there is no shear in the transform) If relativeItem is given, then the angle is determined relative to that item.

viewChanged(view, oldView)[source]#

Called when this item’s view has changed (ie, the item has been added to or removed from a ViewBox)


Called whenever the view coordinates of the ViewBox containing this item have changed.


Return the visible bounds of this item’s ViewBox or GraphicsWidget, in the local coordinate system of the item.


Return the transform that maps from local coordinates to the item’s ViewBox coordinates If there is no ViewBox, return the scene transform. Returns None if the item does not have a view.


Called whenever the transformation matrix of the view has changed. (eg, the view range has changed or the view was resized) Invalidates the viewRect cache.