View Single Post
pichlo's Avatar
Posts: 6,445 | Thanked: 20,981 times | Joined on Sep 2012 @ UK
#12
Originally Posted by velox View Post
Try something like:
<snip>
That's what I said,

Originally Posted by pichlo View Post
convert temperatureHighLabel.text to a number and work with that.



I would go a step further and use the HSL colour scheme. Equate the temperature range to the range 0-1, with guards to prevent a wraparound if temperature goes higher or lower.

Something like this, totally untested but hopefully should give you an idea:
Code:
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
}
What's the point of 'scale'? The colours go the full circle, i.e. 1 is the same colour as 0, i.e. red. Purple is somewhere around 0.8 or 0.9. So I am mapping the maximum temperature to 0 (red) and minimum to 'scale' instead of 1.
__________________
Русский военный корабль, иди нахуй!

Last edited by pichlo; 2018-09-04 at 16:10.
 

The Following 4 Users Say Thank You to pichlo For This Useful Post: