Finding current mouse position in QT

后端 未结 2 1574
北海茫月
北海茫月 2021-01-22 06:19

This is my first attempt at writing a QT app, and I\'m just trying to get a feel for how it works. My goal is to have a 400x400 widget which knows the exact position of the mous

相关标签:
2条回答
  • 2021-01-22 07:06

    If you are ever in a situation when you don't need actual tracking, just position at the moment, you can use QCursor::pos().

    0 讨论(0)
  • 2021-01-22 07:15

    For your widget, you must enable mouse tracking.

    Then, you can either install an event filter, paying attention to mouse events and looking for the move event, or you can inherit from QWidget and override the mouse event, looking for mouse move events.

    http://doc.qt.io/qt-4.8/qwidget.html#mouseTracking-prop

    http://doc.qt.io/qt-4.8/eventsandfilters.html

    http://doc.qt.io/qt-4.8/qmouseevent.html

    0 讨论(0)
提交回复
热议问题