QML ListView inside Repeater



  • 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.


  • Moderators

    @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.



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.