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 inside Repeater
QtWS25 Last Chance

QML ListView inside Repeater

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlrepeaterlistviewmodelc++
2 Posts 2 Posters 2.2k 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.
  • QmyoQ Offline
    QmyoQ Offline
    Qmyo
    wrote on last edited by
    #1

    Hi Guys,

    I want to display N horizontal lists. I put listview inside of repeater. N is a number of lists and it depends on some data in C++. Each list has its own model. I don't know how to properly register model for each list. Here is some sketch of code:

    Column {
        Repeater {
            model: ?? // This number (number of lists) depends on some data in C++
            Rectangle {
                ListView {
                    orientation: ListView.Horizontal
                    model: ?? // There will be more than one list --> Question: How to assign different models to list 
                    delegate: Rectangle {
                        Text {
                            text: somemodelproperty
                        }                
                    }
                }
            }
        }
    }
    

    I've found something like this:

    property var subModels: [m1, m2, ... m10]

    Then for the ListView inside the repeater delegate you can:

    ListView {
    model: subModels[index]
    // ...
    }

    but here is specific number of models, and I don't how how many of them I'll have.

    In C++, I have implemented QList <DataClass> list, and each list is "bounded" to a ListView by doing something like that:

        QQmlContext *ctxt = view.rootContext();
    
        ctxt->setContextProperty("myModel", &serviceList);
    

    Registering one model for one listview is just fine and it's working.

    p3c0P 1 Reply Last reply
    0
    • QmyoQ Qmyo

      Hi Guys,

      I want to display N horizontal lists. I put listview inside of repeater. N is a number of lists and it depends on some data in C++. Each list has its own model. I don't know how to properly register model for each list. Here is some sketch of code:

      Column {
          Repeater {
              model: ?? // This number (number of lists) depends on some data in C++
              Rectangle {
                  ListView {
                      orientation: ListView.Horizontal
                      model: ?? // There will be more than one list --> Question: How to assign different models to list 
                      delegate: Rectangle {
                          Text {
                              text: somemodelproperty
                          }                
                      }
                  }
              }
          }
      }
      

      I've found something like this:

      property var subModels: [m1, m2, ... m10]

      Then for the ListView inside the repeater delegate you can:

      ListView {
      model: subModels[index]
      // ...
      }

      but here is specific number of models, and I don't how how many of them I'll have.

      In C++, I have implemented QList <DataClass> list, and each list is "bounded" to a ListView by doing something like that:

          QQmlContext *ctxt = view.rootContext();
      
          ctxt->setContextProperty("myModel", &serviceList);
      

      Registering one model for one listview is just fine and it's working.

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @Qmyo You can create a 2 Q_INVOKABLE functions. One will return the Repeater's model number and other will return ListView's models. You can make use of index attached property which can be passed to the Q_INVOKABLE functions to return particular model.

      157

      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