To be fair, I don’t know if it’s so many images or so many rows that cause a QTableWidget to show empty rows (or cellwidgets and TableWidgetItems not to appear, however you want to think about it). I think it has something to do with images (I use Pixmaps in labels), because it seems like the bigger the image data I try to display in each row, the earlier the QTable Widget will show its first empty row.
Why does it do this? How do you fix it?
I have no idea. I didn’t see anything about it in my searching.
But I have a hack. Oh yes.
I noticed if you resize the window, it will repaint the images clustered around the rows visible in the viewport at that moment. In other words, if you have a hundred rows, and the top half is OK and the bottom half is empty, if you scroll down to the bottom and resize the window, the bottom half will be OK and the top half will be empty.
So, um — why not programmatically resize the window — just a pixel — when the user scrolls down a certain amount?
First, connect the vertical scrollbar of the table like so (my extended MyTableWidget object is the “self” in this case):
self.connect(self.verticalScrollBar(), QtCore.SIGNAL(“valueChanged(int)”), self.displayedRegionChanged)
somewhere in the MyTableWidget init() method, store the parentWidget (assuming it is your window)
class MyTableWidget(QTableWidget) :
def __init__(self, parentWidget):
self.parentWidgetObj = parentWidget
and then add a method like so:
def displayedRegionChanged(self, newVerticalValue):
#Trigger for deciding we must repaint
repaintingThreshold = self.verticalScrollBar().maximum()/4
if abs(newVerticalValue – self.oldVerticalValue) > repaintingThreshold :
if self.resizeToggle :
self.resizeToggle = not self.resizeToggle
self.oldVerticalValue = newVerticalValue
(To review, I use:
and py2app to deploy, not that it is relevant in this case.)