title: PyQT5 QGIS Dialog Interactions
body: <p>Background:
  Im trying to use a QT designer form as a QGIS attribute form (which is fine and working) but the code for this doesnt follow any documentation or examples ive been  able to find. I did find a little from 2007 which has at least allowed me to get alot working but i feel like its terribly inefficient.</p>
  
  <p>Problem:
  Getting access to events (closeEvent) from a dialog form within QGIS.</p>
  
  <pre><code>import sys
  from PyQt5.QtWidgets import QWidget, QMessageBox, QApplication
  
  
  class Example(QWidget):
  
      def __init__(self):
          super().__init__()
  
          self.initUI()
  
  
      def initUI(self):               
  
          self.setGeometry(300, 300, 250, 150)        
          self.setWindowTitle('Message box')    
          self.show()
  
  
      def closeEvent(self, event):
  
          reply = QMessageBox.question(self, 'Message',
              "Are you sure to quit?", QMessageBox.Yes | 
              QMessageBox.No, QMessageBox.No)
  
          if reply == QMessageBox.Yes:
              event.accept()
          else:
              event.ignore()        
  
  
  if __name__ == '__main__':
  
      app = QApplication(sys.argv)
      ex = Example()
      sys.exit(app.exec_())
  </code></pre>
  
  <p>I got this code from <a href="http://zetcode.com/gui/pyqt5/firstprograms/" rel="nofollow noreferrer">Zetcode Link</a> which im sure would work for standalone of pyqt5 but if i try use this in qgis it crashes the entire application. I believe this is because QGIS is the application and the dialog is under that somehow so the event maybe links to the dialog differently and im not sure how to access that. Does anyone have an idea of how i could access the close event for the dialog thats created using QGIS attribute forms.</p>