Class: QgsMapCanvasItem

An abstract class for items that can be placed on the map canvas.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsMapCanvasItem

Base classes

QGraphicsItem

Subclasses

QgsAdvancedDigitizingCanvasItem

Draws the graphical elements of the CAD tools (QgsAdvancedDigitizingDockWidget) on the map canvas.

QgsGeometryRubberBand

A rubberband class for QgsAbstractGeometry (considering curved geometries).

QgsHighlight

Highlights features on the map.

QgsMapCanvasAnnotationItem

An interactive map canvas item which displays a QgsAnnotation.

QgsRubberBand

Responsible for drawing transient features (e.g. digitizing lines) on the map.

QgsSnapToGridCanvasItem

Shows a grid on the map canvas given a spatial resolution.

QgsVertexMarker

A map canvas item for marking vertices of features using e.g. circles or ‘x’.

Abstract Methods

paint

function to be implemented by derived classes

Methods

rect

returns canvas item rectangle in map units

setRect

sets canvas item rectangle in map units

setRenderContextVariables

Sets render context parameters

toCanvasCoordinates

transformation from map coordinates to screen coordinates

toMapCoordinates

transformation from screen coordinates to map coordinates

updateCanvas

schedules map canvas for repaint

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsMapCanvasItem. See the FAQ for more details.

updatePosition

called on changed extent or resize event to update position of the item

class qgis.gui.QgsMapCanvasItem[source]

Bases: QGraphicsItem

__init__(mapCanvas: QgsMapCanvas | None)

protected constructor: cannot be constructed directly

Parameters:

mapCanvas (Optional[QgsMapCanvas])

abstract paint(self, painter: QPainter | None)[source]

function to be implemented by derived classes

Parameters:

painter (Optional[QPainter])

abstract paint(self, painter: QPainter | None, option: QStyleOptionGraphicsItem | None, widget: QWidget | None = None)[source]
Parameters:
  • painter (Optional[QPainter])

  • option (Optional[QStyleOptionGraphicsItem])

  • widget (Optional[QWidget] = None)

rect(self) QgsRectangle[source]

returns canvas item rectangle in map units

Return type:

QgsRectangle

setRect(self, r: QgsRectangle, resetRotation: bool = True)[source]

sets canvas item rectangle in map units

Parameters:
setRenderContextVariables(self, p: QPainter | None, context: QgsRenderContext) bool[source]

Sets render context parameters

Parameters:
  • p (Optional[QPainter]) – painter for rendering

  • context (QgsRenderContext) – out: configured context

Return type:

bool

Returns:

True in case of success

toCanvasCoordinates(self, point: QgsPointXY) QPointF[source]

transformation from map coordinates to screen coordinates

Parameters:

point (QgsPointXY)

Return type:

QPointF

toMapCoordinates(self, point: QPoint) QgsPointXY[source]

transformation from screen coordinates to map coordinates

Parameters:

point (QPoint)

Return type:

QgsPointXY

updateCanvas(self)[source]

schedules map canvas for repaint

virtual updatePosition(self)[source]

called on changed extent or resize event to update position of the item