I got a couple of questions regarding qDialogButtonBox. While my code still works, I believed that there are a few parts that can be better refined/ I am not finding much info online
class testDialog(QtGui.QDialog):
def __init_(self, parent=None):
...
self.init_ui()
self.signals_connection()
def init_ui(self):
...
self.buttonBox = QtGui.QDialogButtonBox()
self.buttonBox.addButton("Help", QtGui.QDialogButtonBox.HelpRole)
self.buttonBox.addButton("Apply", QtGui.QDialogButtonBox.AcceptRole)
self.buttonBox.addButton("Cancel", QtGui.QDialogButtonBox.RejectRole)
#
def signals_connection(self):
self.test_random.clicked.connect(self.test_rand)
# Is this the latest/correct way to write it?
self.buttonBox.accepted.connect(self.test_apply)
self.buttonBox.rejected.connect(self.test_cancel)
self.buttonBox.helpRequested.connect(self.test_help)
def test_apply(self):
print "I am clicking on Apply"
def test_cancel(self):
print "I am clicking on Cancel"
self.close()
def test_help(self):
print "I am clicking for Help!"
My questions are as follows:
[ol]
[li]Under my function - signals_connection(), the lines that I wrote for the buttonBox (though the code still works) are quite different for the signal I have wrote for the self.test_random and I am unable to find any similar online for the qdialogbuttonbox… There is another style that I have found - self.connect(self.buttonBox, QtCore.SIGNAL(“accepted()”), self, QtCore.SLOT(“accept()”)) but I think that is the old style?? Otherwise what should be the right way to write it?
[/li]
[li]In my test_cancel() function, is writing self.close() the best way to close the application? The way that I run my program is as follows:
[/li]
dialog = testDialog();dialog.show()
[li]Lastly, is it possible to add 3 different tool tips to the 3 buttons I have created? I saw that there is a command for it - self.buttonBox.setToolTip(“Buttons for life!”), but this will results in all 3 buttons to have the same tool tip. Can I make it as individual?
[/li][/ol]