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
Forum Updated to NodeBB v4.3 + New Features

QML ListView inside Repeater

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlrepeaterlistviewmodelc++
2 Posts 2 Posters 2.2k 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.
  • Q Offline
    Q Offline
    Qmyo
    wrote on 17 May 2016, 10:44 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.

    P 1 Reply Last reply 17 May 2016, 12:30
    0
    • Q Qmyo
      17 May 2016, 10:44

      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.

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 17 May 2016, 12:30 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

      2/2

      17 May 2016, 12:30

      • Login

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