color QML Basic Type

an ARGB color value. color type refers to an ARGB color value. It can be specified in a number of ways:

范例:

Rectangle {
    color: "steelblue"
    width: 40; height: 40
}
Rectangle {
    color: "transparent"
    y: 40; width: 40; height: 40
}
Rectangle {
    color: "#FF0000"
    y: 80; width: 40; height: 40
}
Rectangle {
    color: "#800000FF"
    y: 120; width: 40; height: 40
}
Rectangle {
    color: "#00000000"    // ARGB fully transparent
    y: 160
    width: 40; height: 40
}
						

A color type has r , g , b and a properties that refer to the red, green, blue and alpha values of the color, respectively. Additionally it has hsvHue , hsvSaturation , hsvValue and hslHue , hslSaturation , hslLightness properties, which allow access to color values in HSV and HSL color models accordingly:

Text {
    color: "red"
    // prints "1 0 0 1"
    Component.onCompleted: console.log(color.r, color.g, color.b, color.a)
}
						

To test color values for equality, use the Qt.colorEqual() function. This allows colors to be accurately compared whether they are in property form or in any of the acceptable string specification forms.

When integrating with C++, note that any QColor passed into QML from C++ is automatically converted into a color value, and vice-versa.

此基本类型的提供是通过 QtQuick 导入。

另请参阅 QML 基本类型 .