How to add custom button in QMessageBox in PyQt4

I am coding an application that needs custom buttons in a QMessageBox. I managed to create an example in the QT design, which is given below.

enter image description here

I wanted to do this in a QMessageBox.

I am using python 2.6.4 and PyQt4. please can anyone help.

+6
source share
1 answer

Here is an example of building a custom message box from scratch.

import sys from PyQt4 import QtCore, QtGui class Example(QtGui.QDialog): def __init__(self, parent=None): super(Example, self).__init__(parent) msgBox = QtGui.QMessageBox() msgBox.setText('What to do?') msgBox.addButton(QtGui.QPushButton('Accept'), QtGui.QMessageBox.YesRole) msgBox.addButton(QtGui.QPushButton('Reject'), QtGui.QMessageBox.NoRole) msgBox.addButton(QtGui.QPushButton('Cancel'), QtGui.QMessageBox.RejectRole) ret = msgBox.exec_() if __name__ == "__main__": app = QtGui.QApplication(sys.argv) ex = Example() ex.show() sys.exit(app.exec_()) 
+18
source

All Articles