Results 1 to 5 of 5

Thread: How to get mouse's position?

  1. #1
    Join Date
    Jan 2006
    Posts
    55
    Thanks
    13
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default How to get mouse's position?

    I want to get mouse's position in a widget not through QMouseEvent,How can I do this?
    thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to get mouse's position?

    then you will have to work directly with X.
    (Why can't you use QMouseEvent?)

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to get mouse's position?

    Qt Code:
    1. QPoint p = widget->mapFromGlobal(QCursor::pos());
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  4. The following 2 users say thank you to jpn for this useful post:

    Bigpet (14th July 2010), coralbird (23rd July 2006)

  5. #4
    Join Date
    Jan 2006
    Posts
    55
    Thanks
    13
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to get mouse's position?

    Quote Originally Posted by high_flyer
    then you will have to work directly with X.
    (Why can't you use QMouseEvent?)
    sure,I am building a GUI program, but mouseMove event just can be captured when left
    or right button is pressed, which is different with windows ,and grap mouse input is
    dangerous,so I have to get mouse position in timerEvent().

  6. #5
    Join Date
    Jan 2006
    Posts
    55
    Thanks
    13
    Qt products
    Qt3
    Platforms
    Unix/X11

    Talking Re: How to get mouse's position?

    Quote Originally Posted by jpn
    Qt Code:
    1. QPoint p = widget->mapFromGlobal(QCursor::pos());
    To copy to clipboard, switch view to plain text mode 
    Thanks a lot! I will test it.

Similar Threads

  1. Replies: 1
    Last Post: 18th July 2006, 13:06
  2. Position of Qt::WindowFlags / Qt::Popup
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 3rd July 2006, 16:44
  3. Compare QString alphabet position
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 2nd July 2006, 17:50
  4. set Position
    By mickey in forum Newbie
    Replies: 3
    Last Post: 17th June 2006, 22:30
  5. Qt4.1 Mouse Position & Scaling
    By Paul Drummond in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 20:02

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.