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

The QgsAdvancedDigitizingCanvasItem class draws the graphical elements of the CAD tools (QgsAdvancedDigitizingDockWidget) on the map canvas.

QgsGeometryRubberBand

A rubberband class for QgsAbstractGeometry (considering curved geometries).

QgsHighlight

A class for highlight features on the map.

QgsMapCanvasAnnotationItem

An interactive map canvas item which displays a QgsAnnotation.

QgsRubberBand

A class 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 class for marking vertices of features using e.g. circles or ‘x’.

Methods

paint

function to be implemented by derived classes

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

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

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

function to be implemented by derived classes

Parameters:

painter (Optional[QPainter])

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

updatePosition(self)[source]

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