How to get QColor::greenF color value exactly between 0 and 1 instead of rounding off?

Multi tool use
How to get QColor::greenF color value exactly between 0 and 1 instead of rounding off?
I have a QColor
value and I need to break it down into its RGB components between 0 and 1 with only one value after decimal point.
For example: Orange color
is
QColor
Orange color
QColor color = QColor(255,128,0)
qreal green = color.greenF();
qDebug() << green; //0.501960784
Whereas the green component must be 0.6
. That is, it's rgb value is (255,128,0) or (1,0.6,0).
0.6
rgb value is (255,128,0) or (1,0.6,0).
How to get 0.6
instead of 0.501960784
?
0.6
0.501960784
@Angew But Orange color is
255,128,0
and '255,153,0' will be the different type of orange color. I have to map 0-255 range to 0-1 range to reflect the same color exactly.– xcfg96
Jul 1 at 19:59
255,128,0
@xcfg96 Where did you get that it should be 0.6?
– eyllanesc
Jul 1 at 20:00
@xcfg96 Well, the colour will either be
255, 128, 0
(which is pretty close to (1, 0.5, 0)
), or it will be 1, 0.6, 0
(which is 255, 153, 0
). You cannot have both, they're different colours.– Angew
Jul 1 at 20:00
255, 128, 0
(1, 0.5, 0)
1, 0.6, 0
255, 153, 0
@xcfg96 OK, and what tells you that the colour on page 11 should have values
255, 128, 0
?– Angew
Jul 1 at 20:05
255, 128, 0
1 Answer
1
But Orange color is 255,128,0
There is no such thing as "the" orange color. Everyone calls something else using the same word. Orange isn't a color, it's a range of hues. Those hues become colors once you assign them some saturation and brightness. There's a whole lot of colors that can be represented using an 8-bit-per-componet R,G,B triple that all have a hue that is orange, and that thus qualify as an orange. There's no the orange,
Whereas the green component must be 0.6. That is, it's rgb value is (255,128,0) or (1,0.6,0).
It's not. QColor
tells you so, and basic math tells you so. The color clearly is 1/0.6/0
, or 1*255, 6/10*255, 0*255
, or 255, 1530/10, 0
or 255, 153, 0
exactly. It won't ever be 255,128,0
and I have no idea who told you that, but they were wrong.
QColor
1/0.6/0
1*255, 6/10*255, 0*255
255, 1530/10, 0
255, 153, 0
255,128,0
So it's really simple: forget it all. Just use QColor::redF
, greenF
and blueF
. They work the way they should.
QColor::redF
greenF
blueF
Oh, and you didn't even mention the elephants in the room that are color spaces. An RGB triple has no physical meaning - it's entirely abstract - until you map it to a physical color space. And you better use calibrated output devices to interface your color choice with the user, otherwise it'll be endless silliness all around.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
128/255 is not 0.6. Have you tried using 153 instead?
– Angew
Jul 1 at 19:57