The Color
class¶
Essentially, the Color
is just a thin wrapper around Qt Quick's color
. It provides useful properties and methods though. They are listed below.
Methods¶
Category | Methods (and aliases) |
---|---|
Multi-changes | adjust , change , scale |
Hue | adjustHue (or spin ), complement |
Brightness | darken , lighten |
Saturation | desaturate , grayscale (or greyscale ), saturate |
Opacity | opacify (or fadeIn ), transparentize (or fadeOut ) |
Other | invert , mix |
adjust
¶
-
Type: ( change
:offset-object
) →color
Increases or decreases one or more properties of the color by fixed amounts.
Adds the value passed for each keyword argument to the corresponding property of the color, and returns a new adjusted instance of color.
Restrictions (for more details see
offset-object
):alpha
keyword can be specified separately.- Among
rgb
,hsl
,hsv
, andhwb
, only one may be used at a time. - All keyword arguments are of type
offset
and optional.
Examples:
adjustHue
¶
change
¶
-
Type: ( change
:change-object
) →color
Sets one or more properties of the color to new values and returns a new adjusted instance of color.
Restrictions (for more details see
change-object
):alpha
keyword can be specified separately.- Among
rgb
,hsl
,hsv
, andhwb
, only one may be used at a time. - All keyword arguments are of type
norm
and optional.
Examples:
complement
¶
-
Type: () → color
Returns the RGB complement of the color.
This is identical to
color.adjustHue(-180 .deg)
.Examples:
darken
¶
-
Type: ( amount = 0.25
:norm
) →color
Makes the color darker by specified
amount
(by decreasing the HSL lightness).Examples:
desaturate
¶
-
Type: ( amount = 0.25
:norm
) →color
Makes the color less saturated by specified
amount
(by decreasing the HSL saturation).Examples:
grayscale
¶
-
Type: () → color
Alias: greyscale
Returns a gray color with the same lightness as the color's one.
This is identical to
color.change({hsl: {saturation: 0}})
.Examples:
See also:
change
.
invert
¶
-
Type: ( weight = 1.0
:norm
) →color
Returns the negative of the color.
A higher
weight
means the result will be closer to the negative, and a lowerweight
means it will be closer to the original color.weight = 0.5
will always produce#808080
.Examples:
See also:
complement
,%
.
lighten
¶
-
Type: ( amount = 0.25
:norm
) →color
Makes the color lighter by specified
amount
(by increasing the HSL lightness).Examples:
mix
¶
-
Type: ( color2
:any-color
,weight = 0.5
:norm
) →color
Returns a new color that’s a mixture of the current color and
color2
.Both the
weight
and the relative opacity of each color determines how much of each color is in the result. A largerweight
indicates that more of the current color should be used, and a smallerweight
indicates that more ofcolor2
should be used.By default, the colors are mixed in equal proportions.
Examples:
See also:
%
.
opacify
¶
-
Type: ( amount = 0.25
:norm
) →color
Alias: fadeIn
Makes the color more opaque by increasing the alpha channel by
amount
.Examples:
saturate
¶
-
Type: ( amount = 0.25
:norm
) →color
Makes the color more saturated by specified
amount
(by increasing the HSL saturation).Examples:
scale
¶
-
Type: ( change
:offset-object
) →color
Fluidly scales one or more properties of the color and returns a new adjusted instance of color.
Each keyword argument indicates how far the corresponding property of the color should be moved from its original position towards the maximum (if the argument is positive) or the minimum (if the argument is negative). This means that, for example,
{hsl: {lightness: +50['%']}}
will make a color 50% closer to maximum lightness without making it fully white.Restrictions (for more details see
offset-object
):alpha
keyword can be specified separately.- Among
rgb
,hsl
,hsv
, andhwb
, only one may be used at a time. - All keyword arguments are of type
offset
and optional. - Although it is possible to specify
hue
for HSL, HSV, or HWB keyword arguments, it doesn't make much sense because the menthal model of such a change is vague IMO.
Examples:
transparentize
¶
-
Type: ( amount = 0.25
:norm
) →color
Alias: fadeOut
Makes the color less opaque by decreasing the alpha channel by
amount
.Examples:
Properties¶
Category | Properties (and aliases) |
---|---|
Common | alpha (or a ), color (or qolor ), rgb , valid |
RGB | red , green , blue (or just r , g , b ) |
HSL | hue , saturation , lightness (or hslHue , hslSaturation , hslLightness ) |
HSV | hsvHue (or just hue ), hsvSaturation , hsvValue |
HWB | hue , whiteness , blackness (or hwbHue , hwbWhiteness , hwbBlackness ) |
Own¶
alpha
¶
blackness
¶
blue
¶
color
¶
-
Type: qolor
Alias: qolor
Returns the underlying Qt Quick's
color
.
green
¶
hue
¶
-
Type: norm
Alias: hslHue
,hsvHue
,hwbHue
Returns the HSL, HSV, or HWB hue of the color.
See also:
- HSL:
lightness
,saturation
- HSV:
hsvSaturation
,hsvValue
- HWB:
blackness
,whiteness
- HSL:
lightness
¶
-
Type: norm
Alias: hslLightness
Returns the HSL lightness of the color.
See also:
hue
,saturation
.
red
¶
rgb
¶
-
Type: qolor
Returns the same color, but with alpha channel set to 100% (fully opaque).
saturation
¶
-
Type: norm
Alias: hslSaturation
Returns the HSL saturation of the color.
For HSV saturation, see
hsvSaturation
.
whiteness
¶
Inherited from Qt Quick's color
¶
a
¶
- Same as
alpha
.
b
¶
- Same as
blue
.
g
¶
- Same as
green
.
hslHue
¶
- Same as
hue
.
hslLightness
¶
- Same as
lightness
.
hslSaturation
¶
- Same as
saturation
.
hsvHue
¶
- Same as
hue
.
hsvSaturation
¶
-
Type: norm
Returns the HSV saturation of the color.
For HSL saturation, see
saturation
.
hsvValue
¶
-
Type: norm
Returns the HSV value of the color.
See also:
hsvHue
,hsvSaturation
.
r
¶
- Same as
red
.
valid
¶
-
Type: boolean
Returns
true
if the color is valid andfalse
otherwise. The only two ways of getting invalid colors in QML I found are:- Passing an invalid (for example, default-constructed
QColor
from C++. - Defining an uninitialized
color
property:
- Passing an invalid (for example, default-constructed