MCPcopy Create free account
hub / github.com/Liniyous/ElaWidgetTools / T_TreeView

Method T_TreeView

ElaWidgetToolsExample/ExamplePage/T_TreeView.cpp:13–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#include <QVBoxLayout>
12
13T_TreeView::T_TreeView(QWidget* parent)
14 : T_BasePage(parent)
15{
16 setWindowTitle("树形视图");
17 createCustomWidget("浏览多层项目资源,调节行高、缩进和表头间距,观察层级结构的变化。", "树形视图");
18 auto* mainLayout = createPageLayout();
19 auto* section = addExampleSection(mainLayout, "项目资源 · ElaTreeView", "点击箭头展开节点,支持多级资源与滚动浏览。");
20 auto* resourceModel = new T_TreeViewModel(this);
21 _treeView = new ElaTreeView(this);
22 _treeView->setModel(resourceModel);
23 _treeView->setFixedHeight(380);
24 _treeView->setUniformRowHeights(true);
25 _treeView->header()->setSectionResizeMode(QHeaderView::Stretch);
26 _treeView->expandToDepth(0);
27 auto* expandButton = new ElaPushButton("展开全部", this);
28 auto* collapseButton = new ElaPushButton("收起全部", this);
29 connect(expandButton, &ElaPushButton::clicked, _treeView, &ElaTreeView::expandAll);
30 connect(collapseButton, &ElaPushButton::clicked, _treeView, &ElaTreeView::collapseAll);
31 auto* actionLayout = new ElaFlowLayout(0, 12, 12);
32 actionLayout->addWidget(expandButton);
33 actionLayout->addWidget(collapseButton);
34 auto* optionsLayout = new ElaFlowLayout(0, 24, 16);
35 auto* heightSpinBox = new ElaSpinBox(this);
36 heightSpinBox->setRange(24, 60);
37 heightSpinBox->setValue(_treeView->getItemHeight());
38 heightSpinBox->setFixedWidth(120);
39 auto* marginSpinBox = new ElaSpinBox(this);
40 marginSpinBox->setRange(0, 20);
41 marginSpinBox->setValue(5);
42 marginSpinBox->setFixedWidth(120);
43 auto* indentSpinBox = new ElaSpinBox(this);
44 indentSpinBox->setRange(12, 64);
45 indentSpinBox->setValue(20);
46 indentSpinBox->setFixedWidth(120);
47 connect(heightSpinBox, QOverload<int>::of(&ElaSpinBox::valueChanged), _treeView, &ElaTreeView::setItemHeight);
48 connect(marginSpinBox, QOverload<int>::of(&ElaSpinBox::valueChanged), _treeView, &ElaTreeView::setHeaderMargin);
49 connect(indentSpinBox, QOverload<int>::of(&ElaSpinBox::valueChanged), _treeView, &ElaTreeView::setIndentation);
50 optionsLayout->addWidget(createLabeledControl("行高(像素)", heightSpinBox));
51 optionsLayout->addWidget(createLabeledControl("表头间距(像素)", marginSpinBox));
52 optionsLayout->addWidget(createLabeledControl("层级缩进(像素)", indentSpinBox));
53 section->addLayout(actionLayout);
54 section->addWidget(_treeView);
55 section->addLayout(optionsLayout);
56 section->addWidget(new ElaText(QString("四级资源结构 · 共 %1 个节点").arg(resourceModel->getItemCount()), this));
57}
58
59T_TreeView::~T_TreeView()
60{
61}

Callers

nothing calls this directly

Calls 9

getItemCountMethod · 0.80
setRangeMethod · 0.80
setValueMethod · 0.80
addWidgetMethod · 0.80
setFixedHeightMethod · 0.80
setTextPixelSizeMethod · 0.45
setItemHeightMethod · 0.45
setHeaderMarginMethod · 0.45
setIsAnimationMethod · 0.45

Tested by

no test coverage detected