There are two windows in my Qt project: parant and child. Child window is modal, so all clicks on parent window are ignored by system. I need to react on mouse clicks on internal part of parant window (I understand that it is strange requirement, but I can't persuade customer to do not ask it).
So what do we have: parent window is disabled (because child window is opened and modal). And I need to catch mouse click on this blocked (disabled) window.
I see two ways to do it:
Simulate modality of child window. It is my current temporary solution: I've commented out line
setWindowModality(Qt::WindowModal);in the code of child window (i.e. child window is not modal now), so I can catch mouse clicks on parent window. And I've seteventFilter()for parent window to ignore the most of actions. This solution works, but it looks wrong and rough.Find way to catch mouse events on disabled window. Unfortunatelly I can't catch it by
eventFilter()(because input of parent window is blocked). Do you see other approaches?
Or do you see other ways to do it?
This can be done by installing an event filter on the parent window inside the child window.
Here is an example project I did to demonstrate it:
untitled3.pro:
form.h:
form.cpp:
mainwindow.h:
mainwindow.cpp:
form.ui:
mainwindow.ui:
main.cpp:
The result is that the child widget loses focus but always stays on top of the parent widget. Let me know if it is what you are looking for.