[英]How to execute a function after click particular button in PyQt5 Dialog Button Box?
Here is my Dialog Button Box design on Python:这是我在 Python 上设计的对话框按钮框:
self.buttonBox = QtWidgets.QDialogButtonBox(Frame)
self.buttonBox.setGeometry(QtCore.QRect(200, 216, 144, 27))
self.buttonBox.setFont(font)
self.buttonBox.setAcceptDrops(False)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Discard|QtWidgets.QDialogButtonBox.Save)
self.buttonBox.setObjectName("buttonBox")
There are two buttons as shown above, which are Discard
and Save
.如上图有两个按钮,分别是
Discard
和Save
。 How to execute a particular unique function when I click Save
or Discard
.单击
Save
或Discard
时如何执行特定的唯一 function 。 What I have tried is:我试过的是:
self.buttonBox.accepted.connect(self.save)
self.buttonBox.rejected.connect(self.discard)
However, the function execute only when I clicked Save
and did not work when I clicked Discard
.但是,function 仅在我单击
Save
时执行,而在我单击Discard
时不起作用。 How to handle this?如何处理?
Discard
is a destructive
button, not a reject
button. Discard
是destructive
按钮,而不是reject
按钮。 You could either:你可以:
Cancel
, Close
, or Abort
and link to the rejected
signal as you are already doingCancel
、 Close
或Abort
并链接到被rejected
的信号,就像您已经在做的那样Discard
, connect to the clicked
signal and just verify in your self.discard
function that the clicked button (passed with the signal) was the Discard
button before doing anythingDiscard
,请连接到clicked
信号,然后在您的self.discard
function 中验证 clicked 按钮(随信号传递)是Discard
按钮,然后再做任何事情
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.