Pyqt Qtableview Prohibitively Slow When Scrolling With Large Data Sets
I have a program that loads a profile from a csv file and displays the data in a table. The loading of a pandas data frame to the table is fast because I used a custom model implem
Solution 1:
Well, I ended up modifying the custom table model I made to use numpy, and now it is blazing fast.
Updated 22-02-2020 Works as of Pandas 1.0.1:
Use this table model:
import numpy as np
classPandasModel(QtCore.QAbstractTableModel):
"""
Class to populate a table view with a pandas dataframe
"""def__init__(self, data, parent=None):
QtCore.QAbstractTableModel.__init__(self, parent)
self._data = np.array(data.values)
self._cols = data.columns
self.r, self.c = np.shape(self._data)
defrowCount(self, parent=None):
return self.r
defcolumnCount(self, parent=None):
return self.c
defdata(self, index, role=QtCore.Qt.DisplayRole):
if index.isValid():
if role == QtCore.Qt.DisplayRole:
returnstr(self._data[index.row(),index.column()])
returnNonedefheaderData(self, p_int, orientation, role):
if role == QtCore.Qt.DisplayRole:
if orientation == QtCore.Qt.Horizontal:
return self._cols[p_int]
elif orientation == QtCore.Qt.Vertical:
return p_int
returnNone
Post a Comment for "Pyqt Qtableview Prohibitively Slow When Scrolling With Large Data Sets"