PyQt QTableView 在滚动大数据集时速度非常慢 [英] PyQt QTableView prohibitively slow when scrolling with large data sets
本文介绍了PyQt QTableView 在滚动大数据集时速度非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个程序可以从 csv 文件加载配置文件并在表格中显示数据.将 Pandas 数据框加载到表格中的速度很快,因为我使用了 QAbstractTableModel
的自定义模型实现,但是 QTableView 小部件的大小调整非常慢.
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 implementation of QAbstractTableModel
, but the resizing of the QTableView widget is incredibly slow.
如何使调整大小和滚动更流畅?
What can I do to make the resizing and scrolling smoother?
推荐答案
好吧,我最终修改了我使用 numpy 创建的自定义表模型,现在它非常快.
Well, I ended up modifying the custom table model I made to use numpy, and now it is blazing fast.
更新于 22-02-2020从 Pandas 1.0.1 开始工作:
使用这个表模型:
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 str(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
这篇关于PyQt QTableView 在滚动大数据集时速度非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文