How to get mouse position on the screen in Qt?

I want to get the coordinates of the mouse on the screen.

How can I do this in Qt?


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

+6
qt qtgui
source share
2 answers

As indicated in the docs: -

QCursor::pos() 

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

If you have multiple screens, you can use: -

 QPoint QCursor::pos(const QScreen * screen) 

Please note that QScreen for Qt 5

+9
source share

Try the following:

 QCursor::pos() 

should work fine

+3
source share

All Articles