Subgroup: Layer

Class: QgsLayerTreeModelLegendNode

class qgis.core.QgsLayerTreeModelLegendNode

Bases: PyQt5.QtCore.QObject

The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegend implementation.

The objects are used in QgsLayerTreeModel. Custom implementations may offer additional interactivity and customized look.

New in version 2.6: Methods

blockSignals
childEvent
children
connectNotify
createTemporaryRenderContext Returns a temporary context or null if legendMapViewData are not valid
customEvent
data Return data associated with the item.
deleteLater
disconnect
disconnectNotify
draw Entry point called from QgsLegendRenderer to do the rendering.
drawSymbol Draws symbol on the left side of the item
drawSymbolText Draws label on the right side of the item
dumpObjectInfo
dumpObjectTree
dynamicPropertyNames
event
eventFilter
findChild findChild(self, Tuple, name: str = ‘’, options: Union[Qt.FindChildOptions, Qt.FindChildOption] = Qt.FindChildrenRecursively) -> QObject
findChildren findChildren(self, Tuple, name: str = ‘’, options: Union[Qt.FindChildOptions, Qt.FindChildOption] = Qt.FindChildrenRecursively) -> List[QObject]
flags Return item flags associated with the item.
inherits
installEventFilter
invalidateMapBasedData Notification from model that information from associated map view has changed.
isEmbeddedInParent
isScaleOK
isSignalConnected
isWidgetType
isWindowType
killTimer
layerNode Return pointer to the parent layer node
metaObject
model Return pointer to model owning this legend node
moveToThread
objectName
parent
property
pyqtConfigure Each keyword argument is either the name of a Qt property or a Qt signal.
receivers
removeEventFilter
sender
senderSignalIndex
setData Set some data associated with the item.
setEmbeddedInParent
setObjectName
setParent
setProperty
setUserLabel
signalsBlocked
startTimer
thread
timerEvent
tr
userLabel

Attributes

ParentRuleKeyRole
RuleKeyRole
dataChanged Emitted on internal data change so the layer tree model can forward the signal to views [signal]
destroyed destroyed(self, QObject = None) [signal]
objectNameChanged objectNameChanged(self, str) [signal]
staticMetaObject
class ItemContext

Bases: sip.wrapper

QgsLayerTreeModelLegendNode.ItemContext(QgsLayerTreeModelLegendNode.ItemContext)

labelXOffset
painter
point
class ItemMetrics

Bases: sip.wrapper

QgsLayerTreeModelLegendNode.ItemMetrics(QgsLayerTreeModelLegendNode.ItemMetrics)

labelSize
symbolSize
class LegendNodeRoles

Bases: int

ParentRuleKeyRole = 257
RuleKeyRole = 256
childEvent()
connectNotify()
createTemporaryRenderContext(self) → QgsRenderContext

Returns a temporary context or null if legendMapViewData are not valid

customEvent()
data(self, role: int) → Any

Return data associated with the item. Must be implemented in derived class.

dataChanged

Emitted on internal data change so the layer tree model can forward the signal to views [signal]

disconnectNotify()
draw(self, settings: QgsLegendSettings, ctx: QgsLayerTreeModelLegendNode.ItemContext) → QgsLayerTreeModelLegendNode.ItemMetrics

Entry point called from QgsLegendRenderer to do the rendering. Default implementation calls drawSymbol() and drawSymbolText() methods.

If ctx is null, this is just first stage when preparing layout - without actual rendering.

drawSymbol(self, settings: QgsLegendSettings, ctx: QgsLayerTreeModelLegendNode.ItemContext, itemHeight: float) → QSizeF

Draws symbol on the left side of the item

Parameters:
  • settings – Legend layout configuration
  • ctx – Context for rendering - may be null if only doing layout without actual rendering
  • itemHeight – Minimal height of the legend item - used for correct positioning when rendering
Returns:

Real size of the symbol (may be bigger than “normal” symbol size from settings)

drawSymbolText(self, settings: QgsLegendSettings, ctx: QgsLayerTreeModelLegendNode.ItemContext, symbolSize: QSizeF) → QSizeF

Draws label on the right side of the item

Parameters:
  • settings – Legend layout configuration
  • ctx – Context for rendering - may be null if only doing layout without actual rendering
  • symbolSize – Real size of the associated symbol - used for correct positioning when rendering
Returns:

Size of the label (may span multiple lines)

flags(self) → Qt.ItemFlags

Return item flags associated with the item. Default implementation returns Qt.ItemIsEnabled.

invalidateMapBasedData(self)

Notification from model that information from associated map view has changed. Default implementation does nothing. *

isEmbeddedInParent(self) → bool
isScaleOK(self, scale: float) → bool
isSignalConnected()
layerNode(self) → QgsLayerTreeLayer

Return pointer to the parent layer node

model(self) → QgsLayerTreeModel

Return pointer to model owning this legend node

receivers()
sender()
senderSignalIndex()
setData(self, value: Any, role: int) → bool

Set some data associated with the item. Default implementation does nothing and returns false.

setEmbeddedInParent(self, embedded: bool)
setUserLabel(self, userLabel: str)
timerEvent()
userLabel(self) → str