Subgroup: Layer

Class: QgsLayerTreeView

class qgis.gui.QgsLayerTreeView(parent: QWidget = None)

Bases: PyQt5.QtWidgets.QTreeView

Constructor for QgsLayerTreeView

The QgsLayerTreeView class extends QTreeView and provides some additional functionality when working with a layer tree.

The view updates expanded state of layer tree nodes and also listens to changes to expanded states in the layer tree.

The view keeps track of the current layer and emits a signal when the current layer has changed.

Allows the client to specify a context menu provider with custom actions. Also it comes with a set of default actions that can be used when building context menu.

New in version 2.4: Methods

actionEvent
addIndicator Adds an indicator to the given layer tree node.
changeEvent
childEvent
closeEditor
closeEvent
collapseAllNodes Enhancement of QTreeView.collapseAll() that also records expanded state in layer tree nodes
columnCountChanged
columnMoved
columnResized
commitData
connectNotify
contextMenuEvent
create
currentChanged
currentGroupNode Gets current group node.
currentLayer Gets currently selected layer.
currentLegendNode Gets current legend node.
currentNode Gets current node.
customEvent
defaultActions Gets access to the default actions that may be used with the tree view
destroy
dirtyRegionOffset
disconnectNotify
dragEnterEvent
dragLeaveEvent
dragMoveEvent
drawBranches
drawFrame
drawRow
drawTree
dropEvent
dropIndicatorPosition
edit
editorDestroyed
enterEvent
event
eventFilter
executeDelayedItemsLayout
expandAllNodes Enhancement of QTreeView.expandAll() that also records expanded state in layer tree nodes
focusInEvent
focusNextChild
focusNextPrevChild
focusOutEvent
focusPreviousChild
hideEvent
horizontalOffset
horizontalScrollbarAction
horizontalScrollbarValueChanged
indexRowSizeHint
indicators Returns list of indicators associated with a particular layer tree node.
initPainter
initStyleOption
inputMethodEvent
isIndexHidden
isSignalConnected
keyPressEvent
keyReleaseEvent
layerForIndex
layerTreeModel Gets access to the model casted to QgsLayerTreeModel
leaveEvent
menuProvider Returns pointer to the context menu provider.
metric
modelRowsInserted
modelRowsRemoved
mouseDoubleClickEvent
mouseMoveEvent
mousePressEvent
mouseReleaseEvent
moveCursor
moveEvent
nativeEvent
onCurrentChanged
onExpandedChanged
onModelReset
paintEvent
receivers
reexpand
refreshLayerSymbology Force refresh of layer symbology.
removeIndicator Removes a previously added indicator to a layer tree node.
resizeEvent
rowHeight
rowsAboutToBeRemoved
rowsInserted
rowsRemoved
scheduleDelayedItemsLayout
scrollContentsBy
scrollDirtyRegion
selectedIndexes
selectedLayerNodes Returns list of selected nodes filtered to just layer nodes
selectedLayers Gets list of selected layers
selectedLayersRecursive Gets list of selected layers, including those that are not directly selected, but their ancestor groups is selected.
selectedNodes Returns list of selected nodes
selectionChanged
selectionCommand
sender
senderSignalIndex
setCurrentLayer Sets currently selected layer.
setDirtyRegion
setMenuProvider Sets provider for context menu.
setModel Overridden setModel() from base class.
setSelection
setState
setViewportMargins
sharedPainter
showEvent
sizeHintForColumn
startDrag
state
tabletEvent
timerEvent
updateEditorData
updateEditorGeometries
updateExpandedStateFromNode
updateExpandedStateToNode
updateGeometries
updateMicroFocus
verticalOffset
verticalScrollbarAction
verticalScrollbarValueChanged
viewOptions
viewportEvent
viewportMargins
viewportSizeHint
visualRegionForSelection
wheelEvent

Signals

currentLayerChanged Emitted when a current layer is changed [signal]

Attributes

actionEvent()
addIndicator(self, node: QgsLayerTreeNode, indicator: QgsLayerTreeViewIndicator)

Adds an indicator to the given layer tree node. Indicators are icons shown next to layer/group names in the layer tree view. They can be used to show extra information with tree nodes and they allow user interaction.

Does not take ownership of the indicator. One indicator object may be used for multiple layer tree nodes.

See also

indicators()

New in version 3.2.

changeEvent()
childEvent()
closeEditor()
closeEvent()
collapseAllNodes(self)

Enhancement of QTreeView.collapseAll() that also records expanded state in layer tree nodes

New in version 2.18.

columnCountChanged()
columnMoved()
columnResized()
commitData()
connectNotify()
contextMenuEvent(self, event: QContextMenuEvent)
create()
currentChanged()
currentGroupNode(self) → QgsLayerTreeGroup

Gets current group node. If a layer is current node, the function will return parent group. May be null.

currentLayer(self) → QgsMapLayer

