Class: QgsAnnotationLayer

Represents a map layer containing a set of georeferenced annotations, e.g. markers, lines, polygons or text items.

Annotation layers store a set of QgsAnnotationItem items, which are rendered according to the item’s z-order.

Added in version 3.16.

Class Hierarchy

Inheritance diagram of qgis.core.QgsAnnotationLayer

Base classes

QgsMapLayer

Base class for all map layer types.

QObject

Methods

addItem

Adds an item to the layer.

applyEdit

Applies an edit operation to the layer.

applyEditV2

Applies an edit operation to the layer.

clear

Removes all items from the layer.

isEmpty

Returns True if the annotation layer is empty and contains no annotations.

item

Returns the item with the specified id, or None if no matching item was found.

items

Returns a map of items contained in the layer, by unique item ID.

itemsInBounds

Returns a list of the IDs of all annotation items within the specified bounds (in layer CRS), when rendered using the given render context.

linkedVisibilityLayer

Returns a linked layer, where the items in this annotation layer will only be visible when the linked layer is also visible.

paintEffect

Returns the current paint effect for the layer.

removeItem

Removes (and deletes) the item with matching id.

replaceItem

Replaces the existing item with matching id with a new item.

reset

Resets the annotation layer to a default state, and clears all items from it.

setLinkedVisibilityLayer

Sets a linked layer, where the items in this annotation layer will only be visible when the linked layer is also visible.

setPaintEffect

Sets the current paint effect for the layer.

class qgis.core.QgsAnnotationLayer[source]

Bases: QgsMapLayer

__init__(name: str | None, options: QgsAnnotationLayer.LayerOptions)

Constructor for a new QgsAnnotationLayer with the specified layer name.

The options argument specifies load-time layer options.

Parameters:
class LayerOptions

Bases: object

Setting options for loading annotation layers.

Added in version 3.16.

addItem(self, item: QgsAnnotationItem | None) str[source]

Adds an item to the layer.

Ownership of item is transferred to the layer.

Returns the unique ID assigned to the item.

Parameters:

item (Optional[QgsAnnotationItem])

Return type:

str

applyEdit(self, operation: QgsAbstractAnnotationItemEditOperation | None) Qgis.AnnotationItemEditOperationResult[source]

Applies an edit operation to the layer.

Returns True if the operation was successfully applied.

Deprecated since version 3.40: Use applyEditV2() instead.

Parameters:

operation (Optional[QgsAbstractAnnotationItemEditOperation])

Return type:

Qgis.AnnotationItemEditOperationResult

applyEditV2(self, operation: QgsAbstractAnnotationItemEditOperation | None, context: QgsAnnotationItemEditContext) Qgis.AnnotationItemEditOperationResult[source]

Applies an edit operation to the layer.

Returns True if the operation was successfully applied.

Added in version 3.40.

Parameters:
Return type:

Qgis.AnnotationItemEditOperationResult

clear(self)[source]

Removes all items from the layer.

isEmpty(self) bool[source]

Returns True if the annotation layer is empty and contains no annotations.

Return type:

bool

item(self, id: str | None) QgsAnnotationItem | None[source]

Returns the item with the specified id, or None if no matching item was found.

Added in version 3.22.

Parameters:

id (Optional[str])

Return type:

Optional[QgsAnnotationItem]

items(self) Any

Returns a map of items contained in the layer, by unique item ID.

This map contains references to items owned by the layer, and ownership of these remains with the layer.

Return type:

Any

itemsInBounds(self, bounds: QgsRectangle, context: QgsRenderContext, feedback: QgsFeedback | None = None) List[str][source]

Returns a list of the IDs of all annotation items within the specified bounds (in layer CRS), when rendered using the given render context.

The optional feedback argument can be used to cancel the search early.

Added in version 3.22.

Parameters:
Return type:

List[str]

linkedVisibilityLayer(self) QgsMapLayer | None[source]

Returns a linked layer, where the items in this annotation layer will only be visible when the linked layer is also visible.

Added in version 3.40.

Return type:

Optional[QgsMapLayer]

paintEffect(self) QgsPaintEffect | None[source]

Returns the current paint effect for the layer.

See also

setPaintEffect()

Added in version 3.22.

Return type:

Optional[QgsPaintEffect]

removeItem(self, id: str | None) bool[source]

Removes (and deletes) the item with matching id.

Parameters:

id (Optional[str])

Return type:

bool

replaceItem(self, id: str | None, item: QgsAnnotationItem | None)[source]

Replaces the existing item with matching id with a new item.

Ownership of item is transferred to the layer.

Added in version 3.22.

Parameters:
reset(self)[source]

Resets the annotation layer to a default state, and clears all items from it.

setLinkedVisibilityLayer(self, layer: QgsMapLayer | None)[source]

Sets a linked layer, where the items in this annotation layer will only be visible when the linked layer is also visible.

Added in version 3.40.

Parameters:

layer (Optional[QgsMapLayer])

setPaintEffect(self, effect: QgsPaintEffect | None)[source]

Sets the current paint effect for the layer.

Ownership is transferred to the renderer.

See also

paintEffect()

Added in version 3.22.

Parameters:

effect (Optional[QgsPaintEffect])