-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathTableModel.py
More file actions
42 lines (35 loc) · 1.38 KB
/
TableModel.py
File metadata and controls
42 lines (35 loc) · 1.38 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
from PyQt6 import QtCore
# Standard table model requires 2D header and complete dataset
class TableModel(QtCore.QAbstractTableModel):
def __init__(self, header, data):
super().__init__()
self.data = data
self.header = header
def data(self, index, role):
if not index.isValid():
return QtCore.QVariant()
elif role != QtCore.Qt.ItemDataRole.DisplayRole:
return QtCore.QVariant()
return self.data[index.row()][index.column()]
def rowCount(self, parent=None, *args, **kwargs):
return len(self.data)
def columnCount(self, parent=None, *args, **kwargs):
return len(self.data[0])
def headerData(self, p_int, Qt_Orientation, role=None):
if (
Qt_Orientation == QtCore.Qt.Orientation.Horizontal
and role == QtCore.Qt.ItemDataRole.DisplayRole
):
return QtCore.QVariant(self.header[0][p_int])
elif (
Qt_Orientation == QtCore.Qt.Orientation.Vertical
and role == QtCore.Qt.ItemDataRole.DisplayRole
):
return QtCore.QVariant(self.header[1][p_int])
return QtCore.QVariant()
def setData(self, index, value, role=None):
if not index.isValid():
return False
self.data[index.row()][index.column()] = value
self.dataChanged.emit(index, index)
return True