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. Retain mouse coordinates after Zoom in/out.
Forum Update on Monday, May 27th 2025

Retain mouse coordinates after Zoom in/out.

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 443 Views
  • 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
    rohit1729
    wrote on last edited by
    #1

    I've a central widget with scaled axes . I'm getting the coordinates by using:

    x = (event->pos().x());
    y = (event->pos().y());
    

    This is working fine. After zooming in or out, the coordinates still remain same. But from the point of view of central widget, it should get changed. How do I achieve this?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Well how do you zoom the central widget ?
      You have to apply the same math to the mouse coordinates to
      calculate a zoomed point.

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        What @mrjj said. In (pseudo) code it's simply:

        QPoint newCursorPos = oldCursorPos / oldZoomFactor * newZoomFactor;
        
        1 Reply Last reply
        1
        • R Offline
          R Offline
          rohit1729
          wrote on last edited by
          #4

          I'll restate the problem:
          When I zoomed in and hover on the upper left corner, the location should NOT be 0,0 (the QMouseMouseEvent just gives me this point). I want the coordinates relative to the central widget.

          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