DialogButtonBox QML Type
对话框中使用的按钮框。更多
Import Statement: | import QtQuick.Controls |
Inherits: |
属性
- alignment : flags
- buttonLayout : enumeration
(since QtQuick.Controls 2.5 (Qt 5.12))
- delegate : Component
- position : enumeration
- standardButtons : enumeration
附属物业
- buttonBox : DialogButtonBox
- buttonRole : enumeration
信号
- accepted()
- applied()
(since QtQuick.Controls 2.3 (Qt 5.10))
- clicked(AbstractButton button)
- discarded()
(since QtQuick.Controls 2.3 (Qt 5.10))
- helpRequested()
- rejected()
- reset()
(since QtQuick.Controls 2.3 (Qt 5.10))
方法
- AbstractButton standardButton(StandardButton button)
详细说明
对话框和消息框通常按照符合该平台界面指南的顺序显示按钮。不同平台的对话框按钮顺序总是不同。DialogButtonBox 允许开发人员向其中添加按钮,并自动使用用户平台的适当顺序。
对话框的大多数按钮都遵循特定的角色。这些角色包括
- 接受或拒绝对话框。
- 寻求帮助。
- 对对话框本身执行操作(如重置字段或应用更改)。
也可能有其他方法来取消对话框,这可能会导致破坏性结果。
大多数对话框都有几乎可以视为标准的按钮(如OK 和Cancel 按钮)。以标准方式创建这些按钮有时会很方便。
使用 DialogButtonBox 有几种方法。一种方法是指定标准按钮(如OK,Cancel,Save ),然后让按钮框设置按钮。
DialogButtonBox { standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel onAccepted: console.log("Ok clicked") onRejected: console.log("Cancel clicked") }
另外,也可以手工指定按钮及其作用:
DialogButtonBox { Button { text: qsTr("Save") DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole } Button { text: qsTr("Close") DialogButtonBox.buttonRole: DialogButtonBox.DestructiveRole } }
您也可以混合使用普通按钮和标准按钮。
当点击按钮框中的按钮时,会为实际按下的按钮发出clicked() 信号。此外,当具有相应角色的按钮被按下时,会自动发出以下信号:
角色 | 信号 |
---|---|
AcceptRole ,YesRole | accepted() |
ApplyRole | applied() |
DiscardRole | discarded() |
HelpRole | helpRequested() |
RejectRole ,NoRole | rejected() |
ResetRole | reset() |
另请参见 Dialog 。
属性文档
alignment : flags |
该属性用于保存按钮的对齐方式。
可能的值:
常量 | 说明 |
---|---|
Qt.AlignLeft | 按钮向左对齐。 |
Qt.AlignHCenter | 按钮水平居中。 |
Qt.AlignRight | 按钮向右对齐。 |
Qt.AlignTop | 按钮在顶部对齐。 |
Qt.AlignVCenter | 按钮垂直居中。 |
Qt.AlignBottom | 按钮向下对齐。 |
默认情况下,没有设置特定的对齐方式;读取对齐方式属性会产生一个默认的标志值,该值等于 0。可以通过赋值undefined
将该属性重置为该值。在这种情况下,按钮的大小会被调整以填充可用空间。
注: 该属性假定按钮采用水平布局。请注意,在运行iOS 样式时,如果该属性设置为undefined
以外的其他值,且按钮数量超过两个,则DialogButtonBox 将使用垂直布局。在所有其他情况下,按钮将采用水平布局。
buttonLayout : enumeration |
该属性用于设置按钮框中的按钮布局策略。默认值与特定平台有关。
可用值
常量 | 说明 |
---|---|
DialogButtonBox.WinLayout | 使用适合 Windows 应用程序的策略。 |
DialogButtonBox.MacLayout | 使用适合 macOS 应用程序的策略。 |
DialogButtonBox.KdeLayout | 使用适合 KDE 应用程序的策略。 |
DialogButtonBox.GnomeLayout | 为 GNOME 上的应用程序使用适当的策略。 |
DialogButtonBox.AndroidLayout | 使用适合 Android 应用程序的策略。 |
此属性在 QtQuick.Controls 2.5 (Qt 5.12) 中引入。
delegate : Component |
该属性包含用于创建标准按钮的委托。
另请参阅 standardButtons 。
position : enumeration |
该属性保存按钮框的位置。
注意: 如果按钮框被指定为ApplicationWindow 或 Page 的页眉或页脚,则会自动设置适当的位置。
可能的值
常量 | 说明 |
---|---|
DialogButtonBox.Header | 按钮框位于顶部,作为窗口或页面页眉。 |
DialogButtonBox.Footer | 按钮框位于底部,作为窗口或页面页脚。 |
默认值为Footer
。
另请参阅 Dialog::header 和Dialog::footer 。
standardButtons : enumeration |
该属性包含按钮框使用的标准按钮组合。
DialogButtonBox { standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel onAccepted: console.log("Ok clicked") onRejected: console.log("Cancel clicked") }
按钮将按照用户平台的适当顺序定位。
可能的标志:
常量 | 说明 |
---|---|
DialogButtonBox.Ok | 通过AcceptRole 定义的 "确定 "按钮。 |
DialogButtonBox.Open | 通过AcceptRole 定义的 "打开 "按钮。 |
DialogButtonBox.Save | 通过AcceptRole 定义的 "保存 "按钮。 |
DialogButtonBox.Cancel | 通过RejectRole 定义的 "取消 "按钮。 |
DialogButtonBox.Close | 通过RejectRole 定义的 "关闭 "按钮。 |
DialogButtonBox.Discard | 通过DestructiveRole 定义的 "丢弃 "或 "不保存 "按钮(取决于平台)。 |
DialogButtonBox.Apply | 通过ApplyRole 定义的 "应用 "按钮。 |
DialogButtonBox.Reset | 通过ResetRole 定义的 "重置 "按钮。 |
DialogButtonBox.RestoreDefaults | 通过ResetRole 定义的 "恢复默认值 "按钮。 |
DialogButtonBox.Help | 通过HelpRole 定义的 "帮助 "按钮。 |
DialogButtonBox.SaveAll | 通过AcceptRole 定义的 "全部保存 "按钮。 |
DialogButtonBox.Yes | 通过YesRole 定义的 "是 "按钮。 |
DialogButtonBox.YesToAll | 通过YesRole 定义的 "是全部 "按钮。 |
DialogButtonBox.No | 通过NoRole 定义的 "否 "按钮。 |
DialogButtonBox.NoToAll | 通过NoRole 定义的 "否全部 "按钮。 |
DialogButtonBox.Abort | 通过RejectRole 定义的 "放弃 "按钮。 |
DialogButtonBox.Retry | 通过AcceptRole 定义的 "重试 "按钮。 |
DialogButtonBox.Ignore | 通过AcceptRole 定义的 "忽略 "按钮。 |
DialogButtonBox.NoButton | 无效按钮。 |
另请参阅 standardButton() 。
附加属性文档
DialogButtonBox.buttonBox : DialogButtonBox |
此附加属性包含管理此按钮的按钮框,如果按钮不在按钮框中,则为null
。
DialogButtonBox.buttonRole : enumeration |
此附加属性保存按钮框中每个按钮的角色。
DialogButtonBox { Button { text: qsTr("Save") DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole } Button { text: qsTr("Close") DialogButtonBox.buttonRole: DialogButtonBox.DestructiveRole } }
可用值:
常量 | 说明 |
---|---|
DialogButtonBox.InvalidRole | 按钮无效。 |
DialogButtonBox.AcceptRole | 单击按钮将接受对话框(例如OK )。 |
DialogButtonBox.RejectRole | 单击按钮将拒绝对话框(例如Cancel )。 |
DialogButtonBox.DestructiveRole | 单击按钮会导致破坏性更改(例如,用于丢弃更改)并关闭对话框。 |
DialogButtonBox.ActionRole | 单击按钮可更改对话框中的元素。 |
DialogButtonBox.HelpRole | 单击按钮可以请求帮助。 |
DialogButtonBox.YesRole | 该按钮类似于 "是 "按钮。 |
DialogButtonBox.NoRole | 该按钮类似于 "否 "按钮。 |
DialogButtonBox.ResetRole | 按钮将对话框的字段重置为默认值。 |
DialogButtonBox.ApplyRole | 该按钮可应用当前更改。 |
信号文档
accepted() |
当使用AcceptRole
或YesRole
定义的按钮被点击时,将发出该信号。
注: 相应的处理程序是onAccepted
。
另请参阅 rejected()、clicked() 和helpRequested()。
|
clicked(AbstractButton button) |
|
helpRequested() |
rejected() |
当点击以RejectRole
或NoRole
定义的按钮时,将发出该信号。
注: 相应的处理程序是onRejected
。
另请参阅 accepted()、helpRequested() 和clicked()。
|
方法文档
AbstractButton standardButton(StandardButton button) |
返回指定的标准button ,如果不存在,则返回null
。
另请参阅 standardButtons 。
© 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.