Python 更高效的QTableWidget写入解决方案

Python 更高效的QTableWidget写入解决方案,python,performance,qtablewidget,pytables,Python,Performance,Qtablewidget,Pytables,我正在读一个有132000行x16列的PyTable 其思想是读取表并将其内容写入QTableWidget 我这样做会使GUI崩溃 我想知道如何有效地完成这项工作 这是我的代码: #The PyTable is already opened and the reference to the desired table acquired self.ui.tableWidget.setRowCount(tab.nrows) self.ui.tableWidget.setColumnCount(le

我正在读一个有132000行x16列的PyTable

其思想是读取表并将其内容写入QTableWidget

我这样做会使GUI崩溃

我想知道如何有效地完成这项工作

这是我的代码:

#The PyTable is already opened and the reference to the desired table acquired

self.ui.tableWidget.setRowCount(tab.nrows)
self.ui.tableWidget.setColumnCount(len(tab.colnames))
self.ui.tableWidget.setHorizontalHeaderLabels(tab.colnames)
res = []

#Read the PyTable row by row and store the result
for x in tab.where('col1 > -1'):
    res.append(x[:])

#Try to write the QTableWidget row by row
for i, row in enumerate(res):
    for j, col in enumerate(row):
        item = QTableWidgetItem(str(col))
        self.ui.tableWidget.setItem(i, j, item)   

#NOTE 1: with a PyTable with 1000rows X 16cols rows aprox it works perfect
#NOTE 2: with the huge PyTable with 1320000rows x 16cols, it does not work

有这么一张大桌子。。。您不希望将整个表放在小部件中。你想自己实现滚动,所以你只需在小部件中写入屏幕上实际可见的内容。谢谢Corley,我已经考虑过了,但我不知道如何进行滚动。有什么建议或者我可以在哪里读到的地方吗?。谢谢