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. CheckBox or ComboBox loose state in ListView if not displayed
Qt 6.11 is out! See what's new in the release blog

CheckBox or ComboBox loose state in ListView if not displayed

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 877 Views 2 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.
  • SikarjanS Offline
    SikarjanS Offline
    Sikarjan
    wrote on last edited by
    #1

    Hi,

    I am reading a XML file and want to display all the options form this XML file in a ListView. The delegate I use to display the options is a Row with a CheckBox, ComboBox and Text. There are more options than can be displayed but the ListView is flickable and I can scroll through all the options. My problem is that selected Options loose their checked state/index without a signal beeing triggerd if they are not displayed. Is this a bug or a feature?
    How can I prevent this from happening? Also if a add a property to the row holding the last checked stated it will be silently reset as soon as the row is not in view anymore. If you want to try copy this code in the Hello World main.qml (no ui).

    Thanks

    import QtQuick 2.6
    import QtQuick.Controls 1.5
    
    ApplicationWindow {
        id: root
        visible: true
        width: 640
        height: 480
        title: qsTr("Test World")
    
        property real moneySpent: 0
    
        menuBar: MenuBar {
            Menu {
                title: qsTr("File")
                MenuItem {
                    text: qsTr("&Open")
                    onTriggered: console.log("Open action triggered");
                }
                MenuItem {
                    text: qsTr("Exit")
                    onTriggered: Qt.quit();
                }
            }
        }
        toolBar: ToolBar {
            Label {
                text: "Total Spent: "+root.moneySpent
            }
        }
    
        ListModel {
            id: testModel
    
            ListElement { name: "Apple";    cost: 2.45 }
            ListElement { name: "Orange";   cost: 3.25 }
            ListElement { name: "Banana";   cost: 1.95 }
            ListElement { name: "Mango";    cost: 4.45 }
            ListElement { name: "Pineapple"; cost: 3.95}
            ListElement { name: "Blueberries";cost: 4.95}
            ListElement { name: "Apple";    cost: 2.45 }
            ListElement { name: "Orange";   cost: 3.25 }
            ListElement { name: "Banana";   cost: 1.95 }
            ListElement { name: "Mango";    cost: 4.45 }
            ListElement { name: "Pineapple"; cost: 3.95}
            ListElement { name: "Blueberries";cost: 4.95}
            ListElement { name: "Apple";    cost: 2.45 }
            ListElement { name: "Orange";   cost: 3.25 }
            ListElement { name: "Banana";   cost: 1.95 }
            ListElement { name: "Mango";    cost: 4.45 }
            ListElement { name: "Pineapple"; cost: 3.95}
            ListElement { name: "Blueberries";cost: 4.95}
            ListElement { name: "Apple";    cost: 2.45 }
            ListElement { name: "Orange";   cost: 3.25 }
            ListElement { name: "Banana";   cost: 1.95 }
            ListElement { name: "Mango";    cost: 4.45 }
            ListElement { name: "Pineapple"; cost: 3.95}
            ListElement { name: "Blueberries";cost: 4.95}
            ListElement { name: "Apple";    cost: 2.45 }
            ListElement { name: "Orange";   cost: 3.25 }
            ListElement { name: "Banana";   cost: 1.95 }
            ListElement { name: "Mango";    cost: 4.45 }
            ListElement { name: "Pineapple"; cost: 3.95}
            ListElement { name: "Blueberries";cost: 4.95}
            ListElement { name: "Apple";    cost: 2.45 }
            ListElement { name: "Orange";   cost: 3.25 }
            ListElement { name: "Banana";   cost: 1.95 }
            ListElement { name: "Mango";    cost: 4.45 }
            ListElement { name: "Pineapple"; cost: 3.95}
            ListElement { name: "Blueberries";cost: 4.95}
            ListElement { name: "Apple";    cost: 2.45 }
            ListElement { name: "Orange";   cost: 3.25 }
            ListElement { name: "Banana";   cost: 1.95 }
            ListElement { name: "Mango";    cost: 4.45 }
            ListElement { name: "Pineapple"; cost: 3.95}
            ListElement { name: "Blueberries";cost: 4.95}
            ListElement { name: "Apple";    cost: 2.45 }
            ListElement { name: "Orange";   cost: 3.25 }
            ListElement { name: "Banana";   cost: 1.95 }
            ListElement { name: "Mango";    cost: 4.45 }
            ListElement { name: "Pineapple"; cost: 3.95}
            ListElement { name: "Blueberries";cost: 4.95}
            ListElement { name: "Apple";    cost: 2.45 }
            ListElement { name: "Orange";   cost: 3.25 }
            ListElement { name: "Banana";   cost: 1.95 }
            ListElement { name: "Mango";    cost: 4.45 }
            ListElement { name: "Pineapple"; cost: 3.95}
            ListElement { name: "Blueberries";cost: 4.95}
            ListElement { name: "Apple";    cost: 2.45 }
            ListElement { name: "Orange";   cost: 3.25 }
            ListElement { name: "Banana";   cost: 1.95 }
            ListElement { name: "Mango";    cost: 4.45 }
            ListElement { name: "Pineapple"; cost: 3.95}
            ListElement { name: "Blueberries";cost: 4.95}
            ListElement { name: "Apple";    cost: 2.45 }
            ListElement { name: "Orange";   cost: 3.25 }
            ListElement { name: "Banana";   cost: 1.95 }
            ListElement { name: "Mango";    cost: 4.45 }
            ListElement { name: "Pineapple"; cost: 3.95}
            ListElement { name: "Blueberries";cost: 4.95}
        }
    
        ListView {
            anchors.fill: parent
            spacing: 3
            model: testModel
    
            header: Component {
                Row{
                    Label {
                        text: qsTr("Market")
                    }
                }
            }
    
            delegate: Row {
                spacing: 3
                height: 20
    
                CheckBox {
                    id: testCheckBox
                    text: name
                    width: 100
    
                    onCheckedChanged: {
                        if(checked){
                            root.moneySpent += cost
                        }else{
                            root.moneySpent -= cost
                        }
                    }
                }
                ComboBox {
                    model: ["Take", "Ship", "Store"]
    
                    onCurrentIndexChanged: {
                        if(currentIndex > 0 && testCheckBox.checked)
                            root.moneySpent += 5
                    }
                }
                Text {
                    text: cost+" €"
                }
            }
        }
    }
    
    
    
    RohitSSR 1 Reply Last reply
    0
    • SikarjanS Sikarjan

      Hi,

      I am reading a XML file and want to display all the options form this XML file in a ListView. The delegate I use to display the options is a Row with a CheckBox, ComboBox and Text. There are more options than can be displayed but the ListView is flickable and I can scroll through all the options. My problem is that selected Options loose their checked state/index without a signal beeing triggerd if they are not displayed. Is this a bug or a feature?
      How can I prevent this from happening? Also if a add a property to the row holding the last checked stated it will be silently reset as soon as the row is not in view anymore. If you want to try copy this code in the Hello World main.qml (no ui).

      Thanks

      import QtQuick 2.6
      import QtQuick.Controls 1.5
      
      ApplicationWindow {
          id: root
          visible: true
          width: 640
          height: 480
          title: qsTr("Test World")
      
          property real moneySpent: 0
      
          menuBar: MenuBar {
              Menu {
                  title: qsTr("File")
                  MenuItem {
                      text: qsTr("&Open")
                      onTriggered: console.log("Open action triggered");
                  }
                  MenuItem {
                      text: qsTr("Exit")
                      onTriggered: Qt.quit();
                  }
              }
          }
          toolBar: ToolBar {
              Label {
                  text: "Total Spent: "+root.moneySpent
              }
          }
      
          ListModel {
              id: testModel
      
              ListElement { name: "Apple";    cost: 2.45 }
              ListElement { name: "Orange";   cost: 3.25 }
              ListElement { name: "Banana";   cost: 1.95 }
              ListElement { name: "Mango";    cost: 4.45 }
              ListElement { name: "Pineapple"; cost: 3.95}
              ListElement { name: "Blueberries";cost: 4.95}
              ListElement { name: "Apple";    cost: 2.45 }
              ListElement { name: "Orange";   cost: 3.25 }
              ListElement { name: "Banana";   cost: 1.95 }
              ListElement { name: "Mango";    cost: 4.45 }
              ListElement { name: "Pineapple"; cost: 3.95}
              ListElement { name: "Blueberries";cost: 4.95}
              ListElement { name: "Apple";    cost: 2.45 }
              ListElement { name: "Orange";   cost: 3.25 }
              ListElement { name: "Banana";   cost: 1.95 }
              ListElement { name: "Mango";    cost: 4.45 }
              ListElement { name: "Pineapple"; cost: 3.95}
              ListElement { name: "Blueberries";cost: 4.95}
              ListElement { name: "Apple";    cost: 2.45 }
              ListElement { name: "Orange";   cost: 3.25 }
              ListElement { name: "Banana";   cost: 1.95 }
              ListElement { name: "Mango";    cost: 4.45 }
              ListElement { name: "Pineapple"; cost: 3.95}
              ListElement { name: "Blueberries";cost: 4.95}
              ListElement { name: "Apple";    cost: 2.45 }
              ListElement { name: "Orange";   cost: 3.25 }
              ListElement { name: "Banana";   cost: 1.95 }
              ListElement { name: "Mango";    cost: 4.45 }
              ListElement { name: "Pineapple"; cost: 3.95}
              ListElement { name: "Blueberries";cost: 4.95}
              ListElement { name: "Apple";    cost: 2.45 }
              ListElement { name: "Orange";   cost: 3.25 }
              ListElement { name: "Banana";   cost: 1.95 }
              ListElement { name: "Mango";    cost: 4.45 }
              ListElement { name: "Pineapple"; cost: 3.95}
              ListElement { name: "Blueberries";cost: 4.95}
              ListElement { name: "Apple";    cost: 2.45 }
              ListElement { name: "Orange";   cost: 3.25 }
              ListElement { name: "Banana";   cost: 1.95 }
              ListElement { name: "Mango";    cost: 4.45 }
              ListElement { name: "Pineapple"; cost: 3.95}
              ListElement { name: "Blueberries";cost: 4.95}
              ListElement { name: "Apple";    cost: 2.45 }
              ListElement { name: "Orange";   cost: 3.25 }
              ListElement { name: "Banana";   cost: 1.95 }
              ListElement { name: "Mango";    cost: 4.45 }
              ListElement { name: "Pineapple"; cost: 3.95}
              ListElement { name: "Blueberries";cost: 4.95}
              ListElement { name: "Apple";    cost: 2.45 }
              ListElement { name: "Orange";   cost: 3.25 }
              ListElement { name: "Banana";   cost: 1.95 }
              ListElement { name: "Mango";    cost: 4.45 }
              ListElement { name: "Pineapple"; cost: 3.95}
              ListElement { name: "Blueberries";cost: 4.95}
              ListElement { name: "Apple";    cost: 2.45 }
              ListElement { name: "Orange";   cost: 3.25 }
              ListElement { name: "Banana";   cost: 1.95 }
              ListElement { name: "Mango";    cost: 4.45 }
              ListElement { name: "Pineapple"; cost: 3.95}
              ListElement { name: "Blueberries";cost: 4.95}
              ListElement { name: "Apple";    cost: 2.45 }
              ListElement { name: "Orange";   cost: 3.25 }
              ListElement { name: "Banana";   cost: 1.95 }
              ListElement { name: "Mango";    cost: 4.45 }
              ListElement { name: "Pineapple"; cost: 3.95}
              ListElement { name: "Blueberries";cost: 4.95}
          }
      
          ListView {
              anchors.fill: parent
              spacing: 3
              model: testModel
      
              header: Component {
                  Row{
                      Label {
                          text: qsTr("Market")
                      }
                  }
              }
      
              delegate: Row {
                  spacing: 3
                  height: 20
      
                  CheckBox {
                      id: testCheckBox
                      text: name
                      width: 100
      
                      onCheckedChanged: {
                          if(checked){
                              root.moneySpent += cost
                          }else{
                              root.moneySpent -= cost
                          }
                      }
                  }
                  ComboBox {
                      model: ["Take", "Ship", "Store"]
      
                      onCurrentIndexChanged: {
                          if(currentIndex > 0 && testCheckBox.checked)
                              root.moneySpent += 5
                      }
                  }
                  Text {
                      text: cost+" €"
                  }
              }
          }
      }
      
      
      
      RohitSSR Offline
      RohitSSR Offline
      RohitSS
      wrote on last edited by RohitSS
      #2

      Facing the same Issue.

      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