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. QML ListView multiple delegates
Qt 6.11 is out! See what's new in the release blog

QML ListView multiple delegates

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 4 Posters 15.6k 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.
  • B Offline
    B Offline
    bunjee
    wrote on last edited by
    #1

    Greetings Qt Devs,

    I'm using a ListView. Is it possible to specify multiple delegates based on what the model item contains ?

    For instance:

    • if my item has a parameter containing "green" I specify a green Rectangle delegate item.
    • If my item has a parameter containing "string" I specify a Text delegate item.

    Thanks.

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      I think you'll need to make a single delegate that conditionally changes the visible property of its child items depending upon the values in the model. A single view can only create a single type of delegate as far as I am aware.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mario
        wrote on last edited by
        #3

        Loader with a condition on the source could also be used, but the performance will for sure drop quite a lot.

        1 Reply Last reply
        0
        • W Offline
          W Offline
          wladek
          wrote on last edited by
          #4

          Hi bunjee,
          Take a look at this: "http://cdumez.blogspot.com/2010/11/heterogeneous-list-model-in-qml.html":http://cdumez.blogspot.com/2010/11/heterogeneous-list-model-in-qml.html
          I think this is what you are looking for.

          Regards,
          wladek

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bunjee
            wrote on last edited by
            #5

            Thanks guys,

            I thought about the "loading" condition. I guess the performance might hurt a bit.

            Best current option is probably hiding / showing specific parts. Not the most elegant way.

            Ideally I think this should be taken care of in C++. A multi delegate ListView could be a good idea to code.

            1 Reply Last reply
            0
            • W Offline
              W Offline
              wladek
              wrote on last edited by
              #6

              Hi bunjee,

              From my experience I can assure you that the "loading" condition is by far the better from performance point of view. I had a large delegate that defined all my widgets, and I did exactly as you said....hide/show specific parts. The interface suffered a "hung" effect, and after changing to the "Loader" it worked nicely.

              You should try it yourself the both ways and see which one pleases you.

              regards,
              Wladek

              1 Reply Last reply
              0
              • B Offline
                B Offline
                bunjee
                wrote on last edited by
                #7

                Hey Wladek,

                Alright, I'll try your way ! Thanks for the code.

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  bunjee
                  wrote on last edited by
                  #8

                  Looks like it's working pretty good.

                  I wonder if the Loader has some kind of cache under the hood to maximize performance.

                  Thanks.

                  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