Hello All,
There's a problem when I use modelcheckbox.png/delgate in a listview.
I use a ListView to show some elements.
In this list view, I define a model and a delegate. In the view, I combine "Enabled" of model to the checkbox in the listView. But the Enabled do not update when check box state change. I do not know how to sync the model state when view changes, can anyone give me some suggestion?
Code as bellow:
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"
Enabled: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"
Enabled: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"
Enabled: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: Enabled
onCheckedChanged: {
Enabled = 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
}
}
}
}
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"
Enabled: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"
Enabled: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"
Enabled: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: Enabled
onCheckedChanged: {
Enabled = 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
}
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks