I need to display data using the PyQt class QTableWidget
. But there could be dozens of thousand lines. Displaying the whole sheet makes the appli to hang...
So I found a solution consisting on loading data (meaning that the sheet is created) but hidding most of the rows and, when moving the scroll bar, show new rows and hidding previous ones.
In the bellow code, I setted self.rowsShown = 50
and at the init the lines from 1 to 50 are shown. And I previously did self.verticalScrollBar().actionTriggered.connect(self.refreshDisplay)
.
So the code is:
def refreshDisplay(self):
"""
This is to refresh the display when the scrollbar is moved
"""
# Minimum is reached and a previous row exists
if self.verticalScrollBar().value() <= self.verticalScrollBar().minimum() and self.isRowHidden(self.firstRowShown-1):# Minimum is reached and a previous row exists
for row in xrange(self.lastRowShown-1, self.lastRowShown):
self.hideRow(row)
self.lastRowShown -= 1
for row in xrange(self.firstRowShown-1, self.firstRowShown):
self.showRow(row)
self.firstRowShown -= 1
# Maximum is reached and a next row exists
if self.verticalScrollBar().value() >= self.verticalScrollBar().maximum() and self.isRowHidden(self.lastRowShown+1):
for row in xrange(self.firstRowShown, self.firstRowShown+1):
self.hideRow(row)
self.firstRowShown += 1
for row in xrange(self.lastRowShown, self.lastRowShown+1):
self.showRow(row)
self.lastRowShown += 1
This is working very well when I use the roll of the mouse or click on buttons of the scrollbar. But when I grab the slider or use the keypad to move the case selected, I'm blocked in the area shown.
Moreover, the size of the scrolling area correspond to the rows shown only. I would like to redifine it to set my own bar (for example with a size based on the real number of lines), so that I can move fastly to another part of the sheet. But the size of the scroll bar is always updated with the number of lines shown.
So, what I expect from you is to help me to resolve this two issues, OR give me another idea for displaying such huge sheet. Maybe I missed a module or class that already bear this functionnality of loading/showing lines whilemoving the cursor.
Thanks