[PyQt] How to get the event of child widget

David Boddie david at boddie.org.uk
Thu Apr 22 01:40:16 BST 2010


On Wed Apr 21 11:43:24 BST 2010, Jothybasu K Selvaraj wrote:

> I am trying to ignore the close event of a subwindow, but I don't know how
> to do that.

[...]

> class App(QMainWindow,MW.Ui_Form):
>     def __init__(self,parent=None):
>         super(App,self).__init__(parent)
>         self.setupUi(self)
>         flags=QtCore.Qt.Popup
>         flags |= QtCore.Qt.WindowTitleHint
>         self.subwindow.setWindowFlags(flags)
>         self.mdiArea.addSubWindow(self.subwindow)
>         self.subwindow.show()
>         self.connect(self, Qt.SIGNAL('triggered()'),self.closeEvent)
>
>     def closeEvent(subwindow,event):
>         subwindow.event.ignore()

This won't work because the closeEvent() handler is only called for the
main window itself - calling the first parameter, "subwindow", just means
that you access the QMainWindow instance using that name.

I would have thought that it would be possible to set some option to manage
subwindow behaviour, but maybe it isn't. Anyway, I see you have already
investigated the use of window flags to prevent the user from closing the
subwindows using their close buttons.

What you may want to do is to install an event filter on each subwindow as
you create them:

  http://doc.qt.nokia.com/4.7-snapshot/eventsandfilters.html

You could write a simple eventFilter() method in your QMainWindow subclass
that handles events for all the subwindows, filtering out the Close event
type so that subwindows can never be closed.

David


More information about the PyQt mailing list