[Development] QColor and HSL's hue
Matthew Woehlke
mwoehlke.floss at gmail.com
Mon Apr 11 20:54:02 CEST 2016
On 2016-04-09 09:02, Curtis Mitch wrote:
> Is there any technical reason (besides compatibility) why QColor::hslHueF() can't return a value between 0 and 1?
>
> If the colour being represented by QColour is black, QColor::hslHueF() will return -1:
I think there is a misunderstanding here... a negative value is an
"error". Specifically, you get a negative value for hue when the value
cannot be meaningful, because the color is fully desaturated (i.e. a
"perfect" shade of gray). Any value for hue for such colors is
necessarily going to be arbitrary. Qt happens to have made the choice
(which I think is a good one) to return a value that indicates this
clearly, rather than returning an arbitrary value from the normal range,
which might incorrectly imply that the value is meaningful.
> how would I work around the case of a negative hue?
Ideally, you should teach your application how to understand when the
hue is not meaningful and to behave in such cases in a reasonable
manner. Failing that, you could just map a negative value to an
arbitrary value in the normal range. (For example, you could always map
hue like `qMax(0, h)`.)
--
Matthew
More information about the Development
mailing list