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

QTabletEvents don't scale well with high-dpi setting enabled

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • P2: Important
    • None
    • 5.15.0
    • None
    • I have tested this on Windows 10 with scaling set to 175%.
    • Windows

    Description

       

      When drawing on a tablet with Windows 10 with  Qt::AA_EnableHighDpiScaling enabled, QTabletEvents coordinates are not scaled with the scale factor of Windows 10 (e.g. 175%). So for example in a simple painting application when the user draws on the center of a QQuickItem using the coordinates from a QTabletEvent, visually the strokes appear on the top left of the window. To workaround this issue one can multiply the coordinates of the QTabletEvent by the effective devicePixelRatio of the current window (e.g. using QQuickWindow::effectiveDevicePixelRatio) and the coordinates are correctly scaled.

      However, even this workaround is incomplete. The problem is that it only works if the drawing is done using QTabletEvent:posF() which, according to my testing on Windows 10, only returns coordinates to double precision with no more than 1 decimal place. In order to obtain high precision coordinates the following hack is needed:

       

      // event is QTabletEvent retrieved from QQuickWindow and delivered to a QQuickItem
      QPointF pos; 
      pos.setX(event->globalPosF().x()- event->globalX() + event->x());
      pos.setY(event->globalPosF().y() - event->globalY() + event->y());

      This retrieves high precision coordinates, but when a scaling factor is applied according to the device pixel ratio (e.g. pos * QQuickWindow::effectiveDevicePixelRatio) there are some artifacts and the strokes drawn are "shaky". I have checked that using:

      QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
      

      mitigates this somehow but doesn't exactly resolve the issue. If high dpi scaling is disabled, the issue is non-existent.

      The issue described above can easily be reproduced on Window 10 tablets (mine is a Samsung Galaxy Book 10.6) by creating a simple drawing application that uses QQuickPaintedItem (example https://github.com/dragly/hello-remarkable). I can also provide one if needed.

       

      Attachments

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

        Activity

          People

            srutledg Shawn Rutledge
            daljit97 Daljit Singh
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes