Qt Quick's color¶
Did you know that all propertys of color type in Qt Quick have attributes that can be accessed as any other object members (via dot or subscription)? I also didn't because the official documentation contains no information (yes, just nothing, zero info) about it.
But I was so kind to collect this here.
It means that you can do, for example, like this:
Item {
property color color: '#8000ff'
Component.onCompleted: {
// Print the color's RGB values:
console.log(
'RGB:', color.r, color.g, color.b
) // ⇒ RGB: 0.5019607843137255 0 1
// or print the same color as HSV:
let {hsvHue: h, hsvSaturation: s, hsvValue: v} = color
console.log(
`hsv(${Math.floor(h * 360)}°, ${s * 100}%, ${v * 100}%)`
) // ⇒ hsv(270°, 100%, 100%)
}
}
Properties¶
| Category | Properties (and aliases) |
|---|---|
| Common | a, valid |
| RGB | r, g, b |
| HSL | hslHue, hslSaturation, hslLightness |
| HSV | hsvHue, hsvSaturation, hsvValue |
a¶
-
Type: normReturns the alpha channel of the color.
b¶
g¶
hslHue¶
-
Type: normAlias: hsvHueReturns the HSL or HSV hue of the color.
See also:
- HSL:
hslLightness,hslSaturation - HSV:
hsvSaturation,hsvValue
- HSL:
hslLightness¶
-
Type: normReturns the HSL lightness of the color.
See also:
hslHue,hslSaturation.
r¶
hslSaturation¶
-
Type: normReturns the HSL saturation of the color.
For HSV saturation, see
hsvSaturation.See also:
hslHue,hslLightness.
hsvHue¶
- Same as
hslHue.
hsvSaturation¶
-
Type: normReturns the HSV saturation of the color.
For HSL saturation, see
hslSaturation.
hsvValue¶
-
Type: normReturns the HSV value of the color.
See also:
hsvHue,hsvSaturation.
valid¶
-
Type: booleanReturns
trueif the color is valid andfalseotherwise. The only two ways of getting invalid colors in QML I found are:- Passing an invalid (for example, default-constructed
QColorfrom C++. - Defining an uninitialized
colorproperty:
- Passing an invalid (for example, default-constructed