pyqt5 QMessageBox小结
前面4个都有用到
1、Replay box:
reply = QMessageBox.question(self, 'Message',"Are you sure to quit?",QMessageBox.Yes,QMessageBox.No)
if reply == QMessageBox.Yes:
event.accept()
else:
event.ignore()
2、About box:
QMessageBox.about(self, "About Search System",
"The Search System demonstrates how to search images")
3、warning box
QMessageBox.warning(self, "warning", "The save directory is empty",
QMessageBox.Cancel)
4、information box
QMessageBox.information(self,"Tips","Save the current frame successfully!",
QMessageBox.Yes)
QMessageBox.aboutQt(self,"About Qt")
6、critical box
QMessageBox.critical(self,"Critical",
self.tr("错误!"))
7、自定义box(还没有尝试)
def slotCustom(self):
customMsgBox=QMessageBox(self)
customMsgBox.setWindowTitle("Custom message box")
lockButton=customMsgBox.addButton(self.tr("锁定"),
QMessageBox.ActionRole)
unlockButton=customMsgBox.addButton(self.tr("解锁"),
QMessageBox.ActionRole)
cancelButton=customMsgBox.addButton("cancel",QMessageBox.ActionRole)
customMsgBox.setText(self.tr("这是一个自定义消息框!"))
customMsgBox.exec_()
button=customMsgBox.clickedButton()
if button==lockButton:
self.label.setText("Custom MessageBox/Lock")
elif button==unlockButton:
self.label.setText("Custom MessageBox/Unlock")
elif button==cancelButton:
self.label.setText("Custom MessageBox/Cancel")