Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Get Mouse local position on key press event
Forum Updated to NodeBB v4.3 + New Features

Get Mouse local position on key press event

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RiccardoTurati
    wrote on last edited by
    #1

    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.
    Riccardo.

    F 1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      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.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • R RiccardoTurati

        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.
        Riccardo.

        F Offline
        F Offline
        Funtess
        wrote on last edited by
        #3

        @RiccardoTurati Could use mapFromGlobal.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved