Home > Mobile >  QDialog - how to close with custom button in pyqt5
QDialog - how to close with custom button in pyqt5

Time:04-25

I use this code to open Dialog box but I do not know how to close it without default button

code :

class MyApp (QMainWindow):
    def __init__(self) -> None:
        super().__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        #### signals ####
        self.ui.action_add_contacte.triggered.connect(self.Dialog_add_contact)
        
        
    def  Dialog_add_contact(self):
        dialog = QtWidgets.QDialog()
        dialog.ui = Ui_Dialog_add_contacte()
        dialog.ui.setupUi(dialog)
        dialog.ui.btn_cancel_add_contacte.clicked.connect(lambda:pass #some code need to close)
        dialog.exec_()

I try

Dialog.ui.close()

but did not work

CodePudding user response:

Just as any widget, dialog.close().

ui is not a widget, it's helper class object, you cannot close() it.

  • Related