ColorUtils QML Type

Import Statement: import org.kde.kirigami.platform

Methods

Detailed Description

Utilities for processing items to obtain colors and information useful for UIs that need to adjust to variable elements.

Method Documentation

[since 5.69] color adjustColor()

Increases or decreases the properties of color by fixed amounts.

color The color to adjust.

adjustments The adjustments to apply to the color.

{
    red: null, // Range: -255 to 255
    green: null, // Range: -255 to 255
    blue: null, // Range: -255 to 255
    hue: null, // Range: -360 to 360
    saturation: null, // Range: -255 to 255
    value: null // Range: -255 to 255
    alpha: null, // Range: -255 to 255
}

Warning: It is an error to adjust both RGB and HSV properties.

This method was introduced in 5.69.


[since 5.69] color alphaBlend(color foreground, color background)

Returns the result of overlaying the foreground color on the background color.

foreground The color to overlay on the background.

background The color to overlay the foreground on.

import QtQuick
import org.kde.kirigami as Kirigami

Rectangle {
    color: Kirigami.ColorUtils.alphaBlend(Qt.rgba(0, 0, 0, 0.5), Qt.rgba(1, 1, 1, 1))
}

This method was introduced in 5.69.


[since 5.69] enumeration brightnessForColor(color color)

Returns whether a color is bright or dark.

import QtQuick
import org.kde.kirigami as Kirigami

Kirigami.Heading {
    text: {
        if (Kirigami.ColorUtils.brightnessForColor("pink") == Kirigami.ColorUtils.Light) {
            return "The color is light"
        } else {
            return "The color is dark"
        }
    }
}

This method was introduced in 5.69.


real chroma()

Returns the CIELAB chroma of the given color.

CIELAB chroma may give a better quantification of how vibrant a color is compared to HSV saturation.

See also https://en.wikipedia.org/wiki/Colorfulness and https://en.wikipedia.org/wiki/CIELAB_color_space.


[since 5.81] real grayForColor(color color)

Same Algorithm as brightnessForColor but returns a 0 to 1 value for an estimate of the equivalent gray light value (luma). 0 as full black, 1 as full white and 0.5 equivalent to a 50% gray.

This method was introduced in 5.81.


[since 5.69] color linearInterpolation(color one, color two, real balance)

Returns a linearly interpolated color between color one and color two.

one The color to linearly interpolate from.

two The color to linearly interpolate to.

balance The balance between the two colors. 0.0 will return the first color, 1.0 will return the second color. Values beyond these bounds are valid, and will result in extrapolation.

import QtQuick
import org.kde.kirigami as Kirigami

Rectangle {
    color: Kirigami.ColorUtils.linearInterpolation("black", "white", 0.5)
}

This method was introduced in 5.69.


[since 5.69] color scaleColor()

Smoothly scales colors.

color The color to adjust.

adjustments The adjustments to apply to the color. Each value must be between `-100.0` and `100.0`. This indicates how far the property should be scaled from its original to the maximum if positive or to the minimum if negative.

{
    red: null
    green: null
    blue: null
    saturation: null
    value: null
    alpha: null
}

Warning: It is an error to scale both RGB and HSV properties.

This method was introduced in 5.69.


color tintWithAlpha()

Tint a color using a separate alpha value.

This does the same as Qt.tint() except that rather than using the tint color's alpha value, it uses a separate value that gets multiplied with the tint color's alpha. This avoids needing to create a new color just to adjust an alpha value.

targetColor The color to tint.

tintColor The color to tint with.

alpha The amount of tinting to apply.

See also Qt.tint().