color QML Basic Type

ARGB 顔色值。 The color 類型指 ARGB 顔色值。有許多種方式可以指定:

範例:

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
}
					

color 類型擁有 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)
}
					

要測試顔色值是否相等,使用 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.

集成 C++ 時,注意任何 QColor 傳入 QML 來自 C++ is automatically converted into a color value, and vice-versa.

此基本類型的提供是通過 QtQuick 導入。

另請參閱 QML 基本類型 .