PDA

View Full Version : Master - Detail in QML ListViews. A ListView with a delegate with another ListView.



lqsa
12th May 2016, 23:13
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.


// A ListView
ListView {
model: personModels
delegate: Row {
Text {
text: model.name
}
Text {
text: model.street
}
...
// B ListView
ListView {
model: ????
delegate: Row {
Text {
text: model.carColor
}
}
}
}
}

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

How can I do it?

anda_skoa
13th May 2016, 10:01
You need a property in "personModels" that contains the cars for that person.
Then you can just write something like


model: model.cars


What's the type behind "personsModels"?

Cheers,
_

lqsa
16th May 2016, 23:50
Yes, it work's, but in the QML can't put model., it gives error.

It must be:


model: cars

Cheers