I want to create a python GUI using QMessageBox Widget with custom buttons and custom button roles. I have created custom buttons but how to add custom role to a button when it is clicked. The widget has standard button roles but I want to define custom button click functions.
Kindly help me with proper code syntax.
Below is my code:
import sys
from PyQt4 import QtGui,QtCore
class MYGUI(QtGui.QWidget):
def __init__(self):
super(MYGUI,self).__init__()
self.setWindowTitle("GUI")
#widgets:
self.labl=QtGui.QLabel(self)
self.labl.setFont(QtGui.QFont('Calibri', 34))
#Layout:
Layout =QtGui.QVBoxLayout()
Layout.addWidget(self.labl)
Layout.addStretch()
self.setLayout(Layout)
#Actions:
Queries={'Q1':'question 1','Q2':'question2'}
for k,val in Queries.items():
self.Choice=QtGui.QMessageBox()
self.Choice.setIcon(QtGui.QMessageBox.Question)
self.Choice.setWindowTitle(k)
self.Choice.setText(val)
self.Choice.addButton(QtGui.QPushButton('BT1',self))
self.Choice.addButton(QtGui.QPushButton('BT2',self))
self.Choice.addButton(QtGui.QPushButton('BT3',self))
self.Choice.exec_()
self.show()
def main():
app=QtGui.QApplication(sys.argv)
GUI=MYGUI()
sys.exit(app.exec_())
main()