Frage

I'm using a QListView which wraps a very simple list model. I would like to try implementing something similar to the "infinite scroll" seen in some web pages.

Currently the model is updated by a method which adds at most 100 items (they're taken from an external web API which takes at most 100 items per call). My goal: when the user moves to the last element of the list view (in my case, by scrolling down) I would like to start a call to get up to 100 more items, and so on.

To simplify in this example:

  1. Populate the list with 100 items
  2. View scrolled down (by user) to the bottom
  3. Other 100 items fetched.

Is there anything in QListView that tells me when I'm at the end of the visible view?

War es hilfreich?

Lösung

QListView is a subclass of QAbstractScrollArea, so one way of finding out if the vertical scroll bar's position is at one of its extremes is to:

  1. Get the QScrollBar object used by QListView by calling verticalScrollBar().
  2. Connect the sliderMoved(int value) signal of the scroll bar to a slot of your choice.
  3. In the slot, fetch the min/max values of the scroll bar and compare them to the value given in the signal.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top