Skip to main content

QCustomTreeWidget

QCustomTreeWidget

A tokenized hierarchical tree.

Built on QTreeWidget with a convenient nested setItems() API and tokenized styling (selection, hover, branches). variant/sizeVariant.

At a glance​

TierFree (GPLv3)
Importfrom Custom_Widgets.QCustomTreeWidget import QCustomTreeWidget
Qt DesignerYes — drag it from the palette

Quick start​

from Custom_Widgets.QCustomTreeWidget import QCustomTreeWidget

widget = QCustomTreeWidget()
widget.setItems([
{"text": "src", "expanded": True, "children": [
{"text": "main.py"},
{"text": "widgets", "expanded": True, "children": [
{"text": "button.py"}, {"text": "card.py"}]}]},
{"text": "tests", "children": [{"text": "test_button.py"}]},
{"text": "README.md"},
])

That is the exact code behind the screenshot above.

Dark theme​

Colours come from the design tokens, so the widget follows the app theme with no extra work.

QCustomTreeWidget in dark theme

Properties​

Every property below is settable in code and in Qt Designer.

PropertyTypeDefault
frameShapeQFrame::Shape—
frameShadowQFrame::Shadow—
lineWidthint—
midLineWidthint—
frameWidthint—
frameRectQRect—
verticalScrollBarPolicyQt::ScrollBarPolicy—
horizontalScrollBarPolicyQt::ScrollBarPolicy—
sizeAdjustPolicyQAbstractScrollArea::SizeAdjustPolicy—
autoScrollbool—
autoScrollMarginint—
editTriggersQFlags<QAbstractItemView::EditTrigger>—
tabKeyNavigationbool—
showDropIndicatorbool—
dragEnabledbool—
dragDropOverwriteModebool—
dragDropModeQAbstractItemView::DragDropMode—
defaultDropActionQt::DropAction—
alternatingRowColorsbool—
selectionModeQAbstractItemView::SelectionMode—
selectionBehaviorQAbstractItemView::SelectionBehavior—
iconSizeQSize—
textElideModeQt::TextElideMode—
verticalScrollModeQAbstractItemView::ScrollMode—
horizontalScrollModeQAbstractItemView::ScrollMode—
updateThresholdint—
keyboardSearchFlagsQFlags<Qt::MatchFlag>—
autoExpandDelayint—
indentationint—
rootIsDecoratedbool—
uniformRowHeightsbool—
itemsExpandablebool—
sortingEnabledbool—
animatedbool—
allColumnsShowFocusbool—
wordWrapbool—
headerHiddenbool—
expandsOnDoubleClickbool—
columnCountint—
topLevelItemCountint—
supportedDragActionsQFlags<Qt::DropAction>—
variantenum: primary/secondary/outline/ghost``outline
sizeVariantenum: sm/md/lg``md

Methods​

MethodDescription
setItems(items, headers=None)Build the tree from nested data. Each item is a string, or a dict
sizeVariant(*args, **kwargs)Size variant.
variant(*args, **kwargs)Variant.

Theming​

Colours come from the design tokens, so they follow the active theme. Roles used: surface, on-surface, surface-muted, outline, accent, on-primary.

See Design tokens.

QCustomCodeEditor · QCustomDataTable · QCustomNodeGraph · QCustomRichTextEditor · QCustomTableToolbar