forked from nodegui/nodegui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodelview_4_headers.ts
More file actions
44 lines (36 loc) · 1.22 KB
/
modelview_4_headers.ts
File metadata and controls
44 lines (36 loc) · 1.22 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
43
44
import { ItemDataRole, Orientation, QAbstractTableModel, QModelIndex, QTableView, QVariant } from '..';
function main(): void {
const tableView = new QTableView();
const model = new MyModel();
tableView.setModel(model);
tableView.show();
(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 {
if (role === ItemDataRole.DisplayRole) {
return new QVariant(`Row${index.row() + 1}, Column${index.column() + 1}`);
}
return new QVariant();
}
headerData(section: number, orientation: Orientation, role: number): QVariant {
if (role == ItemDataRole.DisplayRole && orientation == Orientation.Horizontal) {
switch (section) {
case 0:
return new QVariant('first');
case 1:
return new QVariant('second');
case 2:
return new QVariant('third');
}
}
return new QVariant();
}
}
main();