forked from nodegui/nodegui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodelview_3_changingmodel.ts
More file actions
42 lines (32 loc) · 1.02 KB
/
modelview_3_changingmodel.ts
File metadata and controls
42 lines (32 loc) · 1.02 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
37
38
39
40
41
42
import { ItemDataRole, QAbstractTableModel, QModelIndex, QTableView, QVariant } from '..';
function main(): void {
const tableView = new QTableView();
const model = new MyModel();
tableView.setModel(model);
tableView.show();
setInterval(() => {
model.timerHit();
}, 1000);
(global as any).win = tableView;
}
class MyModel extends QAbstractTableModel {
rowCount(parent = new QModelIndex()): number {
return 2;
}
columnCount(parent = new QModelIndex()): number {
return 3;
}
data(index: QModelIndex, role = ItemDataRole.DisplayRole): QVariant {
const row = index.row();
const col = index.column();
if (role == ItemDataRole.DisplayRole && row == 0 && col == 0) {
return new QVariant('' + new Date().toTimeString());
}
return new QVariant();
}
timerHit(): void {
const topLeft = this.createIndex(0, 0);
this.emitDataChanged(topLeft, topLeft, [ItemDataRole.DisplayRole]);
}
}
main();