| On this page |
This class inherits from Qt’s QtWidgets.QTreeView class.
It’s generally used instead of QTreeView in python panels as it adds the expansion state and highlight mechanisms while keeping the underlying QTreeView API intact. modelview/TreeView.py is now just an alias to this as its functionality was simply rolled into this class.
Methods ¶
__init__(parent=None)
Create and return a new TreeView object.
setHighlightModel(model)
Sets the selection model used for highlighting items in the tree.
model must be a QtCore.QItemSelectionModel object.
highlightModel()
→ QtCore.QItemSelectionModel
Returns the current highlight selection model.
highlightAncestorsModel()
→ QtCore.QItemSelectionModel
Returns the selection model used for highlighting ancestors of the selected items.
setHighlightBehavior(behavior)
Sets the highlight behavior.
behavior must be a QtWidgets.QAbstractItemView.SelectionBehavior value.
highlightBehavior()
→ QtWidgets.QAbstractItemView.SelectionBehavior
Returns the current highlight behavior.
setDepth(depth)
Sets the default expansion depth for the tree view. If the expansion depth is
greater than 0, then expandToDepth() is called with this value after a
model reset when restoreExpansionStateOnReset is enabled.
depth()
→ int
Returns the current default expansion depth.
setRestoreExpansionStateOnReset(restore)
When enabled, the expansion state is automatically saved before a model reset and restored after, so the tree looks the same after a rebuild.
getExpansionState()
→ dict
Returns a nested dictionary describing which nodes are expanded. Returns an empty dictionary when the model has no rows.
setExpansionState(state)
Restores the expansion state previously captured by getExpansionState().
Items not present in state are collapsed.
expandFully(indexes)
Recursively expands the given indexes and all their children.
indexes must be a list of QtCore.QModelIndex objects.
expandUntil(indexes, predicate)
Recursively expands nodes starting from the given indexes until the
predicate matches.
indexes must be a list of QtCore.QModelIndex objects.
predicate must be a callable that takes a QtCore.QModelIndex and
returns a boolean. If the predicate returns True, the node and its
subtree are not expanded.
collapseFully(indexes)
Recursively collapses the given indexes and all their children.
indexes must be a list of QtCore.QModelIndex objects.
setCurrentPath(path)
→ bool
Sets the current index by navigating the tree using a list of display names.
Returns True if the path was successfully found and set as the current
index.
getCurrentPath()
→ list
of str
Returns the path to the current index as a list of strings (display names).
setHandleCopyActions(handle)
Enable or disable handling of copy actions (Ctrl+C). When enabled, selected item values are copied to the clipboard.
handleCopyActions()
→ bool
Returns whether copy actions are currently handled.
copyValues(indexes)
Copies the values of the given indexes to the clipboard.
indexes must be a list of QtCore.QModelIndex objects.
setNormalizeContextMenuToColumn(column)
Sets the column used to normalize the selection list passed to
createContextActions.
A value of 0 (default) uses column 0. A negative value uses the column that
was right-clicked.
normalizeContextMenuToColumn()
→ int
Returns the current normalization column index for context menus.
createContextActions(indexes, menu)
Override in subclasses to add custom context menu actions. The right-clicked
item is always first in indexes.
indexes must be a list of QtCore.QModelIndex objects.
menu must be a QtWidgets.QMenu.
The base implementation adds Expand All, Collapse All, and Copy
actions.
highlight(selection, command)
Manually triggers highlighting for a given index or selection.
selection can be either a QtCore.QModelIndex or a QtCore.QItemSelection.
command must be a QtCore.QItemSelectionModel.SelectionFlags value.
highlightChanged(selected, deselected)
Called when the highlight selection changes. Override in subclasses to
react to highlight changes.
selected and deselected must be QtCore.QItemSelection objects.