Block mouse click if window didn't have focus before click occurred
I have a
eventFilterfor one of its child widgets where I detect single click (
MouseButtonRelease) and do stuff. But I want to do nothing if the window didn't have focus before the click occurred (i. e. I clicked the window to switch to it, not to launch stuff). Is there a way to construct such a condition? So far I don't see a way: by the time the event is processed the window already has focus so
You should get a
QEvent::WindowActivateevent, but I'm not quite sure it's a good idea to depend on the order of events ... that is if you can be sure that the activate event arrives before the mouse event.
I know about WindowActivate event, but how can I use it to achieve my goal? How do I know that this
MouseButtonReleaseevent is what caused the window to gain focus?
short answer: you can't. At least not using Qt only.
The OS handles and sends the window activation to the window. Then Qt translates the event and posts it in the event queue.
So you see this OS specific and you wont be able to determine the correlation between the window activation and mouse button press.