Class: QgsLayoutItemMapItem

An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: draw()

Class Hierarchy

Inheritance diagram of qgis.core.QgsLayoutItemMapItem

Base classes

QgsLayoutObject

A base class for objects which belong to a layout.

QObject

QgsExpressionContextGenerator

Abstract interface for generating an expression context.

Subclasses

QgsLayoutItemMapGrid

An individual grid which is drawn above the map content in a QgsLayoutItemMap.

QgsLayoutItemMapOverview

An individual overview which is drawn above the map content in a QgsLayoutItemMap, and shows the extent of another QgsLayoutItemMap.

Abstract Methods

draw

Draws the item on to a destination painter.

Methods

enabled

Returns whether the item will be drawn.

id

Returns the unique id for the map item.

map

Returns the layout item map for the item.

name

Returns the friendly display name for the item.

setMap

Sets the corresponding layout map for the item.

setName

Sets the friendly display name for the item.

setStackingLayer

Sets the item's stacking layer, which specifies where the in the map's stack the item should be rendered.

setStackingPosition

Sets the item's stacking position, which specifies where the in the map's stack the item should be rendered.

stackingLayer

Returns the item's stacking layer, which specifies where the in the map's stack the item should be rendered.

stackingPosition

Returns the item's stacking position, which specifies where the in the map's stack the item should be rendered.

Virtual Methods

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

accept

Accepts the specified style entity visitor, causing it to visit all style entities associated with the map item.

finalizeRestoreFromXml

Called after all pending items have been restored from XML.

mapLayer

Returns the internal map layer used by this item, if available.

readXml

Sets the map item state from a DOM document, where element is the DOM node corresponding to a 'LayoutMapGrid' tag.

setEnabled

Controls whether the item will be drawn.

usesAdvancedEffects

Returns True if the item is drawn using advanced effects, such as blend modes.

writeXml

Stores map item state in a DOM element, where element is the DOM element corresponding to a 'LayoutMap' tag.

Attributes

StackAboveMapLabels

StackAboveMapLayer

StackBelowMap

StackBelowMapLabels

StackBelowMapLayer

class qgis.core.QgsLayoutItemMapItem[source]

Bases: QgsLayoutObject

__init__(name: str | None, map: QgsLayoutItemMap | None)

Constructor for QgsLayoutItemMapItem, attached to the specified map.

The name argument gives a friendly display name for the item.

Parameters:
StackAboveMapLabels = 4
StackAboveMapLayer = 2
StackBelowMap = 0
StackBelowMapLabels = 3
StackBelowMapLayer = 1
class StackingPosition

Bases: int

virtual accept(self, visitor: QgsStyleEntityVisitorInterface | None) bool[source]

Accepts the specified style entity visitor, causing it to visit all style entities associated with the map item.

Returns True if the visitor should continue visiting other objects, or False if visiting should be canceled.

Added in version 3.10.

Parameters:

visitor (Optional[QgsStyleEntityVisitorInterface])

Return type:

bool

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

Draws the item on to a destination painter.

Parameters:

painter (Optional[QPainter])

enabled(self) bool[source]

Returns whether the item will be drawn.

See also

setEnabled()

Return type:

bool

virtual finalizeRestoreFromXml(self)[source]

Called after all pending items have been restored from XML. Map items can use this method to run steps which must take place after all items have been restored to the layout, such as connecting to signals emitted by other items, which may not have existed in the layout at the time readXml() was called. E.g. an overview can use this to connect to its linked map item after restoration from XML.

See also

readXml()

id(self) str[source]

Returns the unique id for the map item.

Return type:

str

map(self) QgsLayoutItemMap | None[source]

Returns the layout item map for the item.

See also

setMap()

Return type:

Optional[QgsLayoutItemMap]

virtual mapLayer(self) QgsMapLayer | None[source]

Returns the internal map layer used by this item, if available.

Added in version 3.10.1.

Return type:

Optional[QgsMapLayer]

name(self) str[source]

Returns the friendly display name for the item.

See also

setName()

Return type:

str

virtual readXml(self, element: QDomElement, doc: QDomDocument, context: QgsReadWriteContext) bool[source]

Sets the map item state from a DOM document, where element is the DOM node corresponding to a ‘LayoutMapGrid’ tag.

See also

writeXml()

Parameters:
Return type:

bool

virtual setEnabled(self, enabled: bool)[source]

Controls whether the item will be drawn. Set enabled to True to enable drawing of the item.

See also

enabled()

Parameters:

enabled (bool)

setMap(self, map: QgsLayoutItemMap | None)[source]

Sets the corresponding layout map for the item.

See also

map()

Parameters:

map (Optional[QgsLayoutItemMap])

setName(self, name: str | None)[source]

Sets the friendly display name for the item.

See also

name()

Parameters:

name (Optional[str])

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

Sets the item’s stacking layer, which specifies where the in the map’s stack the item should be rendered.

This setting is only used when stackingPosition() is StackBelowMapLayer or StackAboveMapLayer.

See also

stackingLayer()

Added in version 3.6.

Parameters:

layer (Optional[QgsMapLayer])

setStackingPosition(self, position: QgsLayoutItemMapItem.StackingPosition)[source]

Sets the item’s stacking position, which specifies where the in the map’s stack the item should be rendered.

Added in version 3.6.

Parameters:

position (QgsLayoutItemMapItem.StackingPosition)

stackingLayer(self) QgsMapLayer | None[source]

Returns the item’s stacking layer, which specifies where the in the map’s stack the item should be rendered.

This setting is only used when stackingPosition() is StackBelowMapLayer or StackAboveMapLayer.

Added in version 3.6.

Return type:

Optional[QgsMapLayer]

stackingPosition(self) QgsLayoutItemMapItem.StackingPosition[source]

Returns the item’s stacking position, which specifies where the in the map’s stack the item should be rendered.

See also

stackingLayer()

Added in version 3.6.

Return type:

QgsLayoutItemMapItem.StackingPosition

virtual usesAdvancedEffects(self) bool[source]

Returns True if the item is drawn using advanced effects, such as blend modes.

Return type:

bool

virtual writeXml(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool[source]

Stores map item state in a DOM element, where element is the DOM element corresponding to a ‘LayoutMap’ tag.

See also

readXml()

Parameters:
Return type:

bool