Results 1 to 2 of 2

Thread: Listview inside repeater - model

  1. #1
    Join Date
    Mar 2016
    Posts
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Listview inside repeater - model

    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:

    Qt Code:
    1. Column {
    2. Repeater {
    3. model: ?? // This number (number of lists) depends on some data in C++
    4. Rectangle {
    5. ListView {
    6. orientation: ListView.Horizontal
    7. model: ?? // There will be more than one list --> Question: How to assign different models to list
    8. delegate: Rectangle {
    9. Text {
    10. text: somemodelproperty
    11. }
    12. }
    13. }
    14. }
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Listview inside repeater - model

    Assuming you have a list of models in C++, then you can either use a C++ property that makes that list accessible, or you write a simple list model that has one role which returns the model at the given index.

    Depends mostly on how dynamic the number of model is.
    If it changes often, the list model approach will be better, as the repeater can then specifically destroy/create entries.

    Cheers,
    _

Similar Threads

  1. Increment a property inside repeater delegate
    By beemaneni in forum Qt Quick
    Replies: 3
    Last Post: 8th May 2015, 08:32
  2. ListView problem with c++ model
    By nick85 in forum Qt Quick
    Replies: 7
    Last Post: 12th September 2013, 10:33
  3. ListView inside another element
    By Dp0H in forum Qt Quick
    Replies: 0
    Last Post: 24th September 2012, 13:44
  4. Modify c++ model data from QML Repeater
    By laszlo.gosztola in forum Qt Quick
    Replies: 7
    Last Post: 19th October 2011, 15:35
  5. ListView model binding to QAbstractListModel
    By michalk in forum Qt Quick
    Replies: 1
    Last Post: 16th July 2011, 10:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.