[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: 200

    ListModel {
    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: 200

    ListModel {
    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"
    }

    }@



  • Ah, found it! You should write the myModelRow as an array of ListElement's :)

    @
    ListModel {
    id: myModelColumn
    ListElement {
    myModelRow: [
    ListElement{rect_width:50},
    ListElement{rect_width:30},
    ListElement{rect_width:40}
    ]
    }
    }
    @



  • Ah, great that's working fine.

    Thanks a lot.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.