PDA

View Full Version : How to get mouse click event in GUI application regardless of widgets



Seishin
26th July 2016, 22:47
I'm working on adding a screensaver to my GUI application.
The issue is I want to get the general mouse click event and use it to update the timer of screensaver.
However right now when I click some push buttons or list items, only the clicked widget get the click event but outside container doesn't.
I wonder is there a way to get the general click event in the application instead of rewrite all the widgets to pass click event to their parents widgets?

Thanks in advance.

anda_skoa
26th July 2016, 23:22
All UI events pass through the main application instance.
You can install an event filter on it to see them as they pass through.

See QObject::eventFilter().

Cheers,
_

Seishin
29th July 2016, 16:32
Thanks. The eventFilter() works well for me. But the the thing annoying to me is I have to install the filter on each widget in my container. I wonder is there a more direct way to handle the "global click event" in application?

anda_skoa
29th July 2016, 17:10
I already answered that, didn't I?
Maybe you only clicked the link instead of also reading the text of the previous comment?

Cheers,
_

Seishin
29th July 2016, 23:12
I already answered that, didn't I?
Maybe you only clicked the link instead of also reading the text of the previous comment?

Cheers,
_

I did read your comment but misunderstood to install the filter on children widgets, which is what I always did with event filter.
Now I installed the filter on qApp and it works like a charm.

Also I found a post with code explaination for who met the same issue.
http://www.qtcentre.org/threads/50090-QApplication-handle-all-event-why-does-not-include-QKeyEvent