将 RGB QColor 转换为 HSL

问题描述 投票:0回答:0

代码:

QColor color = "#f0f0f0";
qDebug() << color;
qDebug() << color.toHsl();
qDebug() << color.convertTo(QColor::Hsl);

输出:

QColor(ARGB 1, 0.941176, 0.941176, 0.941176)
QColor(AHSL 1, -1, 0, 0.941176) // hue == -1 here
QColor(AHSL 1, -1, 0, 0.941176) // hue == -1 here

来自文档:QColor::fromHslF():

...

所有值必须在 0.0-1.0 范围内。

QML 端的文档color hsla():

返回具有指定色调、饱和度、亮度和 阿尔法组件。 所有组件应在0-1范围内 (含)

我需要在 QML 端获得正确的色调、饱和度和亮度值。如何将这样的 RGB QColor 转换为 HSL QColor?

qt qt5 rgb hsl qcolor
© www.soinside.com 2019 - 2024. All rights reserved.