How to send value from model to delegate which is separate file?
-
hello, I have troubles sending value from a GridView model to a delegate. I have delegate in a separate file because I would like to have some enhancement. I have remove some code to make code compact for viewing. The model is C++ model
GridView { width: parent.width height: parent.height cellHeight: 250 cellWidth: 250 id: appGrid model: chmodel delegate: GaugeComponent{ }
// GaugeComponent Item { function parseStrtoInt(str) { console.log("gauge string:"+str); console.log("gauge float:"+parseFloat(str)); return parseFloat(str); } property real gaugevalue: parseStrtoInt(num) // num is data in the model CircularGauge { value: gaugevalue anchors.centerIn: parent.Center style: CircularGaugeStyle { needle: Rectangle { y: outerRadius * 0.15 implicitWidth: outerRadius * 0.03 implicitHeight: outerRadius * 0.9 antialiasing: true color: Qt.rgba(0.66, 0.3, 0, 1) } tickmark: Rectangle { visible: styleData.value < 80 || styleData.value % 10 == 0 implicitWidth: outerRadius * 0.02 antialiasing: true implicitHeight: outerRadius * 0.06 color: styleData.value >= 80 ? "#e34c22" : "#e5e5e5" } minorTickmark: Rectangle { visible: styleData.value < 80 implicitWidth: outerRadius * 0.01 antialiasing: true implicitHeight: outerRadius * 0.03 color: "#e5e5e5" } tickmarkLabel: Text { font.pixelSize: Math.max(6, outerRadius * 0.1) text: styleData.value color: styleData.value >= 80 ? "#e34c22" : "#e5e5e5" antialiasing: true } foreground: Item { Rectangle { width: outerRadius * 0.2 height: width radius: width / 2 color: "#e5e5e5" anchors.centerIn: parent } } } } }
-
hello, I have troubles sending value from a GridView model to a delegate. I have delegate in a separate file because I would like to have some enhancement. I have remove some code to make code compact for viewing. The model is C++ model
GridView { width: parent.width height: parent.height cellHeight: 250 cellWidth: 250 id: appGrid model: chmodel delegate: GaugeComponent{ }
// GaugeComponent Item { function parseStrtoInt(str) { console.log("gauge string:"+str); console.log("gauge float:"+parseFloat(str)); return parseFloat(str); } property real gaugevalue: parseStrtoInt(num) // num is data in the model CircularGauge { value: gaugevalue anchors.centerIn: parent.Center style: CircularGaugeStyle { needle: Rectangle { y: outerRadius * 0.15 implicitWidth: outerRadius * 0.03 implicitHeight: outerRadius * 0.9 antialiasing: true color: Qt.rgba(0.66, 0.3, 0, 1) } tickmark: Rectangle { visible: styleData.value < 80 || styleData.value % 10 == 0 implicitWidth: outerRadius * 0.02 antialiasing: true implicitHeight: outerRadius * 0.06 color: styleData.value >= 80 ? "#e34c22" : "#e5e5e5" } minorTickmark: Rectangle { visible: styleData.value < 80 implicitWidth: outerRadius * 0.01 antialiasing: true implicitHeight: outerRadius * 0.03 color: "#e5e5e5" } tickmarkLabel: Text { font.pixelSize: Math.max(6, outerRadius * 0.1) text: styleData.value color: styleData.value >= 80 ? "#e34c22" : "#e5e5e5" antialiasing: true } foreground: Item { Rectangle { width: outerRadius * 0.2 height: width radius: width / 2 color: "#e5e5e5" anchors.centerIn: parent } } } } }
@milan I assume
num
is not available? Try giving your delegate anid
and accessing the model through theGridview.view.model
attached property.// GuageComponent Item { id: mydelegate property real gaugevalue: parseStrtoFloat(mydelegate.GridView.view.model.num) ... }
-
Your program should work without any issue. Please confirm whether model has property call 'num'. If it exist it should work.
What is not working ? What is the error you see ?