Please nominate your Qt Champions for 2021!

Get Mouse local position on key press event

  • Good day,
    I would like to retrive mouse local position inside a key press event.
    How could i do?
    I have used QCursor::pos(); , but it gives me only the global position.
    Anyone could help me?
    Thank you all.
    Best Regards.

  • Moderators

    You could enable mouseTracking in the widget you're interested in, and have its mouseMoveEvent update a local QPoint member variable as the mouse moves. Then you could just read the latest position from that variable in the keyPressEvent.

Log in to reply