color QML Value Type
一个 ARGB 颜色值。更多...
| Import Statement: | import QtQuick |
属性
- a : real
- b : real
- g : real
- hslHue : real
- hslLightness : real
- hslSaturation : real
- hsvHue : real
- hsvSaturation : real
- hsvValue : real
- r : real
- valid : bool
详细说明
color 类型指的是一种ARGB颜色值。可以通过多种方式指定:
- 使用SVG color name ,例如“red”、“green”或“lightsteelblue”。
- 通过十六进制三元组或四元组,格式分别为
"#RRGGBB"和"#AARRGGBB"。例如,红色对应三元组"#FF0000",而略带透明的蓝色对应四元组"#800000FF"。 - 使用Qt.rgba()、Qt.hsva()、Qt.hsla()、Qt.darker()、Qt.lighter() 或Qt.tint() 函数。
示例:

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
}颜色类型具有r、g、b 和a属性,它们分别表示颜色的红、绿、蓝和透明度值。 此外,hsvHue、hsvSaturation、hsvValue、hslHue、hslSaturation 和hslLightness属性可分别用于访问 HSV 和 HSL 颜色模型中的颜色值。
Text {
color: "red"
// prints "1 0 0 1"
Component.onCompleted: console.log(color.r, color.g, color.b, color.a)
}要测试颜色值是否相等,请使用 `Qt.colorEqual()` 函数。这使得无论颜色是以属性形式存在,还是以任何可接受的字符串指定形式存在,都能进行精确比较。
在与 C++ 集成时,请注意,从 C++ 传递到 QML 的任何QColor 值都会自动转换为color 值,反之亦然。
该值类型由QtQuick 导入提供。
SVG 颜色参考
下表列出了可用的SVG 颜色:
| 名称 | 十六进制 | 颜色 |
|---|---|---|
| aliceblue | #f0f8ff | |
| 古白色 | #faebd7 | |
| 水蓝色 | #00ffff | |
| 海蓝 | #7fffd4 | |
| 天蓝色 | #f0ffff | |
| 米色 | #f5f5dc | |
| 米色 | #ffe4c4 | |
| 黑色 | #000000 | |
| 焙白杏仁色 | #ffebcd | |
| 蓝色 | #0000ff | |
| 蓝紫色 | #8a2be2 | |
| 棕色 | #a52a2a | |
| 伯里伍德 | #deb887 | |
| 海军蓝 | #5f9ea0 | |
| 黄绿色 | #7fff00 | |
| 巧克力色 | #d2691e | |
| 珊瑚色 | #ff7f50 | |
| 矢车菊蓝 | #6495ed | |
| 玉米须色 | #fff8dc | |
| 深红 | #dc143c | |
| 青色 | #00ffff | |
| 深蓝色 | #00008b | |
| 深青色 | #008b8b | |
| 深金黄 | #b8860b | |
| 深灰色 | #a9a9a9 | |
| 深绿色 | #006400 | |
| 深灰色 | #a9a9a9 | |
| 深卡其色 | #bdb76b | |
| 深洋红 | #8b008b | |
| 深橄榄绿 | #556b2f | |
| 深橙色 | #ff8c00 | |
| 深兰花色 | #9932cc | |
| 深红色 | #8b0000 | |
| 深鲑鱼色 | #e9967a | |
| 深海绿色 | #8fbc8f | |
| 深板岩蓝 | #483d8b | |
| 深板岩灰 | #2f4f4f | |
| 深板岩灰 | #2f4f4f | |
| 深绿松石色 | #00ced1 | |
| 深紫色 | #9400d3 | |
| 深粉色 | #ff1493 | |
| 深天蓝 | #00bfff | |
| 暗灰色 | #696969 | |
| 暗灰色 | #696969 | |
| 道奇蓝 | #1e90ff | |
| 火砖红 | #b22222 | |
| 花卉白 | #fffaf0 | |
| 森林绿 | #228b22 | |
| 紫红色 | #ff00ff | |
| 盖恩斯伯勒 | #dcdcdc | |
| 幽灵白 | #f8f8ff | |
| 金色 | #ffd700 | |
| 金盏花色 | #daa520 | |
| 灰色 | #808080 | |
| 灰色 | #808080 | |
| 绿色 | #008000 | |
| 黄绿色 | #adff2f | |
| 蜜瓜色 | #f0fff0 | |
| 亮粉色 | #ff69b4 | |
| 印度红 | #cd5c5c | |
| 靛蓝 | #4b0082 | |
| 象牙白 | #fffff0 | |
| 卡其色 | #f0e68c | |
| 薰衣草色 | #e6e6fa | |
| 淡紫粉 | #fff0f5 | |
| 草绿 | #7cfc00 | |
| 柠檬雪纺 | #fffacd | |
| 浅蓝色 | #add8e6 | |
| 浅珊瑚色 | #f08080 | |
| 浅青色 | #e0ffff | |
| 浅金红黄色 | #fafad2 | |
| 浅灰色 | #d3d3d3 | |
| 浅绿色 | #90ee90 | |
| 浅灰色 | #d3d3d3 | |
| 浅粉色 | #ffb6c1 | |
| 浅鲑鱼色 | #ffa07a | |
| 浅海绿色 | #20b2aa | |
| 浅天蓝色 | #87cefa | |
| 浅石灰色 | #778899 | |
| 浅石板灰色 | #778899 | |
| 浅钢蓝色 | #b0c4de | |
| 浅黄色 | #ffffe0 | |
| 柠檬绿 | #00ff00 | |
| 青柠绿 | #32cd32 | |
| 亚麻色 | #faf0e6 | |
| 洋红色 | #ff00ff | |
| 栗色 | #800000 | |
| 中度海蓝 | #66cdaa | |
| 中度蓝色 | #0000cd | |
| 中度兰花色 | #ba55d3 | |
| 中度紫色 | #9370db | |
| 中度海绿色 | #3cb371 | |
| 中灰蓝色 | #7b68ee | |
| 中春绿色 | #00fa9a | |
| 中度绿松石色 | #48d1cc | |
| 中度紫红色 | #c71585 | |
| 午夜蓝 | #191970 | |
| 薄荷奶油色 | #f5fffa | |
| 雾玫瑰 | #ffe4e1 | |
| 莫卡辛 | #ffe4b5 | |
| 纳瓦霍白 | #ffdead | |
| 海军蓝 | #000080 | |
| 复古蕾丝 | #fdf5e6 | |
| 橄榄绿 | #808000 | |
| 橄榄灰 | #6b8e23 | |
| 橙色 | #ffa500 | |
| 橙红色 | #ff4500 | |
| 兰花色 | #da70d6 | |
| 淡金黄 | #eee8aa | |
| 浅绿色 | #98fb98 | |
| 浅绿松石色 | #afeeee | |
| 浅紫红色 | #db7093 | |
| 木瓜色 | #ffefd5 | |
| 蜜桃泡芙 | #ffdab9 | |
| 秘鲁 | #cd853f | |
| pink | #ffc0cb | |
| 李子色 | #dda0dd | |
| 淡蓝色 | #b0e0e6 | |
| 紫色 | #800080 | |
| 红色 | #ff0000 | |
| 玫瑰棕 | #bc8f8f | |
| 皇家蓝 | #4169e1 | |
| 马鞍棕 | #8b4513 | |
| 鲑鱼色 | #fa8072 | |
| 沙褐色 | #f4a460 | |
| 海绿色 | #2e8b57 | |
| 贝壳色 | #fff5ee | |
| 赭石色 | #a0522d | |
| 银 | #c0c0c0 | |
| 天蓝色 | #87ceeb | |
| 石板蓝 | #6a5acd | |
| 板岩灰 | #708090 | |
| 板岩灰 | #708090 | |
| 雪白 | #fffafa | |
| 春绿 | #00ff7f | |
| 钢蓝色 | #4682b4 | |
| 浅棕色 | #d2b48c | |
| 青绿色 | #008080 | |
| 蓟花色 | #d8bfd8 | |
| 番茄 | #ff6347 | |
| 绿松石 | #40e0d0 | |
| 紫色 | #ee82ee | |
| 小麦色 | #f5deb3 | |
| 白色 | #ffffff | |
| 白烟 | #f5f5f5 | |
| 黄色 | #ffff00 | |
| 黄绿色 | #9acd32 |
另请参阅 QML 值类型。
属性文档
a : real
RGBA 模型中的 Alpha 颜色通道。Alpha 表示每个像素的不透明度。
b : real
RGBA 模型中的蓝色通道。
g : real
RGBA 模型中的绿色通道。
hslHue : real
该颜色的 HSL 色相分量。simplified Chinese (Mainland)
hslLightness : real
该颜色的 HSL 明度色分量。
hslSaturation : real
该颜色的HSL饱和度色分量。
hsvHue : real
该颜色的 HSV 色相分量。H.S.V. 色相值
hsvSaturation : real
该颜色的 HSV 饱和度色分量。
hsvValue : real
该颜色的 HSV Value 色值分量。
r : real
RGBA 模型中的红色通道。
valid : bool
如果颜色有效,则返回True ;否则返回False 。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.