color QML Value Type
一个 ARGB 颜色值。更多
属性
- 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属性,分别指颜色的红、绿、蓝和 alpha 值。此外,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 import 提供。
SVG 颜色参考
下表列出了可用的SVG 颜色:
名称 | 十六进制 | 颜色 |
---|---|---|
蓝色 | #f0f8ff | |
古白色 | #f0f8ff | |
水蓝色 | #00ffff | |
海蓝 | #7fffd4 | |
天蓝色 | #f0ffff | |
米色 | #f5f5dc | |
紫褐色 | #ffe4c4 | |
黑色 | #000000 | |
blanchedalmond | #ffebcd | |
蓝色 | #0000ff | |
蓝紫色 | #8a2be2 | |
棕色 | #a52a2a | |
棕色 | #deb887 | |
军校蓝 | #5f9ea0 | |
蓝绿色 | #7fff00 | |
巧克力色 | #d2691e | |
珊瑚色 | #ff7f50 | |
矢车菊蓝 | #6495ed | |
Cornsilk | #fff8dc | |
深红色 | #dc143c | |
青色 | #00ffff | |
深蓝 | #00008b | |
深青色 | #008b8b | |
深金色 | #b8860b | |
深灰色 | #a9a9a9 | |
深绿色 | #006400 | |
深灰色 | #a9a9a9 | |
深卡其色 | #bdb76b | |
深洋红色 | #8b008b | |
深橄榄绿 | #556b2f | |
深橙色 | #ff8c00 | |
深兰色 | #9932cc | |
深红色 | #8b0000 | |
darksalmon | #e9967a | |
深绿色 | #8fbc8f | |
深蓝色 | #483d8b | |
深灰色 | #2f4f4f | |
深灰色 | #2f4f4f | |
深绿色 | #00ced1 | |
深紫色 | #9400d3 | |
粉红色 | #ff1493 | |
深空蓝 | #00bfff | |
dimgray | #696969 | |
dimgrey | #696969 | |
dodgerblue | #1e90ff | |
火砖色 | #b22222 | |
花白色 | #fffaf0 | |
森林绿 | #228b22 | |
紫红色 | #ff00ff | |
gainboro | #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 | |
olivedrab | #6b8e23 | |
橙色 | #ffa500 | |
橙红 | #ff4500 | |
兰色 | #da70d6 | |
浅金色 | #eee8aa | |
苍绿色 | #98fb98 | |
苍绿色 | #afeeee | |
浅紫红色 | #db7093 | |
papayawhip | #ffefd5 | |
peachpuff | #ffdab9 | |
peru | #cd853f | |
粉红色 | #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 色相分量。
hslLightness : real |
颜色的 HSL 明度颜色分量。
hslSaturation : real |
颜色的 HSL 饱和度颜色分量。
hsvHue : real |
颜色的 HSV 色调分量。
hsvSaturation : real |
颜色的 HSV 饱和度颜色分量。
hsvValue : real |
颜色的 HSV 值颜色分量。
r : real |
RGBA 模型的红色通道。
valid : bool |
如果颜色有效,则返回True
;否则返回False
。
© 2025 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.