- class QDialogButtonBox#
《QDialogButtonBox》类是一个小部件,适用于当前小部件样式,以适当的布局显示按钮。 更多…
简介#
属性#
centerButtonsᅟ- 图钮框中的按钮是否居中orientationᅟ- 图钮框的方向standardButtonsᅟ- 图钮框中标准按钮的集合
方法#
def
__init__()def
addButton()def
button()def
buttonRole()def
buttons()def
centerButtons()定义
clear()
信号#
定义
accepted()定义
clicked()定义
rejected()
注意
本说明书可能包含从 C++ 自动翻译到 Python 的片段。我们始终欢迎对片段翻译的贡献。如果您发现存在翻译问题,也可以通过在 https:/bugreports.qt.io/projects/PYSIDE 创建工单的方式告诉我们。
详细说明#
警告
本节包含自动从 C++ 翻译到 Python 的片段,可能包含错误。
对话框和信息框通常以符合该平台界面指南的布局显示按钮。不同的平台具有不同的对话框布局。
QDialogButtonBox允许开发者为对话框添加按钮,并会自动使用适合用户桌面环境的适当布局。大多数对话框按钮遵循某些角色。这些角色包括
接受或拒绝对话框。
请求帮助。
对对话框本身进行操作(例如重置字段或应用更改)。
也还可以有退出对话框的替代方法,这可能会导致破坏性结果。
大多数对话框具有几乎可以被认为是标准的按钮(例如“确定”和“取消”按钮)。有时以标准方式创建这些按钮是方便的。
使用
QDialogButtonBox的方法有几个。一种方法是自己创建按钮(或按钮文本),然后将它们添加到按钮框中,指定它们的角色。buttonBox = QDialogButtonBox(Qt.Vertical) buttonBox.addButton(findButton, QDialogButtonBox.ActionRole) buttonBox.addButton(moreButton, QDialogButtonBox.ActionRole)
另一种方法是,
QDialogButtonBox提供了几个标准的按钮(例如“确定”、“取消”、“保存”)供您使用。这些按钮存在为标志,您可以在构造函数中将它们进行或运算组合。buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) buttonBox.accepted.connect(self.accept) buttonBox.rejected.connect(self.reject)
可以混合并使用普通按钮和标准按钮。
如果按钮框是水平布局,当前按钮的布局方式如下
GnomeLayout水平按钮框按水平
GnomeLayout布局
KdeLayout水平按钮框按水平
KdeLayout布局
MacLayout水平按钮框按水平
MacLayout布局
WinLayout水平按钮框按水平
WinLayout布局如果按钮框是垂直布局,按钮的布局方式如下
GnomeLayout垂直
KdeLayout垂直
MacLayout垂直
WinLayout垂直此外,仅包含具有
ActionRole或HelpRole的按钮的按钮框可以被视为模式对话框,并在macOS上具有不同的外观当单击按钮框中的按钮时,会发出
clicked()信号给实际被按下的按钮。为了方便起见,如果按钮具有AcceptRole、RejectRole或HelpRole角色,则分别发出accepted()、rejected()或helpRequested()信号。如果您想要某个按钮成为默认按钮,则需要自行在该按钮上调用
setDefault()。然而,如果没有设置默认按钮,并且在使用autoDefault属性时保留平台间默认按钮的一致性,则在显示QDialogButtonBox时,接受角色的第一个按钮将被设置为默认按钮。- class ButtonRole#
此枚举描述了可以用来描述按钮框中按钮的角色的枚举。这些角色的组合作为标志使用,用于描述它们行为的不同方面。
常量
描述
QDialogButtonBox.InvalidRole
按钮无效。
QDialogButtonBox.AcceptRole
单击按钮将使对话框被接受(例如,OK)。
QDialogButtonBox.RejectRole
单击按钮将使对话框被拒绝(例如,取消)。
QDialogButtonBox.DestructiveRole
点击按钮将导致破坏性更改(例如,丢弃更改)并关闭对话框。
QDialogButtonBox.ActionRole
点击按钮将导致对话框内元素的变化。
QDialogButtonBox.HelpRole
可以点击按钮请求帮助。
QDialogButtonBox.YesRole
该按钮是一个类似于“是”的按钮。
QDialogButtonBox.NoRole
该按钮是一个类似于“否”的按钮。
QDialogButtonBox.ApplyRole
该按钮应用当前更改。
QDialogButtonBox.ResetRole
该按钮将对话框字段重置为默认值。
另请参阅
- class StandardButton#
(继承自
enum.Flag) These enums describe flags for standard buttons. Each button has a definedButtonRole.常量
描述
QDialogButtonBox.Ok
一个定义了
AcceptRole的“确定”按钮。QDialogButtonBox.Open
一个定义了
AcceptRole的“打开”按钮。QDialogButtonBox.Save
一个定义了
AcceptRole的“保存”按钮。QDialogButtonBox.Cancel
一个定义了
RejectRole的“取消”按钮。QDialogButtonBox.Close
一个定义了
RejectRole的“关闭”按钮。QDialogButtonBox.Discard
一个定义了
DestructiveRole的“弃置”或“不保存”按钮,具体取决于平台。QDialogButtonBox.Apply
一个定义了
ApplyRole的“应用”按钮。QDialogButtonBox.Reset
一个定义了
ResetRole的“重置”按钮。QDialogButtonBox.RestoreDefaults
一个定义了
ResetRole的“恢复默认”按钮。QDialogButtonBox.Help
一个定义了
HelpRole的“帮助”按钮。QDialogButtonBox.SaveAll
一个定义了
AcceptRole的“全部保存”按钮。QDialogButtonBox.Yes
一个定义了
YesRole的“是”按钮。QDialogButtonBox.YesToAll
一个定义了
YesRole的“全部是”按钮。QDialogButtonBox.No
使用
NoRole定义了一个“否”按钮。QDialogButtonBox.NoToAll
使用
NoRole定义了一个“否所有”按钮。QDialogButtonBox.Abort
使用
RejectRole定义了一个“中止”按钮。QDialogButtonBox.Retry
使用
AcceptRole定义了一个“重试”按钮。QDialogButtonBox.Ignore
使用
AcceptRole定义了一个“忽略”按钮。QDialogButtonBox.NoButton
一个无效的按钮。
- class ButtonLayout#
此枚举描述了在按钮框中排列按钮时要使用的布局策略。
常量
描述
QDialogButtonBox.WinLayout
适用于Windows应用程序的相应策略。
QDialogButtonBox.MacLayout
适用于macOS应用程序的相应策略。
QDialogButtonBox.KdeLayout
适用于KDE应用程序的相应策略。
QDialogButtonBox.GnomeLayout
适用于GNOME应用程序的相应策略。
QDialogButtonBox.AndroidLayout
适用于Android应用程序的相应策略。此枚举值自Qt 5.10开始使用。
按钮布局由
current style指定。然而,在X11平台上,它可能受到桌面环境的影响。
注意
可以直接使用当使用
from __feature__ import true_property时,或者通过访问函数使用。- property centerButtons: bool#
此属性表示按钮框中的按钮是否居中。
默认情况下,此属性为
false。此行为适用于大多数类型的对话框。一个显著的例外是大多数平台(例如Windows)上的消息框,其中按钮框在水平方向上居中。另请参阅
- property orientation: Qt.Orientation#
此属性表示按钮框的方向。
默认情况下,方向为水平(即按钮并排排列)。可能的方向有 Qt::Horizontal 和 Qt::Vertical。
- 属性 standardButtons: QDialogButtonBox.StandardButton 的组合#
该属性包含按钮框中的标准按钮集合。
该属性控制按钮框使用哪些标准按钮。
另请参阅
- __init__(buttons, orientation[, parent=None])#
- 参数::
buttons –
StandardButton的组合orientation –
Orientationparent –
QWidget
构造一个具有给定
orientation和parent的按钮框,包含由buttons指定的标准按钮。另请参阅
- __init__([parent=None])
- 参数::
parent –
QWidget
使用给定的
parent构造一个空的,水平按钮框。另请参阅
- __init__(orientation[, parent=None])
- 参数::
orientation –
Orientationparent –
QWidget
使用给定的
orientation和parent构造一个空的按钮框。另请参阅
- __init__(buttons[, parent=None])
- 参数::
buttons –
StandardButton的组合parent –
QWidget
使用给定的
parent构造一个水平按钮框,包含由buttons指定的标准按钮。另请参阅
- accepted()#
按钮框内的按钮被点击时发出此信号,只要它被定义为具有
AcceptRole或YesRole。- addButton(button, role)#
- 参数::
button –
QAbstractButtonrole –
ButtonRole
将指定
role的按钮添加到按钮框中。如果该角色无效,按钮不会被添加。如果按钮已添加,则将其移除并重新添加以使用新的角色。
- addButton(button)
- 参数::
button –
StandardButton- 返回类型:
如果可以添加标准按钮,则将其添加到按钮框并返回一个按钮。如果
另请参阅
- addButton(text, role)
- 参数::
text – str
role –
ButtonRole
- 返回类型:
创建具有指定
text的按钮,将其添加到按钮框指定的role,并返回相应的按钮。如果role无效,则不会创建按钮,并返回零。另请参阅
- button(which)#
- 参数::
which –
StandardButton- 返回类型:
返回对应标准按钮
which的QPushButton,或当此按钮框中不存在该标准按钮时,返回None。- buttonRole(button)#
- 参数::
button –
QAbstractButton- 返回类型:
返回指定
button的按钮角色。如果button为None或尚未添加到按钮框中,则此函数返回InvalidRole。另请参阅
- buttons()#
- 返回类型:
.按钮列表
返回添加到按钮框中所有按钮的列表。
- centerButtons()#
- 返回类型:
bool
另请参阅
centerButtons属性的获取器。
- clear()#
清除按钮框,删除其中所有按钮。
- clicked(button)#
- 参数::
button –
QAbstractButton
当按钮框中的按钮被点击时,会发出此信号。指定被按下的具体按钮由
button表示。- helpRequested()#
当按钮框中的按钮被点击,且该按钮被定义为具有
HelpRole时,将发出此信号。- orientation()#
- 返回类型:
另请参阅
orientation属性的获取器。- rejected()#
当按钮框中的按钮被点击,并且按钮定义为具有
RejectRole或NoRole时,将发出此信号。- removeButton(button)#
- 参数::
button –
QAbstractButton
从按钮框中移除
button而不删除它,并将它的父级设置为 0。另请参阅
- setCenterButtons(center)#
- 参数::
center – bool
另请参阅
属性
centerButtonsᅟ的设置器。- setOrientation(orientation)#
- 参数::
orientation –
Orientation
另请参阅
属性
orientationᅟ的设置器。- setStandardButtons(buttons)#
- 参数::
buttons –
StandardButton的组合
另请参阅
属性
standardButtonsᅟ的设置器。- standardButton(button)#
- 参数::
button –
QAbstractButton- 返回类型:
返回与指定
button对应的标准按钮枚举值,如果指定的button不是一个标准按钮,则返回NoButton。- standardButtons()#
- 返回类型:
StandardButton的组合
另请参阅
属性
standardButtonsᅟ的获取器。
非模态水平
非模态垂直