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. [SOLVED] ListView and dynamically creatable delegate
Qt 6.11 is out! See what's new in the release blog

[SOLVED] ListView and dynamically creatable delegate

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 3 Posters 4.4k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi!

    How to create a delegate to the item only when it is really needed?

    My current solution: delegate: OwnDelegate {}

    This solution doesn't work. The problem is that this solution causes calling of fetchMore() function of the model. In other words it tries to build a delegate to every item of the model when initializing ListView. There can be over 30 000 items in the model.

    More information about the datastructure of the model in this "thread":http://qt-project.org/forums/viewthread/15275/

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      I would do this in C++ with a class inheriting from QAbstractListModel. See http://doc.qt.nokia.com/4.7-snapshot/qdeclarativemodels.html#qabstractitemmodel for an example.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        task_struct
        wrote on last edited by
        #3

        Hi,

        See ListView's property "cacheBuffer":http://doc.qt.nokia.com/4.7-snapshot/qml-listview.html#cacheBuffer-prop . You got delegate instances only for visible items in the list.

        "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

        • Linu...
        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          My model is inherited from QAbstractListModel.

          I tried cacheBuffer but this doesn't solve the problem. Despite of cacheBuffer fetchMore() function is still called. It seems that ListView wants fetch all the items before ListView can be shown.

          I don't want that fetchMore() function is called before it is really needed.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            task_struct
            wrote on last edited by
            #5

            Which function calls fetchMore() ? Is it something from the model or something from ListView?

            "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

            • Linu...
            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              QAbstractItemView calls it

              QAbstractItemModel documentation says:
              "If canFetchMore() returns true, QAbstractItemView will call fetchMore(). However, the fetchMore() function is only called when the model is being populated incrementally."

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                Problem solved

                It is embarrasing to admit that it was all my mistake.

                The problem was that I hadn't defined height to the delegate. That's why unlimited number of items could fit to the listview.

                I certainly have learned my lesson.

                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