Results 1 to 11 of 11

Thread: grabbing position of mouse

  1. #1
    Join Date
    May 2006
    Location
    Pune,India
    Posts
    63
    Thanks
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Unhappy grabbing position of mouse

    How can i grab position of mouse in my application, and how can hide or show mouse.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: grabbing position of mouse

    QCursor
    Note that Qt::CursorShape enum includes Qt::BlankCursor value.

  3. #3
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: grabbing position of mouse

    How can i grab position of mouse in my application
    you can reimplement QWidget's mouseMoveEvent(QMouseEvent *event) and get the current position of the mouse.

    how can hide or show mouse.
    You can use QWidget::setCursor() to change the shape of your cursor.
    This shows the various shapes that you can change your cursor to.

    Use BlankCursor to hide and ArrowCursor to show.

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

    safknw (25th November 2006)

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: grabbing position of mouse

    Quote Originally Posted by munna View Post
    you can reimplement QWidget's mouseMoveEvent(QMouseEvent *event) and get the current position of the mouse.
    Or simply use QCursor::pos(), if you want to know only the current mouse position.

  6. #5
    Join Date
    May 2006
    Location
    Pune,India
    Posts
    63
    Thanks
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: grabbing position of mouse

    I want to limit mouse's position within main windows my application, how I can do this?

  7. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: grabbing position of mouse

    for limiting the mouse in a window -
    1) Convert mouse position from global to window position (use mapFromGlobal())
    2) check if that position lies within the window geometry ( Qwidget->geometry())

    using these u can limit the movement
    hope this helps

  8. #7
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: grabbing position of mouse

    I want to limit mouse's position within main windows my application, how I can do this?
    Do you mean you want to show mouse cursor only in the main window and hide it in all other windows ?

  9. #8
    Join Date
    May 2006
    Location
    Pune,India
    Posts
    63
    Thanks
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: grabbing position of mouse

    Quote Originally Posted by munna View Post
    Do you mean you want to show mouse cursor only in the main window and hide it in all other windows ?
    yes. Only till my application runs.

  10. #9
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: grabbing position of mouse

    You might need to do the following.

    1. Change the cursor to blank cursor for all the widgets that you don't want to show the cursor for.

    2. Reimplement mousePressEvent and mouseReleaseEvent of these widgets and do not let the event propagate.

    hmmm, I think there should definitely be a better way to achieve this, but cannot think of any right now.

  11. #10

    Default Re: grabbing position of mouse

    Is there a way to get the local coords when using GraphicsView? like perhaps scene coords relative to current view?

  12. #11
    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: grabbing position of mouse

    Quote Originally Posted by mooreaa View Post
    Is there a way to get the local coords when using GraphicsView? like perhaps scene coords relative to current view?
    QWidget, QGraphicsView and QGraphicsItem all have lots of mapFrom() and mapTo() methods.
    J-P Nurmi

Similar Threads

  1. Replies: 7
    Last Post: 8th September 2006, 16:19
  2. Replies: 2
    Last Post: 24th July 2006, 18:36
  3. Draw QtCanvasElipse on mouse press event position
    By YuriyRusinov in forum Newbie
    Replies: 1
    Last Post: 31st May 2006, 11:57
  4. Qt4.1 Mouse Position & Scaling
    By Paul Drummond in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 19:02
  5. Clearing a QLabel since the mouse position
    By SkripT in forum Qt Programming
    Replies: 10
    Last Post: 18th January 2006, 18:23

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.