Detect a click on a QMdiArea
-
Hello,
I would like to detect clicks on my QMdiArea. It seems very simple but in fact I couldn't manage to do it... What I really want to do is to detect a click on the whole mdi area.
I mean by this : in any widget contained by the QMdiArea, wether it is the background or a QMdiSubWindow or whatever these QMdiSubWindows may contain ! I already tried to inherit QMdiSubWindow to send a signal to tell it has been clicked. The mousePressEvent has only been received when the user clicked on the title bar of the sub window. If there is a widget in the subwindow, it handles the event then shuts up. MdiSubWindows will never hear of this event.
How could I force every child of a widget to let me know when it has been clicked, as I don't know them all when compiling as well (some of them are plugins) ? It wouldn't be very handy to reimplement every Qt class to add a clickedOn() signal in every possible Widget (that should be available in Qt I think and the event should be sent to the parent everytime even if the child handles it, and if you don't want that you could just specify a widget attribute or something)...
The problem seems very simple to resolve but I'm trapped in a dead end, I searched in the whole documentation and I couldn't find anything which allows this. Maybe I didn't search well, I don't know.Anyway, thank you for your cooperation !
-
Install an event filter on the QMdiArea:
http://qt-project.org/doc/qt-4.8/qobject.html#installEventFilterIf that doesn't work, Install it on all subwidgets, too. (This can be done dynamically during runtime, see http://qt-project.org/doc/qt-4.8/qobject.html#findChildren which gives you all child objects recursively)
-
Thanks a lot for your answer ! It only works with findChildren() but it works well. The only issue is that I have to make sure that the eventFilter is installed on dynamically allocated widgets during runtime after my main window constructor is set. Anyway, I'll document this for my program's plugin developers.