0

I've basically just designed a quick UI in Qt Designer and converted it to python code. I can't find anywhere online on how to handle the closeEvent() for the converted code that QtDesigner gives me with a class that inherits from object. Any help would be appreciated. Here is the set up code (Haven't included specific code for each GUI element as I don't think that should be necessasry... Just want to reduce clutter... Please let me know if you need the whole code):

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(789, 440)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        # more set up code...
    def retranslateUi(self, MainWindow):
        #translateUi stuff
Isukali
  • 109
  • 12
  • What do you mean by "handle"? You want to do something when the window is closed? – user202729 Feb 11 '21 at 05:56
  • 1
    Does this answer your question? [QtDesigner changes will be lost after redesign User Interface](https://stackoverflow.com/questions/46544780/qtdesigner-changes-will-be-lost-after-redesign-user-interface) (hint: **never** edit the code generated by pyuic: that class is **not** a Qt class, so no `closeEvent` will ever called; read more about [using Designer](https://www.riverbankcomputing.com/static/Docs/PyQt5/designer.html) and don't try to change those files anymore). – musicamante Feb 11 '21 at 06:18
  • @musicamante (tip: you should not edit the autogenerated comments as they will be deleted automatically) it isn't really clear that this is the problem OP is currently having, they might still be stuck at a previous step. – user202729 Feb 11 '21 at 06:32
  • Let me clarify. By "handle" I want to do something when the window is closed @user202729 How can I do this? – Isukali Feb 11 '21 at 06:36
  • @musicamant But then how do I make something happen when the window is closed? For example, output to the console, "Window Closed" or run another function, etc. you get the idea. – Isukali Feb 11 '21 at 06:40
  • @Azerox You could subclass `QMainWindow` and overload `closeEvent`. The first answer in post that @musicamante linked to does exactly that. – Heike Feb 11 '21 at 11:52

0 Answers0