Class: QgsLayoutItemMapGridStack

A collection of grids which is drawn above the map content in a QgsLayoutItemMap. The grid stack controls which grids are drawn and the order they are drawn in.

Class Hierarchy

Inheritance diagram of qgis.core.QgsLayoutItemMapGridStack

Base classes

QgsLayoutItemMapItemStack

A collection of map items which are drawn above the map content in a QgsLayoutItemMap. The item stack controls which items are drawn and the order they are drawn in.

Methods

addGrid

Adds a new map grid to the stack and takes ownership of the grid.

asList

Returns a list of QgsLayoutItemMapGrids contained by the stack.

calculateMaxGridExtension

Calculates the maximum distance grids within the stack extend beyond the QgsLayoutItemMap's item rect.

grid

Returns a reference to a grid with matching gridId within the stack.

maxGridExtension

Calculates the maximum distance grids within the stack extend beyond the QgsLayoutItemMap's item rect.

moveGridDown

Moves a grid with matching gridId down the stack, causing it to be rendered below other grids.

moveGridUp

Moves a grid with matching gridId up the stack, causing it to be rendered above other grids.

removeGrid

Removes a grid with matching gridId from the stack and deletes the corresponding QgsLayoutItemMapGrid.

class qgis.core.QgsLayoutItemMapGridStack[source]

Bases: QgsLayoutItemMapItemStack

__init__(map: QgsLayoutItemMap | None)

Constructor for QgsLayoutItemMapGridStack, attached to the specified map.

Parameters:

map (Optional[QgsLayoutItemMap])

__init__(a0: QgsLayoutItemMapGridStack)
Parameters:

a0 (QgsLayoutItemMapGridStack)

addGrid(self, grid: QgsLayoutItemMapGrid | None)[source]

Adds a new map grid to the stack and takes ownership of the grid. The grid will be added to the end of the stack, and rendered above any existing map grids already present in the stack.

Note

After adding a grid to the stack, updateBoundingRect() and update() should be called for the QgsLayoutItemMap to prevent rendering artifacts.

See also

removeGrid()

Parameters:

grid (Optional[QgsLayoutItemMapGrid])

asList(self) List[QgsLayoutItemMapGrid]

Returns a list of QgsLayoutItemMapGrids contained by the stack.

Return type:

List[QgsLayoutItemMapGrid]

calculateMaxGridExtension(self)[source]

Calculates the maximum distance grids within the stack extend beyond the QgsLayoutItemMap’s item rect. This method calculates the distance for each side of the map item separately.

grid(self, gridId: str | None) QgsLayoutItemMapGrid | None[source]

Returns a reference to a grid with matching gridId within the stack.

Parameters:

gridId (Optional[str])

Return type:

Optional[QgsLayoutItemMapGrid]

grid(self, index: int) QgsLayoutItemMapGrid | None[source]

Returns a reference to a grid at the specified index within the stack.

Parameters:

index (int)

Return type:

Optional[QgsLayoutItemMapGrid]

maxGridExtension(self) float[source]

Calculates the maximum distance grids within the stack extend beyond the QgsLayoutItemMap’s item rect.

Return type:

float

moveGridDown(self, gridId: str | None)[source]

Moves a grid with matching gridId down the stack, causing it to be rendered below other grids.

Note

After moving a grid within the stack, update() should be called for the QgsLayoutItemMap to redraw the map with the new grid stack order.

See also

moveGridUp()

Parameters:

gridId (Optional[str])

moveGridUp(self, gridId: str | None)[source]

Moves a grid with matching gridId up the stack, causing it to be rendered above other grids.

Note

After moving a grid within the stack, update() should be called for the QgsLayoutItemMap to redraw the map with the new grid stack order.

See also

moveGridDown()

Parameters:

gridId (Optional[str])

removeGrid(self, gridId: str | None)[source]

Removes a grid with matching gridId from the stack and deletes the corresponding QgsLayoutItemMapGrid.

Note

After removing a grid from the stack, updateBoundingRect() and update() should be called for the QgsLayoutItemMap to prevent rendering artifacts.

See also

addGrid()

Parameters:

gridId (Optional[str])