Qt 5, get the mouse position in a screen

前端 未结 6 1346
难免孤独
难免孤独 2020-12-17 10:37

First of all, I\'d like to mention that I found that related post How to get the mouse position on the screen in Qt? but it \"just didn\'t work\" for me. I made some tests,

6条回答
  •  孤街浪徒
    2020-12-17 10:57

    This may seem like a trivial solution, but on my KDE it works (I ran into the same problems originally). If you want to determine the local mouse coordinates with respect to a widget (this will be in device pixels and relative to the top left corner of the widget I believe) you can use

    QWidget::mapFromGlobal(QCursor::pos());
    

    i.e. call this->mapFromGlobal.

提交回复
热议问题