Unsolved CheckBox or ComboBox loose state in ListView if not displayed
-
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+" €" } } } }
-
Facing the same Issue.