Gets currently selected layer. May be null

currentLayerChanged

Emitted when a current layer is changed [signal]

currentLegendNode(self) → QgsLayerTreeModelLegendNode

Gets current legend node. May be null if current node is not a legend node.

New in version 2.14.

currentNode(self) → QgsLayerTreeNode

Gets current node. May be null

customEvent()
defaultActions(self) → QgsLayerTreeViewDefaultActions

Gets access to the default actions that may be used with the tree view

destroy()
dirtyRegionOffset()
disconnectNotify()
dragEnterEvent()
dragLeaveEvent()
dragMoveEvent()
drawBranches()
drawFrame()
drawRow()
drawTree()
dropEvent(self, event: QDropEvent)
dropIndicatorPosition()
edit()
editorDestroyed()
enterEvent()
event()
eventFilter()
executeDelayedItemsLayout()
expandAllNodes(self)

Enhancement of QTreeView.expandAll() that also records expanded state in layer tree nodes

New in version 2.18.

focusInEvent()
focusNextChild()
focusNextPrevChild()
focusOutEvent()
focusPreviousChild()
hideEvent()
horizontalOffset()
horizontalScrollbarAction()
horizontalScrollbarValueChanged()
indexRowSizeHint()
indicators(self, node: QgsLayerTreeNode) → object

Returns list of indicators associated with a particular layer tree node.

See also

addIndicator()

New in version 3.2.

initPainter()
initStyleOption()
inputMethodEvent()
isIndexHidden()
isSignalConnected()
keyPressEvent(self, event: QKeyEvent)
keyReleaseEvent()
layerForIndex(self, index: QModelIndex) → QgsMapLayer
layerTreeModel(self) → QgsLayerTreeModel

Gets access to the model casted to QgsLayerTreeModel

leaveEvent()
menuProvider(self) → QgsLayerTreeViewMenuProvider

Returns pointer to the context menu provider. May be null

metric()
modelRowsInserted(self, index: QModelIndex, start: int, end: int)
modelRowsRemoved(self)
mouseDoubleClickEvent()
mouseMoveEvent()
mousePressEvent()
mouseReleaseEvent(self, event: QMouseEvent)
moveCursor()
moveEvent()
nativeEvent()
onCurrentChanged(self)
onExpandedChanged(self, node: QgsLayerTreeNode, expanded: bool)
onModelReset(self)
paintEvent()
receivers()
reexpand()
refreshLayerSymbology(self, layerId: str)

Force refresh of layer symbology. Normally not needed as the changes of layer’s renderer are monitored by the model

removeIndicator(self, node: QgsLayerTreeNode, indicator: QgsLayerTreeViewIndicator)

Removes a previously added indicator to a layer tree node. Does not delete the indicator.

See also

addIndicator()

See also

indicators()

New in version 3.2.

resizeEvent()
rowHeight()
rowsAboutToBeRemoved()
rowsInserted()
rowsRemoved()
scheduleDelayedItemsLayout()
scrollContentsBy()
scrollDirtyRegion()
selectedIndexes()
selectedLayerNodes(self) → List[QgsLayerTreeLayer]

Returns list of selected nodes filtered to just layer nodes

selectedLayers(self) → List[QgsMapLayer]

Gets list of selected layers

selectedLayersRecursive(self) → List[QgsMapLayer]

Gets list of selected layers, including those that are not directly selected, but their ancestor groups is selected. If we have a group with two layers L1, L2 and just the group node is selected, this method returns L1 and L2, while selectedLayers() returns an empty list.

New in version 3.4.

selectedNodes(self, skipInternal: bool = False) → List[QgsLayerTreeNode]

Returns list of selected nodes

Parameters:skipInternal – If true, will ignore nodes which have an ancestor in the selection
selectionChanged()
selectionCommand()
sender()
senderSignalIndex()
setCurrentLayer(self, layer: QgsMapLayer)

Sets currently selected layer. Null pointer will deselect any layer.

setDirtyRegion()
setMenuProvider(self, menuProvider: QgsLayerTreeViewMenuProvider)

Sets provider for context menu. Takes ownership of the instance

setModel(self, model: QAbstractItemModel)

Overridden setModel() from base class. Only QgsLayerTreeModel is an acceptable model.

setSelection()
setState()
setViewportMargins()
sharedPainter()
showEvent()
sizeHintForColumn()
startDrag()
state()
tabletEvent()
timerEvent()
updateEditorData()
updateEditorGeometries()
updateExpandedStateFromNode(self, node: QgsLayerTreeNode)
updateExpandedStateToNode(self, index: QModelIndex)
updateGeometries()
updateMicroFocus()
verticalOffset()
verticalScrollbarAction()
verticalScrollbarValueChanged()
viewOptions()
viewportEvent()
viewportMargins()
viewportSizeHint()
visualRegionForSelection()
wheelEvent()