[PyQt] Problem with destroyed() signal and QMainWindow

Phil Thompson phil at riverbankcomputing.com
Wed Aug 18 18:25:13 BST 2010


On Wed, 18 Aug 2010 08:43:00 -0700 (PDT), dizou <di_zou at yahoo.com> wrote:
> I have a QMainWindow that spawns another QMainWindow. When the second
> QMainWindow is closed by the x button in the upper right corner, I want
> some
> stuff to happen in the first QMainWindow. This is what I have:
> 
> class MainWindow(QMainWindow):
>     def __init__(self):
>         QMainWindow.__init__(self)
>     def EnterDrawMode(self):
>         drawWindow = DrawWindow(self)
>         drawWindow.show()
>         self.connect(drawWindow, SIGNAL("destroyed()"), self.Test)
>     def Test(self):
>         print "exit"
>         #do stuff
> 
> class DrawWindow(QMainWindow):
>     def __init__(self, parent):
>         QMainWindow.__init__(self, parent)
>         self.setObjectName("DrawWindow")
>         self.setFixedSize(200, 200)
> 
> However, when I close DrawWindow, nothing happens. What am I doing
wrong?

Closing a window doesn't necessarily destroy it. Check the
WA_DeleteOnClose widget attribute.

Phil


More information about the PyQt mailing list