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. QCursor::setPos doesn't support float arguments?
Qt 6.11 is out! See what's new in the release blog

QCursor::setPos doesn't support float arguments?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 520 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.
  • F Offline
    F Offline
    FishBoneEK
    wrote on last edited by FishBoneEK
    #1

    Hello!
    Noticed that QCursor::setPos only accept int coordinates, so I can't perfectly set the mouse pos under high DPI screens?

    I'm trying to make a drag zone on QML that prevents the mouse to go outside the window while dragging:

    • start dragging, record start coordinate
    • onPositionChanged, calculate mouse coord delta, emit event
    • QCursor:::setPos move mouse back to start coord
    • onPositionChanged...
    • In the end the user is able to move something (like a slider, based on emitted delta events)
      while preventing the mouse to go outside the window

    On 100% scaled screens it works fine, but on 125% scaled screen the moved "thing" starts drifting, e.g. if you move the mouse in a circle the "thing" starts to drift to the corner of the window.

    My guess is QCursor::setPos accepts int arguments so each time it's not perfectly set to the start coordinate, causing a bias to the delta events.

    Platform is Windows.

    Thanks!

    1 Reply Last reply
    0
    • F Offline
      F Offline
      FishBoneEK
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • F Offline
        F Offline
        FishBoneEK
        wrote on last edited by
        #3

        Example codes:

        • QML drag zone: https://pastebin.com/WjEGTBiV
        • QML main: https://pastebin.com/0eZJqFVh
        • C++ helper: https://pastebin.com/1L66xgTh
        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          There might be a rounding error somewhere but you can't position on a half pixel in e.g. windows - see SetCursorPos.
          So yes, with 125% the logical position 61/62 is mapped to the physical position 76/78 while it should be 76,25/77,5 but SetCursorPos can't handle this.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2

          • Login

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