Question

I want to load some part of the very big file into my QListWidget on Python PyQt. When user moves the scrollbar of the QListWidget and reaches the end of the scrollbar, the event is activating and the next part of the file is loading (appends) to the QListWidget. Is there some event for controlling the end position of the scrollbar?

Était-ce utile?

La solution

There's no dedicated signal for "scrolled to end", but you can easily check that in the valueChanged signal:

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))

EDIT:

Or, within a class:

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

You should probably catch up on the docs for lambda's and the signal-slot framework in general.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top