如何取消 QColorDialog::getColor()?

Pet*_*ter 1 qt

在我正在开发的 QT 应用程序中,我们让用户使用 QColorDialog::getColor() 选择颜色。基于外部事件,我需要取消这个打开的对话框。有没有办法做到这一点?我没有在 QColorDialog 上看到任何其他静态方法退出对话框。

或者,可能更好的方法是关闭所有打开的对话框。有这样的方法吗?

tat*_*tsy 5

在这个 Qt 论坛帖子之后,

http://www.qtforum.org/article/37032/ok-cancel-buttons-on-qcolordialog.html

我测试了以下代码。

QColor color = QColorDialog::getColor();
if (!color.isValid()) return;

// Your process for selected color
// ...
Run Code Online (Sandbox Code Playgroud)

它对我有用。