ColorDialog QML Type
颜色对话框。更多...
| Import Statement: | import QtQuick.Dialogs |
| Since: | Qt 6.4 |
| Inherits: |
属性
- options : flags
- selectedColor : color
详细说明
ColorDialog 类型为颜色对话框提供了一个 QML API。

要显示颜色对话框,需创建一个 ColorDialog 实例,设置所需属性,并调用 `open()` 方法。可通过 `selectedColor ` 属性确定对话框中初始选中的颜色。
MenuItem {
text: qsTr("Color")
onTriggered: colorDialog.open()
}
ColorDialog {
id: colorDialog
selectedColor: document.color
onAccepted: document.color = selectedColor
}
MyDocument {
id: document
}可用性
目前,以下平台支持原生平台颜色对话框:
- iOS
- Linux(在 GTK+ 平台主题下运行时)
- macOS
Qt Quick Dialogs 在没有原生实现的平台上,会使用Qt Quick 实现作为备用方案。
属性文档
options : flags
该属性包含影响对话框外观和风格的各种选项。
默认情况下,所有选项均处于禁用状态。
应在显示对话框之前设置这些选项。在对话框可见时进行设置,不能保证会立即对对话框产生影响(具体取决于选项和平台)。
可用选项:
| 常量 | 描述 |
|---|---|
ColorDialog.ShowAlphaChannel | 显示一个滑块以及用于设置透明度值的额外输入字段。 |
ColorDialog.NoButtons | 不显示“Open ”和“Cancel ”按钮(适用于“实时对话框”)。 |
ColorDialog.NoEyeDropperButton | 不显示Eye Dropper 按钮。此选项在Qt 6.6中新增。 |
ColorDialog.DontUseNativeDialog | 强制对话框使用非原生的 Quick 实现。 |
selectedColor : color
该属性保存对话框中当前选中的颜色。
可以通过处理 `accepted()` 信号来获取最终选定的颜色。当用户点击“Open ”以确认颜色时,`accepted()` 信号的处理程序可以查询 `selectedColor` 属性,从而获取用户最终选定的颜色。
另请参阅 accepted()。
© 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.