-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathCheckedListWidget.h
More file actions
36 lines (31 loc) · 1.11 KB
/
Copy pathCheckedListWidget.h
File metadata and controls
36 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once
#include <QDebug>
#include <QFrame>
#include <QMainWindow>
#include <QListWidget>
namespace Examples {
class Window1 : public QMainWindow {
Q_OBJECT
public:
Window1() {
checkedListWidget.move(10, 10);
checkedListWidget.resize(160, 200);
for (auto index = 1; index <= 10; ++index) {
checkedListWidget.addItem(QString("Item %1").arg(index));
auto item = checkedListWidget.item(index-1);
item->setFlags(item->flags()|Qt::ItemIsUserCheckable);
item->setCheckState(index % 2 != 0 ? Qt::Checked : Qt::Unchecked);
}
checkedListWidget.setCurrentRow(0);
connect(&checkedListWidget, &QListWidget::itemChanged, [&](QListWidgetItem *item) {
qDebug() << QString("item changed, item='%1', index=%2, value=%3").arg(item->text()).arg(checkedListWidget.row(item)).arg(item->checkState() == Qt::CheckState::Unchecked ? "Unchecked" : "Checked");
});
setCentralWidget(&frame);
setWindowTitle("Checked list widget example");
resize(200, 240);
}
private:
QFrame frame;
QListWidget checkedListWidget {&frame};
};
}