|
2018-09-04
, 10:01
|
|
Posts: 6,436 |
Thanked: 12,701 times |
Joined on Nov 2011
@ Ängelholm, Sweden
|
#2
|
|
2018-09-04
, 10:50
|
|
Posts: 433 |
Thanked: 727 times |
Joined on Oct 2012
@ Costa Blanca, España
|
#3
|
Rectangle { id: colorTemperature width: 100; height: 140 radius: 12 anchors.centerIn: temperatureHighLabel color: { if (temperatureHighLabel.text >= "38" ) "#b20012" // dark red else if (temperatureHighLabel.text >= "32" ) "#bd0014" // red else if (temperatureHighLabel.text >= "27" ) "#ec0019" // scarlet else if (temperatureHighLabel.text >= "21" ) "#ec9649" // orange else if (temperatureHighLabel.text >= "16" ) "#f7c200" // yellow else if (temperatureHighLabel.text >= "10" ) "#9ad346" // rich green else if (temperatureHighLabel.text >= "4" ) "#47b04b" // green else if (temperatureHighLabel.text <= "-1" ) "#4293ff" // sky blue else if (temperatureHighLabel.text <= "-7" ) "#3c00ff" // blue else if (temperatureHighLabel.text <= "-12") "#6a28a3" // purple else if (temperatureHighLabel.text <= "-18") "#8d009a" // pinky purple else if (temperatureHighLabel.text <= "-23") "#bd009a" // magenta } }
|
2018-09-04
, 10:50
|
|
Posts: 6,447 |
Thanked: 20,981 times |
Joined on Sep 2012
@ UK
|
#4
|
The Following User Says Thank You to pichlo For This Useful Post: | ||
|
2018-09-04
, 10:53
|
|
Posts: 1,552 |
Thanked: 3,108 times |
Joined on Jun 2012
@ Russia, 96
|
#5
|
|
2018-09-04
, 10:54
|
|
Posts: 6,447 |
Thanked: 20,981 times |
Joined on Sep 2012
@ UK
|
#6
|
The Following User Says Thank You to pichlo For This Useful Post: | ||
|
2018-09-04
, 11:19
|
|
Posts: 433 |
Thanked: 727 times |
Joined on Oct 2012
@ Costa Blanca, España
|
#7
|
Really? I stand corrected. But it means I dislike QML even more than before.
Being Old Skool, I would convert temperatureHighLabel.text to a number and work with that. It would be faster anyway if you do the conversion only once and not at the background for each comparison.
It would also give you a lovely opportunity to change the colour continuously rather than in discreet steps like in your example
|
2018-09-04
, 11:50
|
Posts: 33 |
Thanked: 29 times |
Joined on Aug 2008
@ Netherlands
|
#8
|
The Following 2 Users Say Thank You to wdehoog For This Useful Post: | ||
|
2018-09-04
, 12:17
|
|
Posts: 394 |
Thanked: 1,341 times |
Joined on Dec 2009
|
#9
|
Rectangle { id: colorTemperature width: 100; height: 140 radius: 12 property int temperatureInt: { return parseInt(temperatureHighLabel.text) } anchors.centerIn: temperatureHighLabel color: { if (temperatureInt >= 38 ) { return "#b20012" // dark red } else if (temperatureInt >= 32 ) { return "#bd0014" // red } else if (temperatureInt >= 27 ) { return "#ec0019" // scarlet } else if (temperatureInt >= 21 ) { return "#ec9649" // orange } else if (temperatureInt >= 16 ) { return "#f7c200" // yellow } else if (temperatureInt >= 10 ) { return "#9ad346" // rich green } else if (temperatureInt >= 4 ) { return "#47b04b" // green } else if (temperatureInt >= -1 ) { return "#4293ff" // sky blue } else if (temperatureInt >= -7 ) { return "#3c00ff" // blue } else if (temperatureInt >= -12) { return "#6a28a3" // purple } else if (temperatureInt >= -18) { return "#8d009a" // pinky purple } else return "#bd009a" // magenta } }
|
2018-09-04
, 12:40
|
|
Posts: 1,552 |
Thanked: 3,108 times |
Joined on Jun 2012
@ Russia, 96
|
#10
|
as the title suggests, I'm trying to associate colours to weather temperature, mostly it seems to work until I get to single figures and minus temperatures.
Here is my clunky code, this code is used in `/usr/lib/qt5/qml/Sailfish/Weather/WeatherDetailsHeader.qml`
I've played with this extensively, originally it was in if/else format but the same problem occurred. I've tried different java operators, I've tried adding plus/minus symbols to temp figures, but still I get dark red for single and minus figures. Any ideas appreciated.
The format used for laying out my code, was taken directly from harbour-nationalrail used for associating rail operator colours. Originally, the code was laid out in the same way as my windDirection patch, that being inthe style of 'if/else' statements, but that yielded the same problem as does the above.
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..
Last edited by Markkyboy; 2018-09-04 at 09:57.