Unsolved Block mouse click if window didn't have focus before click occurred
-
I have a
QMainWindow
with aneventFilter
for 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 soisActiveWindow
always returnstrue
. AndQMainWindow::hasFocus
is alwaysfalse
. -
@Violet-Giraffe
Hi,
You should get aQEvent::WindowActivate
event, 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.Kind regards.
-
@kshegunov
I know about WindowActivate event, but how can I use it to achieve my goal? How do I know that thisMouseButtonRelease
event is what caused the window to gain focus? -
@Violet-Giraffe
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.