Results 1 to 5 of 5

Thread: How to get mouse click event in GUI application regardless of widgets

  1. #1
    Join Date
    Jul 2012
    Posts
    53
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to get mouse click event in GUI application regardless of widgets

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get mouse click event in GUI application regardless of widgets

    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,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Seishin (29th July 2016)

  4. #3
    Join Date
    Jul 2012
    Posts
    53
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get mouse click event in GUI application regardless of widgets

    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?

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get mouse click event in GUI application regardless of widgets

    I already answered that, didn't I?
    Maybe you only clicked the link instead of also reading the text of the previous comment?

    Cheers,
    _

  6. #5
    Join Date
    Jul 2012
    Posts
    53
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get mouse click event in GUI application regardless of widgets

    Quote Originally Posted by anda_skoa View Post
    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/5009...lude-QKeyEvent

Similar Threads

  1. create mouse click event problem
    By yagabey in forum Qt Programming
    Replies: 6
    Last Post: 8th October 2009, 21:45
  2. can not get mouse double click event for QGraphicsItem
    By learning_qt in forum Qt Programming
    Replies: 2
    Last Post: 14th September 2009, 20:36
  3. Mouse click event problem
    By impeteperry in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2007, 13:44
  4. The event fired by the mouse click on the frame
    By Placido Currò in forum Qt Programming
    Replies: 8
    Last Post: 3rd March 2007, 09:05
  5. mouse click event
    By vijay anandh in forum Qt Programming
    Replies: 1
    Last Post: 1st May 2006, 09:24

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.