summation of value in listview
-
I get these list model ..
import QtQuick 2.0 ListModel { ListElement { number: "amber" events: "0" delayM: 0 } ListElement { number: "john" events: "0" delayM: 0 } ListElement { number: "karl" events: "4" delayM: 43 } ListElement { number: "sara" events: "0" delayM: 0 } ListElement { number: "maria" events: "2" delayM: 11 } }
for sure I get my list view .... but I need to do a sum with delayM value when I refresh my listview .... a pieces of my listview code:
Row { id: rowList width: 960 height: 200 clip: true ListView { id: mylistView width: 310 height: 180 clip: true contentHeight: 180 contentWidth: 320 spacing: 10 model: myListmodel {} delegate: Component { Row { spacing: 50 Column { spacing: 5 Text { text: number; font.pointSize: 12 font.family: "Arial" font.bold: true } Text { horizontalAlignment: Text.AlignRight text: { if(events === "0"){ qsTr("all ok") } else{ qsTr(events + " events") } } leftPadding: 20 font.italic: true font.family: "Arial" font.pointSize: 10 } Text { id: totMaterial horizontalAlignment: Text.AlignRight text: { if(delayM === 0){ qsTr(" --") } else{ qsTr(delayM + " min. ") //totRitMat = totRitMat + delayM /* error loop text*/ } } leftPadding: 20 font.italic: true font.pointSize: 10 font.family: "Arial" } } } //onCompleted: totRitMat = totRitMat + totMaterial /* these is wrong*/ } }
is possible to do these?
regards
-
Hi @gfxx ,
Please have a look at the sample code:-
Row { id: rowList property int totalVal: 0 [..] [..] Text { id: totMaterial horizontalAlignment: Text.AlignRight text: { if(delayM === 0) { qsTr(" --") } else { qsTr(delayM + " min. ") + (rowList.totalVal = rowList.totalVal + delayM) } } [..] [..]
-
Hi @gfxx ,
Please have a look at the sample code:-
Row { id: rowList property int totalVal: 0 [..] [..] Text { id: totMaterial horizontalAlignment: Text.AlignRight text: { if(delayM === 0) { qsTr(" --") } else { qsTr(delayM + " min. ") + (rowList.totalVal = rowList.totalVal + delayM) } } [..] [..]
@Shrinidhi-Upadhyaya i obtain these error: QML QQuickText: Binding loop detected for property "text"
but it make the summation.
-
Hi @gfxx , iam sorry for that, did not see that
Here is the sample code:-
Text { id: totMaterial horizontalAlignment: Text.AlignRight text: delayM === 0 ? qsTr(" --") : qsTr(delayM + " min. ") + rowList.totalVal Component.onCompleted: { rowList.totalVal = rowList.totalVal + delayM } }
I guess this will fix the Binding loop error.
-
Hi @gfxx , iam sorry for that, did not see that
Here is the sample code:-
Text { id: totMaterial horizontalAlignment: Text.AlignRight text: delayM === 0 ? qsTr(" --") : qsTr(delayM + " min. ") + rowList.totalVal Component.onCompleted: { rowList.totalVal = rowList.totalVal + delayM } }
I guess this will fix the Binding loop error.
@Shrinidhi-Upadhyaya said in summation of value in listview:
Text {
id: totMaterial
horizontalAlignment: Text.AlignRighttext: delayM === 0 ? qsTr(" --") : qsTr(delayM + " min. ") + rowList.totalVal Component.onCompleted: { rowList.totalVal = rowList.totalVal + delayM } }
Yes it fix ..... (with c++ or java style if statement) ... but my intention it is write the code in these manner:
Text { id: totMaterial horizontalAlignment: Text.AlignRight text: delayM === 0 ? qsTr(" --") : qsTr(delayM + " min. ") /* not here the summation + rowList.totalVal*/ Component.onCompleted: { rowList.totalVal = rowList.totalVal + delayM console.log("my first add value: " + rowList.totalVal ) /* I think is possible to see all value .... but I see only the first NON zero ... all other I not can see ... so if I would to show the summation in other place I can't :( */ } }
-
@Shrinidhi-Upadhyaya said in summation of value in listview:
Text {
id: totMaterial
horizontalAlignment: Text.AlignRighttext: delayM === 0 ? qsTr(" --") : qsTr(delayM + " min. ") + rowList.totalVal Component.onCompleted: { rowList.totalVal = rowList.totalVal + delayM } }
Yes it fix ..... (with c++ or java style if statement) ... but my intention it is write the code in these manner:
Text { id: totMaterial horizontalAlignment: Text.AlignRight text: delayM === 0 ? qsTr(" --") : qsTr(delayM + " min. ") /* not here the summation + rowList.totalVal*/ Component.onCompleted: { rowList.totalVal = rowList.totalVal + delayM console.log("my first add value: " + rowList.totalVal ) /* I think is possible to see all value .... but I see only the first NON zero ... all other I not can see ... so if I would to show the summation in other place I can't :( */ } }
-
Hi @gfxx , do you mean to tell you want to access the value of delayM at a particular index or something?
Here is the sample code for that:-
Component.onCompleted: { for(var i=0;i<dummyModel.count;i++) { console.log("Index:",i) console.log("Value:",dummyModel.get(i).delayM) } }