Results 1 to 3 of 3

Thread: Master - Detail in QML ListViews. A ListView with a delegate with another ListView.

  1. #1
    Join Date
    Nov 2014
    Posts
    33
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Master - Detail in QML ListViews. A ListView with a delegate with another ListView.

    I have a ListView (A) that on it's delegate has another ListView (B). How can (B) objects change when the user changes from one item to another in (A)?

    For exemple:

    Imagine that I have a list of persons, and every person has a list of cars:
    - Person1 - car1, car2, car3
    - Person2 - car4
    - Person3 - car5, car6, car7, car8
    - Person4 - car9, car10
    ...

    The QML has a ListView (A) that it's delegate has another ListView (B). The parent ListView (A) shows the Person data, and the detail ListView (B) must show the cars of that person.

    Qt Code:
    1. // A ListView
    2. ListView {
    3. model: personModels
    4. delegate: Row {
    5. Text {
    6. text: model.name
    7. }
    8. Text {
    9. text: model.street
    10. }
    11. ...
    12. // B ListView
    13. ListView {
    14. model: ????
    15. delegate: Row {
    16. Text {
    17. text: model.carColor
    18. }
    19. }
    20. }
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

    The problem is that the second ListView must change the model for every item in ListView A.

    How can I do it?

  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: Master - Detail in QML ListViews. A ListView with a delegate with another ListVie

    You need a property in "personModels" that contains the cars for that person.
    Then you can just write something like
    Qt Code:
    1. model: model.cars
    To copy to clipboard, switch view to plain text mode 

    What's the type behind "personsModels"?

    Cheers,
    _

  3. #3
    Join Date
    Nov 2014
    Posts
    33
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Master - Detail in QML ListViews. A ListView with a delegate with another ListVie

    Yes, it work's, but in the QML can't put model., it gives error.

    It must be:

    Qt Code:
    1. model: cars
    To copy to clipboard, switch view to plain text mode 

    Cheers

Similar Threads

  1. Display decoration in listview delegate
    By manuelschneid3r in forum Qt Quick
    Replies: 1
    Last Post: 4th January 2016, 14:40
  2. Replies: 1
    Last Post: 5th December 2015, 12:38
  3. Replies: 11
    Last Post: 16th October 2015, 15:34
  4. Replies: 6
    Last Post: 21st May 2015, 20:53
  5. Replies: 1
    Last Post: 23rd June 2012, 14:23

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.