1

I have my main application QWindow where, when I press a QPushButton a new child window (a QWidget) pops up. There are two ways of exiting the QWidget window:

  1. Click the X in the top right hand corner, or
  2. Click on the 'Finished' QPushButton I have in the QWidget window.

I would like to ensure that, when either method is used to exit the window, the QWidget is deleted. I believe that I can ensure this in the second case by adding self.deleteLater() to the function called when the 'Finished QPushButton is clicked, but I am struggling to see how to do this in the first case.

derNincompoop
  • 672
  • 11
  • 22

1 Answers1

1

You can set an attribute on the widget to do this:

class Widget(QtGui.QWidget)
    def __init__(self, parent=None)
        super(Widget, self).__init__(parent)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

Your "Finished" button then only has to call self.close() (which is equivalent to clicking the titlebar close button).

ekhumoro
  • 115,249
  • 20
  • 229
  • 336