Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Handling stylus input in QML
Forum Updated to NodeBB v4.3 + New Features

Handling stylus input in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 614 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.
  • L Offline
    L Offline
    Larvae
    wrote on last edited by Larvae
    #1

    Hi,

    I'm trying to handle the input of a stylus on a tablet in QML, but I'm stuck.

    Qt has an example on how to use classic C++ to draw on a tablet. In the example they inherit QWidget to create a canvas which can handle QTabletEvent-events, allowing you to draw thick and thin lines based on the pen preassure. It works fine on my tablet.

    I'm trying to get the same in modern QML. From what I have found, the QML element to handle this would be PointHandler. I can't get it to handle pen input, though. This is my last code to test this:

    Window {
        visible: true
        width: 640
        height: 480
        id: main
        title: qsTr("Hello World")
    
        Label {
            id: label
            anchors.centerIn: parent
        }
    
        Rectangle {
            anchors.left: main.left
            anchors.top: main.top
            width: main.width
            height: main.height
            opacity: 0
            PointHandler {
                acceptedDevices: PointerDevice.AllDevices
                onActiveChanged: {
                    label.text = (active == true ) ? "AllDevices" : ""
                }
            }
            PointHandler {
                acceptedDevices: PointerDevice.UnknownDevice
                onActiveChanged: {
                    label.text = (active == true ) ? "UnknownDevice" : ""
                }
            }
            PointHandler {
                acceptedDevices: PointerDevice.Mouse
                onActiveChanged: {
                    label.text = (active == true ) ? "Mouse " + point.pressure : ""
                }
            }
            PointHandler {
                acceptedDevices: PointerDevice.TouchScreen
                onActiveChanged: {
                    label.text = (active == true ) ? "TouchScreen" : ""
                }
            }
            PointHandler {
                acceptedDevices: PointerDevice.TouchPad
                onActiveChanged: {
                    label.text = (active == true ) ? "TouchPad" : ""
                }
            }
            PointHandler {
                acceptedDevices: PointerDevice.Stylus
                onActiveChanged: {
                    label.text = (active == true ) ? "Stylus" : ""
                }
            }
            PointHandler {
                acceptedDevices: PointerDevice.Airbrush
                onActiveChanged: {
                    label.text = (active == true ) ? "Airbrush" : ""
                }
            }
            PointHandler {
                acceptedDevices: PointerDevice.Puck
                onActiveChanged: {
                    label.text = (active == true ) ? "Puck" : ""
                }
            }
        }
    
    }
    

    Since it didn't work I added a PointHandler for each type to see what happens. Turns out, the stylus triggers the PointHandler for Mouse instead of Stylus. So far I wasn't able to find out how to change this. I hope someone here can give me some pointers on that.

    Regards

    Thorsten

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Larvae
      wrote on last edited by
      #2

      After some try-and-error I found out that QGuiApplication recieves QTabletEvents, but they are not sent to the QQmlApplicationEngine.

      At least installing an eventfilter that sends a message to qDebug when QTabletEvents are encountered reacts this way.

      M 1 Reply Last reply
      0
      • L Larvae

        After some try-and-error I found out that QGuiApplication recieves QTabletEvents, but they are not sent to the QQmlApplicationEngine.

        At least installing an eventfilter that sends a message to qDebug when QTabletEvents are encountered reacts this way.

        M Offline
        M Offline
        Marek
        wrote on last edited by
        #3

        @Larvae Hi
        Have you beeen able to handle stylus input in QML ? Here is some documentation HandlerPoint I'm starting some project which require pressure velocity measurement with hand writing so I wonder how it worked for you.
        Best,
        Marek

        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