各位高人:
我在listView里定义了model和delgate,把delegate的一个checkbox和mode的programEnabled绑定了,但是当checkbox发生变化时,model的值一直保持不变,请问这个是什么原因啊?
这个是读取model的函数
Button { id: buttonProgram text: qsTr("编程") function buttonProgramClicked() { var addrList = []; var itemCnt = listControlerModel.count; for (var i = 0; i < itemCnt; i++) { var tempModelItem = listControlerModel.get(i);
// programEnabled 不会根据视图上的值变化????? if(tempModelItem.programEnabled) { addrList.push(tempModelItem.ID); } } }
onClicked:buttonProgramClicked() }
这里是定义view,model,delgate的地方,其他的值都是对的,就是programEnabled不对
ListView { id: listControler width: 110 height: 160 anchors.top: parent.top// 这句话会让元素向上对齐,否则是居中对齐 anchors.topMargin: 0 Layout.fillWidth: true Layout.fillHeight: true clip:true // 设置为false会导致数据滑出窗外
model: ListModel { id: listControlerModel ListElement { ID: "1" type:"EVC41" SN: "12345" programEnabled:true colorCode: "black" // grey(off line) black(Not Check),pink(busy) red(Program Failed) green(Program OK) currentProgress:0 } ListElement { ID: "2" type:"EVC61" SN: "12346" programEnabled:true colorCode: "green" // grey(off line) black(Not Check) pink( busy )red(Program Failed) green(Program OK) currentProgress:100 } ListElement { ID: "3" type:"Unknow" SN: "Unknow" programEnabled:false colorCode: "pink" // grey(off line) black(Not Check) red(Program Failed) green(Program OK) currentProgress:50 } } Component { id: listControlerHead
Row { spacing: 5 Text { width: 40 height: 40 text: "升级"
} Text { width: 40 text: "地址" font.bold: true }
Text { width: 80 text: "类型" font.bold: true } Text { width: 80 text: "SN" font.bold: true } Text { width: 80 text: "状态" font.bold: true }
Text { width: 80 text: "进度" font.bold: true } } } header:listControlerHead delegate: Item { id: listControlerDelegate x: 5 width: parent.width height: 40
Row { spacing: 5 CheckBox { width: 40 height: 40 checked: programEnabled onCheckedChanged: { programEnabled = checked }
} Text { width: 40 text: ID anchors.verticalCenter: parent.verticalCenter font.bold: true }
Text { width: 80 text: type anchors.verticalCenter: parent.verticalCenter font.bold: true } Text { width: 80 text: SN anchors.verticalCenter: parent.verticalCenter font.bold: true } Rectangle { width: 20 height: 20 anchors.verticalCenter: parent.verticalCenter color: colorCode } ProgressBar { anchors.verticalCenter: parent.verticalCenter Layout.fillWidth: true maximumValue: 100 minimumValue : 0 value: currentProgress indeterminate: false } } } }