PDA

View Full Version : grabbing position of mouse



safknw
24th November 2006, 12:08
How can i grab position of mouse in my application, and how can hide or show mouse.

jacek
24th November 2006, 12:15
QCursor

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

munna
24th November 2006, 12:15
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 (http://doc.trolltech.com/4.2/qcursor.html#details) shows the various shapes that you can change your cursor to.

Use BlankCursor to hide and ArrowCursor to show.

jacek
24th November 2006, 12:18
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.

safknw
24th November 2006, 12:52
I want to limit mouse's position within main windows my application, how I can do this?

aamer4yu
24th November 2006, 12:58
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

munna
24th November 2006, 12:59
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 ?

safknw
24th November 2006, 13:05
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.

munna
24th November 2006, 13:13
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.

mooreaa
25th June 2008, 05:17
Is there a way to get the local coords when using GraphicsView? like perhaps scene coords relative to current view?

jpn
28th June 2008, 16:00
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.