Python Forum
Closing Modal Window in QT
Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Closing Modal Window in QT
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 341 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  [Tkinter] Modal window DPaul 14 2,301 Oct-18-2023, 06:11 AM
Last Post: DPaul
  [PyQt] PyQt5 window closing when trying to display a graph bianca 4 1,618 Aug-12-2023, 03:25 PM
Last Post: bianca
Exclamation [Tkinter] Error when closing the main window with destroy TomasSanchexx 1 727 Aug-06-2023, 01:54 AM
Last Post: deanhystad
Question closing a "nested" window with a button in PySimpleGUI and repeating this process Robby_PY 9 13,408 Jan-18-2021, 10:21 PM
Last Post: Serafim
  [PyQt] Received RunTimeError after script concludes, closing Dialog Window (clicking x-out) skipper0802 0 2,524 Oct-09-2020, 09:23 PM
Last Post: skipper0802
  Closing window on button click not working kenwatts275 4 3,663 May-03-2020, 01:59 PM
Last Post: deanhystad
  tkinter window and turtle window error 1885 3 6,619 Nov-02-2019, 12:18 PM
Last Post: 1885
  [split] Closing a window but not the whole program scriptdrache 1 2,304 Jun-25-2019, 03:43 PM
Last Post: joe_momma
  [Tkinter] Closing a window but not the whole program Wiggy1 2 4,939 Jan-11-2019, 12:51 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020