Class: QgsGroupLayer

A map layer which consists of a set of child layers, where all component layers are rendered as a single flattened object during map renders.

Child layers are never owned by QgsGroupLayer. References to layers in a group are stored as weak references only, which wills be automatically cleaned up whenever the linked child layer is deleted.

Added in version 3.24.

Class Hierarchy

Inheritance diagram of qgis.core.QgsGroupLayer

Base classes

QgsMapLayer

Base class for all map layer types.

QObject

Methods

childLayers

Returns the child layers contained by the group.

paintEffect

Returns the current paint effect for the group layer.

prepareLayersForRemovalFromGroup

Prepares all child layers in the group prior to removal from the group.

setChildLayers

Sets the child layers contained by the group.

setPaintEffect

Sets the current paint effect for the renderer.

class qgis.core.QgsGroupLayer[source]

Bases: QgsMapLayer

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

Constructor for a new QgsGroupLayer with the specified layer name.

The options argument specifies load-time layer options.

Parameters:
class LayerOptions

Bases: object

Setting options for loading group layers.

Added in version 3.16.

childLayers(self) List[QgsMapLayer]

Returns the child layers contained by the group.

See also

setChildLayers()

Return type:

List[QgsMapLayer]

paintEffect(self) QgsPaintEffect | None[source]

Returns the current paint effect for the group layer.

See also

setPaintEffect()

Return type:

Optional[QgsPaintEffect]

prepareLayersForRemovalFromGroup(self)[source]

Prepares all child layers in the group prior to removal from the group.

This method should be called before removing a group layer from a project, to ensure that the existing child layers are in a state which is compatible with non-group layer children.

Added in version 3.30.

setChildLayers(self, layers: Iterable[QgsMapLayer])[source]

Sets the child layers contained by the group.

This method does not take ownership of the layers, but rather assigns them to the group. Layers should be already added to the parent QgsProject wherever appropriate.

See also

childLayers()

Parameters:

layers (Iterable[QgsMapLayer])

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

Sets the current paint effect for the renderer.

Ownership is transferred to the renderer.

See also

paintEffect()

Parameters:

effect (Optional[QgsPaintEffect])