Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Is it possible to use QML ListView as "pagination"
Forum Updated to NodeBB v4.3 + New Features

Is it possible to use QML ListView as "pagination"

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wiru
    wrote on last edited by
    #1

    Is there a way to handle large amount of data with a ListView to reduce server load? Generally speaking, something like a pagination, but not the standard type where user selects Page 1, 2 ,3... but rather request data while scrolling.

    I know that when using a ListView items not in screen are not rendered, so that part is fine, but the issue is when requesting data from api. If I have a large data set, it takes some time to load it all and create the delegate for the ListView. So the general idea would be to use limit and offset on the api call, to request data only for the first x items, and if user scrolls, fetch data for the next x items.

    Since I can't count on currentIndex (because the user can scroll the list without selecting/changing the current item) I can't use it to calculate limit/offset.

    I know the total count of items in the list, so I could try to limit the ListView model to e.g. 20 items, and when the user scrolls to the end, request next 20 items and extend the model (if that's possible).

    All in all, I was hoping for some suggestions and feedback on the idea, or if anyone had some similar case, how did they handle it?

    J.HilkJ 1 Reply Last reply
    0
    • W Wiru

      Is there a way to handle large amount of data with a ListView to reduce server load? Generally speaking, something like a pagination, but not the standard type where user selects Page 1, 2 ,3... but rather request data while scrolling.

      I know that when using a ListView items not in screen are not rendered, so that part is fine, but the issue is when requesting data from api. If I have a large data set, it takes some time to load it all and create the delegate for the ListView. So the general idea would be to use limit and offset on the api call, to request data only for the first x items, and if user scrolls, fetch data for the next x items.

      Since I can't count on currentIndex (because the user can scroll the list without selecting/changing the current item) I can't use it to calculate limit/offset.

      I know the total count of items in the list, so I could try to limit the ListView model to e.g. 20 items, and when the user scrolls to the end, request next 20 items and extend the model (if that's possible).

      All in all, I was hoping for some suggestions and feedback on the idea, or if anyone had some similar case, how did they handle it?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      hi @Wiru
      if you have an AbstractItemModel (c++) as a base for your model, you can/should implement the canFetchMoreand fetchMore methods for a dynamic loading of the data.

      The this example
      https://doc.qt.io/qt-5/qtwidgets-itemviews-fetchmore-example.html

      for a more detailed view


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      W 2 Replies Last reply
      0
      • J.HilkJ J.Hilk

        hi @Wiru
        if you have an AbstractItemModel (c++) as a base for your model, you can/should implement the canFetchMoreand fetchMore methods for a dynamic loading of the data.

        The this example
        https://doc.qt.io/qt-5/qtwidgets-itemviews-fetchmore-example.html

        for a more detailed view

        W Offline
        W Offline
        Wiru
        wrote on last edited by Wiru
        #3

        @J-Hilk I'm handling the api call in javascript and create an object that's then used as the model for the ListView. I was also considering in making a custom ListView component based on the ListView class. But if possible, I'd rather not, as it would increase the complexity.

        Edit: This fetchMore definitely seems like something that would be great to have. I'll check it out more.

        1 Reply Last reply
        0
        • J.HilkJ J.Hilk

          hi @Wiru
          if you have an AbstractItemModel (c++) as a base for your model, you can/should implement the canFetchMoreand fetchMore methods for a dynamic loading of the data.

          The this example
          https://doc.qt.io/qt-5/qtwidgets-itemviews-fetchmore-example.html

          for a more detailed view

          W Offline
          W Offline
          Wiru
          wrote on last edited by
          #4

          @J-Hilk Quick question regarding beginInsertRows(), do you by chance know if it resets the ListViws current item/index? It's important for me to keep the selected item intact, e.g. if current index is 5, and it inserts 10 more items, it keeps item at index 5 selected.

          I did some research about dynamic ListView models, but in all examples, once the model is extended/updated, ListView resets to index 0, losing users selected item.

          J.HilkJ 1 Reply Last reply
          0
          • W Wiru

            @J-Hilk Quick question regarding beginInsertRows(), do you by chance know if it resets the ListViws current item/index? It's important for me to keep the selected item intact, e.g. if current index is 5, and it inserts 10 more items, it keeps item at index 5 selected.

            I did some research about dynamic ListView models, but in all examples, once the model is extended/updated, ListView resets to index 0, losing users selected item.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @Wiru
            I don't know for sure, but I think it simply resets the currentItem/Index

            I'm not an expert in the model view field, so maybe someone else can give you a better/more detailed answer


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            0
            • k03rdt6K Offline
              k03rdt6K Offline
              k03rdt6
              wrote on last edited by k03rdt6
              #6
              This post is deleted!
              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved