Class: QgsLayerTreeCustomNode

Layer tree custom node serves as a node for objects that are not layers nor groups.

They are created, and can be found based on a node ID, which should be unique in the whole layer tree.

Added in version 4.0.

Class Hierarchy

Inheritance diagram of qgis.core.QgsLayerTreeCustomNode

Base classes

QgsLayerTreeNode

Base class for nodes in a layer tree.

QObject

Abstract Methods

name

Returns the node's name.

setName

Sets the node's name.

writeXml

Write custom node as XML element <layer-tree-custom-node> and add it to the given parent element.

Methods

nodeId

Returns the node's unique identifier.

Static Methods

readXml

Read custom node from XML element <layer-tree-custom-node> and return the newly created node (or None on error).

class qgis.core.QgsLayerTreeCustomNode[source]

Bases: QgsLayerTreeNode

__init__(nodeId: str | None, nodeName: str | None = '', checked: bool = True)

Constructor to create custom nodes that represent application objects other than layers and groups.

Parameters:
  • nodeId (Optional[str]) – Unique identifier of the custom node.

  • nodeName (Optional[str] = '') – Optional name of the custom node.

  • checked (bool = True) – Whether the custom node should be checked or not once it is created.

abstract name(self) str[source]

Returns the node’s name.

Return type:

str

nodeId(self) str[source]

Returns the node’s unique identifier.

Return type:

str

static readXml(element: QDomElement, context: QgsReadWriteContext) QgsLayerTreeCustomNode | None[source]

Read custom node from XML element <layer-tree-custom-node> and return the newly created node (or None on error).

Parameters:
Return type:

Optional[QgsLayerTreeCustomNode]

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

Sets the node’s name.

Parameters:

name (Optional[str])

abstract writeXml(self, parentElement: QDomElement, context: QgsReadWriteContext)[source]

Write custom node as XML element <layer-tree-custom-node> and add it to the given parent element.

Parameters: