Ionică Bizău
Ionică Bizău

Reputation: 113517

How to get the mouse position on the screen in Qt?

I want to get the mouse coordinates on the screen.

How can I do this in Qt?


On Windows, using C# I was doing something like suggested in the answers to this question.

Upvotes: 9

Views: 13024

Answers (2)

TheDarkKnight
TheDarkKnight

Reputation: 27639

As the docs state: -

QCursor::pos()

Returns the position of the cursor (hot spot) of the primary screen in global screen coordinates.

If you have multiple screens, you can use: -

QPoint QCursor::pos(const QScreen * screen) 

Note that QScreen is for Qt 5

Upvotes: 11

Thomas Ayoub
Thomas Ayoub

Reputation: 29479

Try this :

QCursor::pos()

should work perfectly

Upvotes: 3

Related Questions