-
Notifications
You must be signed in to change notification settings - Fork 572
/
main.py
28 lines (25 loc) · 906 Bytes
/
main.py
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
from PyQt6.QtWidgets import *
from PyQt6.QtCore import *
headers = ["Scientist name", "Birthdate", "Contribution"]
rows = [("Newton", "1643-01-04", "Classical mechanics"),
("Einstein", "1879-03-14", "Relativity"),
("Darwin", "1809-02-12", "Evolution")]
class TableModel(QAbstractTableModel):
def rowCount(self, parent):
return len(rows)
def columnCount(self, parent):
return len(headers)
def data(self, index, role):
if role != Qt.ItemDataRole.DisplayRole:
return QVariant()
return rows[index.row()][index.column()]
def headerData(self, section, orientation, role):
if role != Qt.ItemDataRole.DisplayRole or orientation != Qt.Orientation.Horizontal:
return QVariant()
return headers[section]
app = QApplication([])
model = TableModel()
view = QTableView()
view.setModel(model)
view.show()
app.exec()