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

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

paint(self, painter: Optional[QPainter], option: Optional[QStyleOptionGraphicsItem], widget: Optional[QWidget] = None)

Parameters:

painter (Optional[QPainter])

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