Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-99009

QCursor::setPos X coordinates is wrong when DPI scaling is used



    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.15.2
    • Fix Version/s: None
    • Component/s: GUI: High-DPI
    • Labels:
    • Platform/s:
      Linux/X11, Windows


      QML applications (couldn't test on QWidget) on High-DPI multi-monitor setups cannot use `QCursor::setPos` reliably.


      How to reproduce:

      1. Use a setup with at least 2 monitors with DPI scaling enabled (200% on each screen is what I used).
      2. Start the application. It will open on your primary monitor
      3. Move the application's window to the other (secondary) monitor
      4. Call `QCursor::setPos(x, y)`. The X coordinate will always reset to 0.

      Here is a very short code snippet of the issue:

      const auto offset = ...; // Some code that computes an offset
      const auto currentPos = cursor->pos();
      const auto newPos = currentPos + offset;

      When I run the code snippet from a window on my primary monitor I get the following log:

      • `currentPos = QPoint(4419, 111)`
      • `newPos = QPoint(5750, 111)`
      • After calling setPos, `cursor->pos() = QPoint(5750, 111)` (equal to what was expected)

      If I run this exact same code but I move my application's window to my secondary monitor, I get the following log:

      • `currentPos = QPoint(582, 70)`
      • `newPos = QPoint(1913, 70)`
      • After calling setPos, `cursor->pos() = QPoint(0, 70)` (X coord has been reset to 0)


      Configs on which I could repeat the issue:

      Arch Linux

      DE: Gnome 41

      X server: Xorg

      Qt version: 5.15.2

      Primary display: 4K @200% scaling

      Secondary display: 4K @200% scaling


      Ubuntu 21.04

      DE: Gnome 3.38.5

      X Server: Xorg

      Qt version: 5.15.2

      Primary display: 1440p @200% scaling

      Secondary display: 1440p @200% scaling


      Windows 10

      Qt version: 5.15.2

      Primary display: 1920×1080 @150% scaling

      Secondary display: 4K @200% scaling


      I have a small project available that shows the example but Jira tells me there is a "missing token" when I try to upload it, I don't know how I can attach it to this message.

      In the meantime the files content can be found in the last message of this ticket on Qt's forum: https://forum.qt.io/topic/132330/qcursor-setpos-sets-wrong-x-coordinates/7


          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.



              sorvig Morten Sørvig
              ebatsin Bastien
              0 Vote for this issue
              4 Start watching this issue



                  Gerrit Reviews

                  There are no open Gerrit changes