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) →colorIncreases 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):alphakeyword can be specified separately.- Among
rgb,hsl,hsv, andhwb, only one may be used at a time. - All keyword arguments are of type
offsetand optional.
Examples:
adjustHue¶
change¶
-
Type: ( change:change-object) →colorSets 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):alphakeyword can be specified separately.- Among
rgb,hsl,hsv, andhwb, only one may be used at a time. - All keyword arguments are of type
normand optional.
Examples:
complement¶
-
Type: () → colorReturns the RGB complement of the color.
This is identical to
color.adjustHue(-180 .deg).Examples:
darken¶
-
Type: ( amount = 0.25:norm) →colorMakes the color darker by specified
amount(by decreasing the HSL lightness).Examples:
desaturate¶
-
Type: ( amount = 0.25:norm) →colorMakes the color less saturated by specified
amount(by decreasing the HSL saturation).Examples:
grayscale¶
-
Type: () → colorAlias: greyscaleReturns 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) →colorReturns the negative of the color.
A higher
weightmeans the result will be closer to the negative, and a lowerweightmeans it will be closer to the original color.weight = 0.5will always produce#808080.Examples:
See also:
complement,%.
lighten¶
-
Type: ( amount = 0.25:norm) →colorMakes the color lighter by specified
amount(by increasing the HSL lightness).Examples:
mix¶
-
Type: ( color2:any-color,weight = 0.5:norm) →colorReturns a new color that’s a mixture of the current color and
color2.Both the
weightand the relative opacity of each color determines how much of each color is in the result. A largerweightindicates that more of the current color should be used, and a smallerweightindicates that more ofcolor2should be used.By default, the colors are mixed in equal proportions.
Examples:
See also:
%.
opacify¶
-
Type: ( amount = 0.25:norm) →colorAlias: fadeInMakes the color more opaque by increasing the alpha channel by
amount.Examples:
saturate¶
-
Type: ( amount = 0.25:norm) →colorMakes the color more saturated by specified
amount(by increasing the HSL saturation).Examples:
scale¶
-
Type: ( change:offset-object) →colorFluidly 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):alphakeyword can be specified separately.- Among
rgb,hsl,hsv, andhwb, only one may be used at a time. - All keyword arguments are of type
offsetand optional. - Although it is possible to specify
huefor 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) →colorAlias: fadeOutMakes 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: qolorAlias: qolorReturns the underlying Qt Quick's
color.
green¶
hue¶
-
Type: normAlias: hslHue,hsvHue,hwbHueReturns the HSL, HSV, or HWB hue of the color.
See also:
- HSL:
lightness,saturation - HSV:
hsvSaturation,hsvValue - HWB:
blackness,whiteness
- HSL:
lightness¶
-
Type: normAlias: hslLightnessReturns the HSL lightness of the color.
See also:
hue,saturation.
red¶
rgb¶
-
Type: qolorReturns the same color, but with alpha channel set to 100% (fully opaque).
saturation¶
-
Type: normAlias: hslSaturationReturns 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: normReturns the HSV saturation of the color.
For HSL saturation, see
saturation.
hsvValue¶
-
Type: normReturns the HSV value of the color.
See also:
hsvHue,hsvSaturation.
r¶
- Same as
red.
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