Python Forum

Full Version: Closing Modal Window in QT
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

 I create a modal dialog in PyQT5 in this way:

from PyQt5 import QtCore, QtGui, QtWidgets

class FirmUi_Dialog(object):


   def setupUi(self, Dialog):
       Dialog.setObjectName("Dialog")
       Dialog.setWindowModality(QtCore.Qt.ApplicationModal)
       Dialog.resize(311, 300)
       Dialog.setModal(True)
       self.groupBox = QtWidgets.QGroupBox(Dialog)
....
       self.saveFirmPB = QtWidgets.QPushButton(Dialog)
       self.saveFirmPB.setGeometry(QtCore.QRect(140, 240, 75, 23))
       self.saveFirmPB.setObjectName("saveFirmPB")
       self.cancelPB = QtWidgets.QPushButton(Dialog)
       self.cancelPB.setGeometry(QtCore.QRect(220, 240, 75, 23))
       self.cancelPB.setObjectName("cancelPB")
       self.saveFirmPB.clicked.connect(self.saveFirmToDB)
       self.cancelPB.clicked.connect(self.closeFirmDialog)

       self.retranslateUi(Dialog)

   def saveFirmToDB(self):
      print("Save")

   def closeFirmDialog(self):
      pass  #How I can close the Dialog (Modal Window)
            self.close() #doesn't work 
to open the dialog in the Mainwindow, I create the following function:

def showFirmaDialog(self):
   firmDialog = QtWidgets.QDialog()
   ui = FirmUi_Dialog()
   ui.setupUi(firmDialog)
   firmDialog.exec_()
This steps works fine. But I dont' find a way to trigger the close event for this dialog when I push the cancelPB 

Greetings 

niesel