擅长:python、mysql、java
<p>如果您的设计中有一个特定的“ExitButton”,您应该能够在主代码中连接它并创建一个弹出对话框。您必须导入QtCore/QtGui组件。我总是直接编写GUI(QtDesigner在处理这些事情时很痛苦),所以我假设如下:</p>
<pre><code> from PyQt4.QtGui import *
from PyQt4.QtCore import *
[YOUR CODE]
ui.ExitButton.clicked.connect(Exit)
def Exit():
msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setText("Are you sure you want to close this window?")
msg.setWindowTitle("MessageBox demo")
msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
msg.buttonClicked.connect(msgbtn)
retval = msg.exec_()
print "value of pressed message box button:", retval
</code></pre>