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

Tablet input events are mistakenly generated when hovering the screen on Windows

    XMLWordPrintable

Details

    • Windows

    Description

      On Windows, there is a bug in the tablet input system that causes Qt applications to mistakenly understand that a stylus is in contact with the screen when the user is touching the screen with their fingers.

      Steps to reproduce:

      1. Swipe on a touchscreen using a finger.
      2. Hold the finger without lifting it.
      3. Then hover on the screen with a stylus (without touching it).

      Qt applications detect the actions above as the user actually using their stylus to be in contact with the screen (which is obviously not the case).

      Here is a small QML example (the problem can also be consistently reproduce with Tablet Widgets example):

      import QtQuick
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          PointHandler {
              id: handler
              acceptedDevices: PointerDevice.Stylus
          }
      
          Rectangle {
              width: 50; height: 50
              color: "red"
              x: handler.point.position.x
              y: handler.point.position.y
          }
      }
      

      Here if you carry the steps above, you'll see the rectangle moving even if you hover with the stylus without touching the screen.

      Digging into the code I found out that this happens because in QWindowsPointerHandler::translatePenEvent, the code determines that the left button is pressed. In queryMouseButtons, `GetAsyncKeyState(VK_LBUTTON) < 0` is used to detect whether the left mouse button is pressed but on Windows this also returns true when the user is touching the screen.
      So in my understanding, this mistakenly generates a QTabletEvent::Press event (also the Qt documentation explicitly mentions that "0.0 (pressure) indicates that the stylus is not on the tablet", yet the QTabletEvent::Press event is triggered with a pressure value of 0).

      I am not exactly sure what would the appropriate solution be here, but I think in the case of stylus events the mouse buttons should include the Qt::LeftButton flag only if the pen is actually touching the screen (i.e. using IS_POINTER_INCONTACT_WPARAM).

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated: