Python PyQt 滚动条到达末尾事件
我想把一个非常大的文件的一部分加载到我的QListWidget里,使用的是Python的PyQt。当用户移动QListWidget的滚动条并到达滚动条的底部时,就会触发一个事件,然后把文件的下一部分加载(追加)到QListWidget里。有没有什么事件可以用来控制滚动条的结束位置呢?
1 个回答
3
没有专门的信号来表示“滚动到最后”,但是你可以很简单地在 valueChanged
信号中检查这一点:
def scrolled(scrollbar, value):
if value == scrollbar.maximum():
print 'reached max' # that will be the bottom/right end
if value == scrollbar.minimum():
print 'reached min' # top/left end
scrollBar = listview.verticalScrollBar()
scrollBar.valueChanged.connect(lambda value: scrolled(scrollBar, value))
补充:
或者,在一个类里面:
class MyWidget(QWidget):
def __init__(self):
# here goes the rest of your initialization code
# like the construction of your listview
# connect the valueChanged signal:
self.listview.verticalScrollBar().valueChanged.connect(self.scrolled)
# your parameter "f"
self.f = 'somevalue' # whatever
def scrolled(self, value):
if value == self.listview.verticalScrollBar().maximum():
self.loadNextChunkOfData()
def loadNextChunkOfData(self):
# load the next piece of data and append to the listview
你可能需要多看看关于 lambda 表达式和信号-槽机制的文档,这样会更有帮助。