Results 1 to 3 of 3

Thread: How to reliably detect if the mouse is inside a widget

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default How to reliably detect if the mouse is inside a widget

    Hello!

    The title says it all, I want to detect if the mouse pointer is inside a widget or not. Mouse tracking is enabled and I get mouseMoveEvents when the mouse is moving inside the widget. However, I do not get an event when the mouse is outside of the widget, so I can't detect if the mouse is actually outside or just not moving.

    I tried a naive approach by defining a margin along the border of the widget and if the mouse pointer is in that margin I assume that the mouse has left the widget. But any margin can be jumped over if the mouse is moving fast enough so this was a waste of time.

    How to do it right?

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: How to reliably detect if the mouse is inside a widget

    I don't know the right way, but I guess you can get the global cursor position with QCursor:os()
    ( http://developer.qt.nokia.com/doc/qt...ursor.html#pos ) and then see whether it is inside your widget.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to reliably detect if the mouse is inside a widget

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. The following user says thank you to wysota for this useful post:

    Cruz (2nd January 2012)

Similar Threads

  1. How to detect hover events when mouse button is pressed
    By yagabey in forum Qt Programming
    Replies: 12
    Last Post: 26th April 2016, 09:23
  2. how to detect mouse click on qwtPlot?
    By rambo83 in forum Qwt
    Replies: 7
    Last Post: 18th December 2013, 05:04
  3. Replies: 8
    Last Post: 28th June 2011, 14:57
  4. Replies: 0
    Last Post: 11th January 2011, 09:00
  5. Mouse move inside control/Widget
    By squidge in forum Newbie
    Replies: 0
    Last Post: 27th September 2009, 16:56

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.