QDialogButtonBoxclass is a widget that presents buttons in a layout that is appropriate to the current widget style. 更多 …
def
addButton
(button)
def
addButton
(button, role)
def
addButton
(text, role)
def
button
(which)
def
buttonRole
(button)
def
buttons
()
def
centerButtons
()
def
clear
()
def
orientation
()
def
removeButton
(button)
def
setCenterButtons
(center)
def
setOrientation
(orientation)
def
setStandardButtons
(buttons)
def
standardButton
(button)
def
standardButtons
()
def
accepted
()
def
clicked
(button)
def
helpRequested
()
def
rejected
()
Dialogs and message boxes typically present buttons in a layout that conforms to the interface guidelines for that platform. Invariably, different platforms have different layouts for their dialogs.
QDialogButtonBoxallows a developer to add buttons to it and will automatically use the appropriate layout for the user’s desktop environment.大多数对话框按钮遵循某些角色。这些角色包括:
接受或拒绝对话框。
寻求帮助。
在对话框自身上履行动作 (譬如:重置字段或应用更改)。
There can also be alternate ways of dismissing the dialog which may cause destructive results.
Most dialogs have buttons that can almost be considered standard (e.g. OK and Cancel buttons). It is sometimes convenient to create these buttons in a standard way.
There are a couple ways of using
QDialogButtonBox. One ways is to create the buttons (or button texts) yourself and add them to the button box, specifying their role.findButton = QPushButton(self.tr("&Find")) findButton.setDefault(True) moreButton = QPushButton(self.tr("&More")) moreButton.setCheckable(True) moreButton.setAutoDefault(False) buttonBox = QDialogButtonBox(Qt.Vertical) buttonBox.addButton(findButton, QDialogButtonBox.ActionRole) buttonBox.addButton(moreButton, QDialogButtonBox.ActionRole)另外,
QDialogButtonBoxprovides several standard buttons (e.g. OK, Cancel, Save) that you can use. They exist as flags so you can OR them together in the constructor.self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject)You can mix and match normal buttons and standard buttons.
Currently the buttons are laid out in the following way if the button box is horizontal:
![]()
Button box laid out in horizontal
GnomeLayout
![]()
Button box laid out in horizontal
KdeLayout
![]()
Button box laid out in horizontal
MacLayout
![]()
Button box laid out in horizontal
WinLayoutThe buttons are laid out the following way if the button box is vertical:
GnomeLayout
KdeLayout
MacLayout
WinLayout
![]()
![]()
![]()
![]()
Additionally, button boxes that contain only buttons with
ActionRoleorHelpRolecan be considered modeless and have an alternate look on macOS:
非模态水平
MacLayout
![]()
非模态垂直
MacLayout
![]()
When a button is clicked in the button box, the
clicked()signal is emitted for the actual button is that is pressed. For convenience, if the button has anAcceptRole,RejectRole,或HelpRole,accepted(),rejected(),或helpRequested()signals are emitted respectively.If you want a specific button to be default you need to call
setDefault()on it yourself. However, if there is no default button set and to preserve which button is the default button across platforms when using theautoDefaultproperty, the first push button with the accept role is made the default button when theQDialogButtonBoxis shown,
QDialogButtonBox
(
buttons
[
,
parent=None
]
)
¶
QDialogButtonBox(buttons, orientation[, parent=None])
QDialogButtonBox([parent=None])
QDialogButtonBox(orientation[, parent=None])
- param parent
- param buttons
StandardButtons- param orientation
取向
Constructs a horizontal button box with the given
parent
, containing the standard buttons specified by
buttons
.
另请参阅
Constructs a button box with the given
orientation
and
parent
, containing the standard buttons specified by
buttons
.
另请参阅
Constructs an empty, horizontal button box with the given
parent
.
另请参阅
Constructs an empty button box with the given
orientation
and
parent
.
另请参阅
PySide2.QtWidgets.QDialogButtonBox.
ButtonRole
¶
This enum describes the roles that can be used to describe buttons in the button box. Combinations of these roles are as flags used to describe different aspects of their behavior.
|
常量 |
描述 |
|---|---|
|
QDialogButtonBox.InvalidRole |
The button is invalid. |
|
QDialogButtonBox.AcceptRole |
Clicking the button causes the dialog to be accepted (e.g. OK). |
|
QDialogButtonBox.RejectRole |
Clicking the button causes the dialog to be rejected (e.g. Cancel). |
|
QDialogButtonBox.DestructiveRole |
Clicking the button causes a destructive change (e.g. for Discarding Changes) and closes the dialog. |
|
QDialogButtonBox.ActionRole |
Clicking the button causes changes to the elements within the dialog. |
|
QDialogButtonBox.HelpRole |
The button can be clicked to request help. |
|
QDialogButtonBox.YesRole |
The button is a “Yes”-like button. |
|
QDialogButtonBox.NoRole |
The button is a “No”-like button. |
|
QDialogButtonBox.ApplyRole |
The button applies current changes. |
|
QDialogButtonBox.ResetRole |
The button resets the dialog’s fields to default values. |
另请参阅
StandardButton
PySide2.QtWidgets.QDialogButtonBox.
StandardButton
¶
These enums describe flags for standard buttons. Each button has a defined
ButtonRole
.
|
常量 |
描述 |
|---|---|
|
QDialogButtonBox.Ok |
An “OK” button defined with the
|
|
QDialogButtonBox.Open |
An “Open” button defined with the
|
|
QDialogButtonBox.Save |
A “Save” button defined with the
|
|
QDialogButtonBox.Cancel |
A “Cancel” button defined with the
|
|
QDialogButtonBox.Close |
A “Close” button defined with the
|
|
QDialogButtonBox.Discard |
A “Discard” or “Don’t Save” button, depending on the platform, defined with the
|
|
QDialogButtonBox.Apply |
An “Apply” button defined with the
|
|
QDialogButtonBox.Reset |
A “Reset” button defined with the
|
|
QDialogButtonBox.RestoreDefaults |
A “Restore Defaults” button defined with the
|
|
QDialogButtonBox.Help |
A “Help” button defined with the
|
|
QDialogButtonBox.SaveAll |
A “Save All” button defined with the
|
|
QDialogButtonBox.Yes |
A “Yes” button defined with the
|
|
QDialogButtonBox.YesToAll |
A “Yes to All” button defined with the
|
|
QDialogButtonBox.No |
A “No” button defined with the
|
|
QDialogButtonBox.NoToAll |
A “No to All” button defined with the
|
|
QDialogButtonBox.Abort |
An “Abort” button defined with the
|
|
QDialogButtonBox.Retry |
A “Retry” button defined with the
|
|
QDialogButtonBox.Ignore |
An “Ignore” button defined with the
|
|
QDialogButtonBox.NoButton |
An invalid button. |
另请参阅
ButtonRole
standardButtons
PySide2.QtWidgets.QDialogButtonBox.
ButtonLayout
¶
This enum describes the layout policy to be used when arranging the buttons contained in the button box.
|
常量 |
描述 |
|---|---|
|
QDialogButtonBox.WinLayout |
Use a policy appropriate for applications on Windows. |
|
QDialogButtonBox.MacLayout |
Use a policy appropriate for applications on macOS. |
|
QDialogButtonBox.KdeLayout |
Use a policy appropriate for applications on KDE. |
|
QDialogButtonBox.GnomeLayout |
Use a policy appropriate for applications on GNOME. |
|
QDialogButtonBox.AndroidLayout |
Use a policy appropriate for applications on Android. This enum value was added in Qt 5.10. |
The button layout is specified by the
current
style
. However, on the X11 platform, it may be influenced by the desktop environment.
PySide2.QtWidgets.QDialogButtonBox.
accepted
(
)
¶
PySide2.QtWidgets.QDialogButtonBox.
addButton
(
button
,
role
)
¶
button
–
QAbstractButton
role
–
ButtonRole
添加给定
button
to the button box with the specified
role
. If the role is invalid, the button is not added.
If the button has already been added, it is removed and added again with the new role.
注意
The button box takes ownership of the button.
另请参阅
PySide2.QtWidgets.QDialogButtonBox.
addButton
(
button
)
¶
button
–
StandardButton
添加标准
button
to the button box if it is valid to do so, and returns a push button. If
button
is invalid, it is not added to the button box, and zero is returned.
另请参阅
PySide2.QtWidgets.QDialogButtonBox.
addButton
(
text
,
role
)
¶
text – unicode
role
–
ButtonRole
which
–
StandardButton
返回
QPushButton
corresponding to the standard button
which
,或
None
if the standard button doesn’t exist in this button box.
button
–
QAbstractButton
Returns the button role for the specified
button
. This function returns
InvalidRole
if
button
is
None
or has not been added to the button box.
另请参阅
Returns a list of all the buttons that have been added to the button box.
PySide2.QtWidgets.QDialogButtonBox.
centerButtons
(
)
¶
bool
另请参阅
PySide2.QtWidgets.QDialogButtonBox.
clear
(
)
¶
Clears the button box, deleting all buttons within it.
PySide2.QtWidgets.QDialogButtonBox.
clicked
(
button
)
¶
button
–
QAbstractButton
PySide2.QtWidgets.QDialogButtonBox.
helpRequested
(
)
¶
PySide2.QtWidgets.QDialogButtonBox.
orientation
(
)
¶
取向
另请参阅
PySide2.QtWidgets.QDialogButtonBox.
rejected
(
)
¶
PySide2.QtWidgets.QDialogButtonBox.
removeButton
(
button
)
¶
button
–
QAbstractButton
移除
button
from the button box without deleting it and sets its parent to zero.
另请参阅
PySide2.QtWidgets.QDialogButtonBox.
setCenterButtons
(
center
)
¶
center
–
bool
另请参阅
PySide2.QtWidgets.QDialogButtonBox.
setOrientation
(
orientation
)
¶
orientation
–
取向
另请参阅
PySide2.QtWidgets.QDialogButtonBox.
setStandardButtons
(
buttons
)
¶
buttons
–
StandardButtons
另请参阅
PySide2.QtWidgets.QDialogButtonBox.
standardButton
(
button
)
¶
button
–
QAbstractButton
Returns the standard button enum value corresponding to the given
button
,或
NoButton
若给定
button
isn’t a standard button.
PySide2.QtWidgets.QDialogButtonBox.
standardButtons
(
)
¶
StandardButtons
另请参阅