Jan-23-2023, 08:46 AM
Problem solfed in table format class:
# table format class class TableModel(QtCore.QAbstractTableModel): def __init__(self, data): super(TableModel, self).__init__() self._data = data #self.rows_nr, self.columns_nr = data.shape self.hheaders = ["ID", "Datum", "Gewicht", "Bmkg"] # <<<<<<<<<<<<<<< NEW LINE def data(self, index, role): if role == Qt.DisplayRole: value = self._data[index.row()][index.column()] if index.column() == 2: # Betrag return "%.1f" % float(value) #elif index.column() == 1: # Datum # return value.strftime("%Y-%m-%d") else: return value if role == Qt.TextAlignmentRole: value = self._data[index.row()][index.column()] if index.column() == 0 or index.column() == 2: # ID, Betrag return Qt.AlignmentFlag.AlignVCenter + Qt.AlignmentFlag.AlignRight else: return Qt.AlignmentFlag.AlignVCenter def rowCount(self, index): # The length of the outer list. return len(self._data) def columnCount(self, index): # The following takes the first sub-list, and returns # the length (only works if all rows are an equal length) return len(self._data[0]) def headerData(self, section, orientation, role): # <<<<<<<<<<<<<<< NEW DEF # row and column headers if role == QtCore.Qt.DisplayRole: if orientation == QtCore.Qt.Horizontal: return self.hheaders[section] return QtCore.QVariant()