以下是一个概念验证示例:class Widget(QtGui.QWidget):
def __init__(self):
super(Widget, self).__init__()
self.resize(600,400)
layout = QtGui.QVBoxLayout(self)
self.table = QtGui.QTableWidget(20,10)
self.vBar = self.table.verticalScrollBar()
self._vBar_lastVal = self.vBar.value()
layout.addWidget(self.table)
self.vBar.valueChanged.connect(self.scrollbarChanged)
def scrollbarChanged(self, val):
bar = self.vBar
minVal, maxVal = bar.minimum(), bar.maximum()
avg = (minVal+maxVal)/2
rowCount = self.table.rowCount()
# scrolling down
if val > self._vBar_lastVal and val >= avg:
self.table.insertRow(rowCount)
# scrolling up
elif val < self._vBar_lastVal:
lastRow = rowCount-1
empty = True
for col in xrange(self.table.