ColorDialog QML Type

颜色对话框更多

Import Statement: import QtQuick.Dialogs
Since: Qt 6.4
Inherits:

Dialog

属性

详细说明

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不显示OpenCancel 按钮(对 "实时对话框 "有用)。
ColorDialog.NoEyeDropperButton不显示Eye Dropper 按钮。此值在 Qt 6.6 中添加。
ColorDialog.DontUseNativeDialog强制对话框使用非本地快速实现。

selectedColor : color

该属性保存对话框中当前选择的颜色。

可以处理accepted() 信号以获得最终选择。当用户点击Open 接受一种颜色时,accepted() 信号的信号处理程序可以查询 selectedColor 属性,以获得用户最终选择的颜色。

另请参见 accepted()。


© 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.