Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to detect Scroll Up intention



  • Hi all,

    I am creating a chat application, and when my user opens the conversation only the last 20 messages are displayed. What I want to do, is when the user scrolls up , show him the previous messages, kind of like WhatsApp does.
    I am using ListView item in QML (QtQuick2), and I need to detect that the user has made an intention to scroll higher than current amount of messages and upon detecting this event, launch a call to the server to get the messages.
    What signal/slots should I use to achieve this behaviour?
    (I working with Android and Desktop platforms)

    TIA


  • Moderators

    @Nulik
    Are you using a C++ (QAbstractItemModel) for your QML ListView?
    If so the ListView calls fetchMore() on the model when scrolled to the end.

    ListView inherits Flickable QML type, which does the scrolling and provides various properties and signals



  • @raven-worx said in How to detect Scroll Up intention:

    @Nulik
    Are you using a C++ (QAbstractItemModel) for your QML ListView?
    If so the ListView calls fetchMore() on the model when scrolled to the end.

    Yes , I am using C++ class with QAbstractItemModel as parent class.

    ListView inherits Flickable QML type, which does the scrolling and provides various properties and signals

    ok, will look at that, thanks!


  • Moderators

    @Nulik
    so in that case you simply need to implement canFetchMore() and fetchMore().
    in fetchMore() method you need to request the data. When you receivedthe data simply insert the rows into the model with beginInsertRows()/endInsertRows().
    The rest is already handled by ListView


Log in to reply