Infinite scrolling of a TableView



  • Hi all,
    Is it possible to create a QML TableView with infinite scrolling, so I can load more data into it dynamically when the scroll reaches the end?
    For example, this is possible on a ListView using the code below, but I couldn't find a way to do it on a TableView:
    onAtYEndChanged: {
    if(atYEnd) sigEndOfListReached()
    }
    Thank you,
    Bruno.


  • Moderators

    Yes, it can be done in the same way as in all Qt's MVC classes: subclass QAbstractItemModel and reimplement canFetchMore() and fetchMore() methods. It might look scary at first sight, but is really super-easy.



  • Hi Sierdzio, thank you for the quick response, but that's not the kind of solution I'm looking for.
    I don't want to subclass QAbstractItemModel for each TableView I have (many!). Meanwhile, I just created a navigation bar where the user can move backward/forward manually. :-(
    Thanks again/Bruno.


  • Moderators

    Nobody forces you to subclass QAbstractItemModel multiple times. Just like ListModel can work on different data, so can the QAbstractItemModel, when applied carefully. As for navigation: QtQuick.Controls have a built-in ScrollBar item, if you are interested.

    If you still want to do it purely in QML, though, here is an idea:

    TableView {
        onCurrentRowChanged: {
            if (currentRow > (0.9 * rowCount)) {
                // insert more rows
            }
        }
    }


Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.