San*_*era 7 python qtableview pyqt4
我有一个程序从csv文件加载配置文件并在表中显示数据.将pandas数据框加载到表中的速度很快,因为我使用了自定义模型实现QAbstractTableModel
,但是QTableView小部件的大小调整非常慢.
我该怎么做才能使调整大小和滚动更顺畅?
好吧,我最后修改了我使用numpy制作的自定义表模型,现在它速度非常快.
使用此表格模型:
import numpy as np
class PandasModel(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)
def rowCount(self, parent=None):
return self.r
def columnCount(self, parent=None):
return self.c
def data(self, index, role=QtCore.Qt.DisplayRole):
if index.isValid():
if role == QtCore.Qt.DisplayRole:
return self._data[index.row(),index.column()]
return None
def headerData(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
return None
Run Code Online (Sandbox Code Playgroud)