more efficient solution for QTableWidget write

守給你的承諾、 提交于 2019-12-13 04:32:43

问题


I am reading a PyTable, with 1320000rows x 16cols

The idea is to read the table and to write its content into a QTableWidget.

The way I am doing it makes the GUI collapse.

I would like a clue about how to do it in an efficient way.

Here it is my code:

#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

来源:https://stackoverflow.com/questions/22173626/more-efficient-solution-for-qtablewidget-write

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!