我想将非常大的文件的一部分加载到Python PyQt上的QListWidget中。当用户移动QListWidget的滚动条并到达滚动条的末尾时,该事件正在激活,并且文件的下一部分正在加载(追加)到QListWidget。是否有一些事件可以控制滚动条的结束位置?
答案 0 :(得分:2)
没有“滚动到结束”的专用信号,但您可以在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和信号槽框架的文档。