[solved]A listView in a listview
-
Hi,
I manage to put a listview in a listview, but I don't know how to handle models
I want to do something like that
@import QtQuick 1.0
Rectangle {
id: root
width: 300
height: 200ListModel {
id: myModelColumn
ListElement {
ListModel {
id: myModelRow
ListElement{rect_width:50 ; rect_color"#ff0000"}
ListElement{rect_width:30 ; rect_color"#ffff00"}
ListElement{rect_width:40 ; rect_color"#ffffcc"}
}
}
ListElement {
ListModel {
id: myModelRow
ListElement{rect_width:30 ; rect_color"#ffff00"}
ListElement{rect_width:40 ; rect_color"#ffffcc"}
ListElement{rect_width:50 ; rect_color"#ff0000"}
}
}
//...
}Component {
id: myDelegateRow
Rectangle
{
height:parent.height
width:rect_width
color:rect_color
}
}Component {
id: myDelegateColumn
ListView {
width: rectangle1.width
height: 20
model: myModelRow
delegate: myDelegateRow
orientation: "Horizontal"
}
}ListView {
anchors.fill: parent
model: myModelColumn
delegate: myDelegateColumn
orientation: "Vertical"
}}@
But i've got an error :" ListElement: cannot contain nested elements"
Thanks
-
Try:
@ListElement {
myModelRow: ListModel {
ListElement{rect_width:30 ; rect_color: "#ffff00"}
ListElement{rect_width:40 ; rect_color: "#ffffcc"}
ListElement{rect_width:50 ; rect_color: "#ff0000"}
}
}@I've done this but I have the code at home and don't remember the exact syntax. Tell me if this doesn't work.
-
Thanks, I haven't thought that way but that still not work.
I have reduce the code if you want to try@import QtQuick 1.0
Rectangle {
id: root
width: 300
height: 200ListModel {
id: myModelColumn
ListElement {
myModelRow:ListModel {
ListElement{rect_width:50}
ListElement{rect_width:30}
ListElement{rect_width:40}
}
}//...
}Component {
id: myDelegateRow
Rectangle
{
height:parent.height
width:rect_width
color:"red"
border.color: "#000000"
}
}Component {
id: myDelegateColumn
ListView {
width: rectangle1.width
height: 20
model: myModelRow
delegate: myDelegateRow
orientation: "Horizontal"
}
}ListView {
anchors.fill: parent
model: myModelColumn
delegate: myDelegateColumn
orientation: "Vertical"
}}@