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. Facing an issue with Listview in Repeater
Forum Updated to NodeBB v4.3 + New Features

Facing an issue with Listview in Repeater

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 173 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.
  • P Offline
    P Offline
    Praveen.Illa
    wrote on last edited by
    #1

    Hi Team,

    I am trying to control the visibility of the listview control on every button click for respective data model.
    But, I am getting below errors at "visible: buttonRepeater.model.expanded"
    Unable to assign [undefined] to bool
    Unable to assign [undefined] to bool
    Unable to assign [undefined] to bool

    I am not sure what is wrong.
    Can someone please help me in sorting out. Thank you

    import QtQuick
    import QtQuick.Controls
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480
    
        ListModel {
            id: groupModel
            ListElement {
                name: "Model 1"
                expanded: false
            }
            ListElement {
                name: "Model 2"
                expanded: false
            }
            ListElement {
                name: "Model 3"
                expanded: false
            }
        }
    
        ListModel {
            id: model1Items
            ListElement { description: "Item 1.1" }
            ListElement { description: "Item 1.2" }
            ListElement { description: "Item 1.3" }
        }
    
        ListModel {
            id: model2Items
            ListElement { description: "Item 2.1" }
            ListElement { description: "Item 2.2" }
            ListElement { description: "Item 2.3" }
        }
    
        ListModel {
            id: model3Items
            ListElement { description: "Item 3.1" }
            ListElement { description: "Item 3.2" }
            ListElement { description: "Item 3.3" }
        }
    
        Column {
            anchors.fill: parent
            spacing: 10
    
            Repeater {
                id: buttonRepeater
                model: groupModel
    
                delegate: Column {
                    width: parent.width
    
                    Button {
                        text: model.name
                        onClicked: {
                            groupModel.setProperty(index, "expanded", !model.expanded)
                        }
                    }
    
                    ListView {
                        id: listView
                        width: parent.width
                        height: contentHeight
                        visible: buttonRepeater.model.expanded
                        model: buttonRepeater.model.name === "Model 1" ? model1Items :
                               buttonRepeater.model.name === "Model 2" ? model2Items :
                               model3Items
    
                        delegate: Item {
                            width: parent.width
                            height: 30
    
                            Text {
                                anchors.centerIn: parent
                                text: model.description
                            }
                        }
                    }
                }
            }
        }
    }
    
    
    jeremy_kJ 1 Reply Last reply
    0
    • P Praveen.Illa

      Hi Team,

      I am trying to control the visibility of the listview control on every button click for respective data model.
      But, I am getting below errors at "visible: buttonRepeater.model.expanded"
      Unable to assign [undefined] to bool
      Unable to assign [undefined] to bool
      Unable to assign [undefined] to bool

      I am not sure what is wrong.
      Can someone please help me in sorting out. Thank you

      import QtQuick
      import QtQuick.Controls
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480
      
          ListModel {
              id: groupModel
              ListElement {
                  name: "Model 1"
                  expanded: false
              }
              ListElement {
                  name: "Model 2"
                  expanded: false
              }
              ListElement {
                  name: "Model 3"
                  expanded: false
              }
          }
      
          ListModel {
              id: model1Items
              ListElement { description: "Item 1.1" }
              ListElement { description: "Item 1.2" }
              ListElement { description: "Item 1.3" }
          }
      
          ListModel {
              id: model2Items
              ListElement { description: "Item 2.1" }
              ListElement { description: "Item 2.2" }
              ListElement { description: "Item 2.3" }
          }
      
          ListModel {
              id: model3Items
              ListElement { description: "Item 3.1" }
              ListElement { description: "Item 3.2" }
              ListElement { description: "Item 3.3" }
          }
      
          Column {
              anchors.fill: parent
              spacing: 10
      
              Repeater {
                  id: buttonRepeater
                  model: groupModel
      
                  delegate: Column {
                      width: parent.width
      
                      Button {
                          text: model.name
                          onClicked: {
                              groupModel.setProperty(index, "expanded", !model.expanded)
                          }
                      }
      
                      ListView {
                          id: listView
                          width: parent.width
                          height: contentHeight
                          visible: buttonRepeater.model.expanded
                          model: buttonRepeater.model.name === "Model 1" ? model1Items :
                                 buttonRepeater.model.name === "Model 2" ? model2Items :
                                 model3Items
      
                          delegate: Item {
                              width: parent.width
                              height: 30
      
                              Text {
                                  anchors.centerIn: parent
                                  text: model.description
                              }
                          }
                      }
                  }
              }
          }
      }
      
      
      jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      @Praveen-Illa said in Facing an issue with Listview in Repeater:

      Hi Team,

      I am trying to control the visibility of the listview control on every button click for respective data model.
      But, I am getting below errors at "visible: buttonRepeater.model.expanded"
      Unable to assign [undefined] to bool

      Edited to emphasize the problem:

              Repeater {
                  id: buttonRepeater
                  model: groupModel
      
                  delegate: Column {
                      ListView {
                          visible: buttonRepeater.model.expanded
                      }
                  }
              }
      

      buttonRepeater.model.expanded is attempting to access a property called expanded in buttonRepeater's model, not a role called expanded within a row of the model. Printing the values of buttonRepeater and buttonRepeater.model should make this clear.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      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