Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [solved]A listView in a listview
Forum Updated to NodeBB v4.3 + New Features

[solved]A listView in a listview

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Merinas
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mario
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Merinas
        wrote on last edited by
        #3

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

        }@

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mario
          wrote on last edited by
          #4

          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}
          ]
          }
          }
          @

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Merinas
            wrote on last edited by
            #5

            Ah, great that's working fine.

            Thanks a lot.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved