I'd like to be able to execute a callback when a QDialog is shown in PyQt4, preferably via the signal/slot mechanism. Looking at the PyQt documentation on QDialog, I can't find the correct signal to which to attach the slot that I want run.
What is a good way to do this?
If you want a signal to be emitted every time the dialog is shown, you could create a class like this:
class Dialog(QtGui.QDialog):
dialogShown = QtCore.pyqtSignal()
def showEvent(self, event):
super(Dialog, self).showEvent(event)
self.dialogShown.emit()
and then use it like this:
self.dialog = Dialog()
self.dialog.dialogShown.connect(self.handleDialogShown)
Would be fine in my opinion to override the show or showEvent method and put your callbacks there.
class MyDialog(QtGui.QDialog):
def show(self):
super(MyDialog, self).show()
callbacks()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With