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

Method T_ListView

ElaWidgetToolsExample/ExamplePage/T_ListView.cpp:10–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include "T_ListViewModel.h"
9
10#include <QItemSelectionModel>
11#include <QSortFilterProxyModel>
12#include <QVBoxLayout>
13
14T_ListView::T_ListView(QWidget* parent)
15 : T_BasePage(parent)
16{
17 setWindowTitle("列表视图");
18 createCustomWidget("搜索列表内容,尝试单选、多选以及不同的行背景。", "列表视图");
19 auto* mainLayout = createPageLayout();
20 auto* section = addExampleSection(mainLayout, "资源列表 · ElaListView", "启用多选后,可使用 Ctrl 或 Shift 连续选择多个条目。");
21 auto* searchEdit = new ElaLineEdit(this);
22 searchEdit->setFixedWidth(260);
23 searchEdit->setPlaceholderText("搜索资源名称");
24 searchEdit->setClearButtonEnabled(true);
25 auto* multiCheckBox = new ElaCheckBox("允许多选", this);
26 multiCheckBox->setFixedHeight(searchEdit->height());
27 auto* alternatingCheckBox = new ElaCheckBox("交替行背景", this);
28 alternatingCheckBox->setFixedHeight(searchEdit->height());
29 auto* optionsLayout = new ElaFlowLayout(0, 20, 12);
30 optionsLayout->addWidget(searchEdit);
31 optionsLayout->addWidget(multiCheckBox);
32 optionsLayout->addWidget(alternatingCheckBox);
33 _listView = new ElaListView(this);
34 _listView->setFixedHeight(350);
35 _listView->setSelectionMode(QAbstractItemView::SingleSelection);
36 auto* resourceModel = new T_ListViewModel(this);
37 auto* filterModel = new QSortFilterProxyModel(this);
38 filterModel->setSourceModel(resourceModel);
39 filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
40 _listView->setModel(filterModel);
41 auto* resultText = new ElaText("选择结果:尚未选择", this);
42 connect(searchEdit, &ElaLineEdit::textChanged, filterModel, &QSortFilterProxyModel::setFilterFixedString);
43 connect(multiCheckBox, &ElaCheckBox::toggled, this, [this](bool checked) {
44 _listView->clearSelection();

Callers

nothing calls this directly

Calls 4

setFixedHeightMethod · 0.80
addWidgetMethod · 0.80
setTextPixelSizeMethod · 0.45
setIsAnimationMethod · 0.45

Tested by

no test coverage detected