Using TableView as ListView-delegate
-
I have a
modelthat contains severalQStandardItemModels. Now I want to create a view that displays aTableViewfor each of theseQStandardItemModels.
I had the idea to have aListViewthat has aTableViewas delegate, something like this:ListView { id: myListView anchors { fill: parent margins: 5 } model: testModel delegate: CompareDelegate { } }And in
CompareDelegate.qml:Item { id: base width: 500 height: 300 TableView { anchors.fill: parent } }How do I get the
TableViewinside the delegate to use the appropriateQStandardItemModelwithin the model of theListView?
I hope the question is somewhat clear.Thanks in advance.
-
I have a
modelthat contains severalQStandardItemModels. Now I want to create a view that displays aTableViewfor each of theseQStandardItemModels.
I had the idea to have aListViewthat has aTableViewas delegate, something like this:ListView { id: myListView anchors { fill: parent margins: 5 } model: testModel delegate: CompareDelegate { } }And in
CompareDelegate.qml:Item { id: base width: 500 height: 300 TableView { anchors.fill: parent } }How do I get the
TableViewinside the delegate to use the appropriateQStandardItemModelwithin the model of theListView?
I hope the question is somewhat clear.Thanks in advance.
@qwasder85 A simple way would be to keep a
Q_INVOKABLEfunction or a public slot in your model which will return these individualQStandardItemModelsbased on some property. Now since theTableViewis inside the delegate assigned toListViewyou can make use ofindexproperty and pass it to the function which will return the model. Something likeItem { id: base ... TableView { anchors.fill: parent model: myListView.model.getModel(index) //or testModel.getModel(index) } } -
@qwasder85 A simple way would be to keep a
Q_INVOKABLEfunction or a public slot in your model which will return these individualQStandardItemModelsbased on some property. Now since theTableViewis inside the delegate assigned toListViewyou can make use ofindexproperty and pass it to the function which will return the model. Something likeItem { id: base ... TableView { anchors.fill: parent model: myListView.model.getModel(index) //or testModel.getModel(index) } }