-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtable_model.py
33 lines (24 loc) · 1.09 KB
/
table_model.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
29
30
31
32
33
from PySide2 import QtCore, QtGui
import pandas as pd
class TableModel(QtCore.QAbstractTableModel):
def __init__(self, data, parent=None):
QtCore.QAbstractTableModel.__init__(self, parent)
pd.set_option('display.precision', 8)
pd.set_option('display.float_format', lambda x: '%.8f' % x)
self.table_data = data
def data(self, index, role=QtCore.Qt.DisplayRole):
if index.isValid():
if role == QtCore.Qt.DisplayRole:
self.dataChanged.emit(index, index)
return str(self.table_data.iloc[index.row(), index.column()])
elif role == QtGui.Qt.TextAlignmentRole:
return int(QtGui.Qt.AlignCenter | QtGui.Qt.AlignVCenter)
return None
def rowCount(self, index):
return self.table_data.shape[0]
def columnCount(self, index):
return self.table_data.shape[1]
def headerData(self, col, orientation, role):
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
return self.table_data.columns[col].upper()
return None