MessageDialog QML Type
消息对话框。更多
Import Statement: | import QtQuick.Dialogs |
Since: | Qt 6.3 |
Inherits: |
属性
- buttons : flags
- detailedText : string
- informativeText : string
- text : string
信号
- buttonClicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role)
详细说明
MessageDialog 类型为消息对话框提供了 QML API。
消息对话框用于通知用户或向用户提问。消息对话框会显示一个主要的text 来提醒用户注意某种情况,一个informative text 来进一步解释该提醒或向用户提问,以及一个可选的detailed text 来在用户要求时提供更多数据。消息框还可以显示一组可配置的buttons ,用于接受用户回复。
要显示消息对话框,请构建 MessageDialog 的实例,设置所需的属性,然后调用open() 。
MessageDialog { buttons: MessageDialog.Ok text: "The document has been modified." }
用户必须单击OK 按钮才能解除消息对话框。
除了提醒用户注意事件外,一种更复杂的方法是询问用户如何处理该事件。将问题存储在informative text 属性中,并在buttons 属性中指定一组按钮作为用户回复。这些按钮是通过使用位顺时针 OR 运算符组合值来指定的。
MessageDialog { text: "The document has been modified." informativeText: "Do you want to save your changes?" buttons: MessageDialog.Ok | MessageDialog.Cancel onAccepted: document.save() }
可用性
本机平台消息对话框目前在以下平台上可用:
- 安卓
- iOS
- MacOS
Qt Quick Dialogs 在没有本地实现的平台上,使用 实现作为备用。Qt Quick
属性文档
buttons : flags |
该属性包含消息对话框使用的按钮组合。默认值为MessageDialog.NoButton
。
可能的标志:
常量 | 说明 |
---|---|
MessageDialog.Ok | 使用AcceptRole 定义的 "确定 "按钮。 |
MessageDialog.Open | 通过AcceptRole 定义的 "打开 "按钮。 |
MessageDialog.Save | 通过AcceptRole 定义的 "保存 "按钮。 |
MessageDialog.Cancel | 通过RejectRole 定义的 "取消 "按钮。 |
MessageDialog.Close | 通过RejectRole 定义的 "关闭 "按钮。 |
MessageDialog.Discard | 通过DestructiveRole 定义的 "丢弃 "或 "不保存 "按钮(取决于平台)。 |
MessageDialog.Apply | 通过ApplyRole 定义的 "应用 "按钮。 |
MessageDialog.Reset | 通过ResetRole 定义的 "重置 "按钮。 |
MessageDialog.RestoreDefaults | 通过ResetRole 定义的 "恢复默认值 "按钮。 |
MessageDialog.Help | 通过HelpRole 定义的 "帮助 "按钮。 |
MessageDialog.SaveAll | 通过AcceptRole 定义的 "全部保存 "按钮。 |
MessageDialog.Yes | 通过YesRole 定义的 "是 "按钮。 |
MessageDialog.YesToAll | 通过YesRole 定义的 "是全部 "按钮。 |
MessageDialog.No | 通过NoRole 定义的 "否 "按钮。 |
MessageDialog.NoToAll | 通过NoRole 定义的 "否全部 "按钮。 |
MessageDialog.Abort | 通过RejectRole 定义的 "放弃 "按钮。 |
MessageDialog.Retry | 通过AcceptRole 定义的 "重试 "按钮。 |
MessageDialog.Ignore | 通过AcceptRole 定义的 "忽略 "按钮。 |
MessageDialog.NoButton | 对话框没有按钮。 |
另请参阅 buttonClicked() 。
detailedText : string |
该属性包含要在详细信息区域显示的文本。
另请参阅 text 和informativeText 。
informativeText : string |
text : string |
该属性包含要在消息对话框中显示的文本。
另请参阅 informativeText 和detailedText 。
信号文档
buttonClicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role) |
当点击带有指定role 的button 时,将发出该信号。
通过为该信号提供处理程序,您可以响应任何自定义按钮被按下。button 参数说明哪个按钮被点击,而role 参数则说明该按钮的功能作用。
MessageDialog { id: dialog text: qsTr("The document has been modified.") informativeText: qsTr("Do you want to save your changes?") buttons: MessageDialog.Ok | MessageDialog.Cancel onButtonClicked: function (button, role) { switch (button) { case MessageDialog.Ok: document.save() break; } } }
注: 相应的处理程序是onButtonClicked
。
另请参阅 buttons 。
© 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.