Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

qt

qtgui

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.

like image 535
Ionică Bizău Avatar asked Oct 22 '13 16:10

Ionică Bizău


1 Answers

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

like image 127
TheDarkKnight Avatar answered Oct 27 '22 00:10

TheDarkKnight