The Following User Says Thank You to Markkyboy For This Useful Post: | ||
|
2018-09-04
, 16:05
|
|
Posts: 6,447 |
Thanked: 20,981 times |
Joined on Sep 2012
@ UK
|
#12
|
Rectangle { id: colorTemperature width: 100; height: 140 radius: 12 property int tempMin: -20 property int tempMax: 40 property int temperatureInt: { return max(tempMin, min(tempMax, parseInt(temperatureHighLabel.text))); } property real scale: 0.9 anchors.centerIn: temperatureHighLabel color: Qt.hsla((scale * (tempMax - temperatureInt)) / (tempMax - tempMin), 1, // full saturation, feel free to experiment 1, // full lightness, feel free to experiment 1); // no transparency, feel free to experiment }
|
2018-09-04
, 19:20
|
Posts: 71 |
Thanked: 456 times |
Joined on Jan 2017
@ Portugal
|
#13
|
Rectangle { id: teste width: 15*mm height: 15*mm x: 50*mm y: 50*mm color: getTemperature() MouseArea { anchors.fill: parent onClicked: Math.random() } } ListModel { id: colorTemperature } property real currentTemperature: 16 property real minTemperature: -20 property real maxTemperature: 40 function getTemperature() { setArrayOfTEmperatures() //normalized temperature [0-1] var normalized01Temperature = normalizeTemp(currentTemperature, minTemperature, maxTemperature) //normalize temperature to [0 - number of temperatures in listmodel] var colorT = normalized01Temperature * colorTemperature.count var index = Math.floor(colorT) // get the index of listmodel return colorTemperature.get(index).cTemp; } function normalizeTemp(temp, minTemp, maxTemp) { return (temp-minTemp)/(maxTemp-minTemp); } function setArrayOfTEmperatures() { colorTemperature.clear() colorTemperature.append({"cTemp": "red"}) colorTemperature.append({"cTemp": "#f7c200"}) colorTemperature.append({"cTemp": "blue"}) colorTemperature.append({"cTemp": "yellow"}) ........... }
|
2018-09-05
, 07:06
|
|
Posts: 394 |
Thanked: 1,341 times |
Joined on Dec 2009
|
#14
|
|
2018-09-30
, 06:19
|
|
Posts: 433 |
Thanked: 727 times |
Joined on Oct 2012
@ Costa Blanca, España
|
#16
|
Is this project still live somewhere or being developed? It seems really nice to me.
The Following User Says Thank You to Markkyboy For This Useful Post: | ||
I formatted your code exactly as you've posted and it appears to work. I think I may need to change some of the colours, like dark red and red are barely distinguishable.
I wholly agree with your comments about if/else being a sign that improvement is required. I am now looking into it......always learning along the way, mainly how NOT to do it!
Thanks, your input is appreciated.
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..