How to use PointerDevice
larkei15 last edited by
I am trying to detect when a stylus (such as a surface pen or apple pencil) is being used for input in my application using only QML. I see there is a PointerDevice type (https://doc.qt.io/qt-5/qml-qtquick-pointerdevice.html) that I can get the device type from. I can access the PointerDevice from a PointerEvent, but the problem is the only place in the documentation that seems to show how to get a PointerEvent is from the tapped event of TapHandler. Even then, the documentation doesn't explicitly say that the event property is a PointerEvent, it just says it is an object, however, in the example code it shows there being a device property of this event. Anyway, I cannot use the TapHandler because I want to detect the device type without releasing and long presses don't emit the PointerEvent with the longPressed signal.
The workaround that I tried is by making a PointHandler that only accepts PointerDevice.Pen and when I handle the pressed signal in a MouseArea, I check to see if the PointHandler is active. It does detect when the PointHandler is active with not specified pointer type, but it's never activating when I force it to look for only PointerDevice.Pen. I am having a lot of trouble debugging this because I have no way of seeing what device type it is detecting the stylus as, because the stylus doesn't activate the PointHandler when I force it to accept only PointerDevice.Finger input.
It is extremely frustrating that the PointerEvent could supply me with the functionality to do exactly what I need, but there seems to be no way to access it within the limited documentation.
Any help would be greatly appreciated.