Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

call function when close second windows



  • class Ui_first1(object):
     def setupUi(self, first1):
         first1.setObjectName("first1")
         first1.resize(380, 249)
         
         self.label = QtWidgets.QLabel(first1)
         self.label.setGeometry(QtCore.QRect(160, 80, 191, 71))
         self.label.setObjectName("label")
    
         self.retranslateUi(first1)
         QtCore.QMetaObject.connectSlotsByName(first1)
    
     def retranslateUi(self, first1):
         _translate = QtCore.QCoreApplication.translate
         first1.setWindowTitle(_translate("first1", "Form"))
         self.label.setText(_translate("first1", "first windows"))
    
     
    
    
    class Ui_second2(object):
     def setupUi(self, second2):
         second2.setObjectName("second2")
         second2.resize(394, 300)
         self.label = QtWidgets.QLabel(second2)
         self.label.setGeometry(QtCore.QRect(50, 120, 191, 71))
         self.label.setObjectName("label")
         app.aboutToQuit.connect(self.closeEvent) # as I understand its bind close button
    
         self.retranslateUi(second2)
         QtCore.QMetaObject.connectSlotsByName(second2)
    
     def retranslateUi(self, second2):
         _translate = QtCore.QCoreApplication.translate
         second2.setWindowTitle(_translate("second2", "Form"))
         self.label.setText(_translate("second2", "second windows"))
    
     # need print text when user close second windows, but print when close firs windows
     def closeEvent(self,):
         print("close")
    

    When a close second windows nothing happens, but when I close all windows and the function is called. I need to call function when close only second windows. How to fix it?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You are modifying the wrong part of the code. The Ui_XXX classes are generated based on the .ui file you created with designer. They are not even widgets. You need to modify the widget code that uses the Ui_XXX classes.


Log in to reply