1

I am creating a simple drawing application and would like my app handle pen (stylus like Apple Pencil) input. The app is written in Qml/Qt Quick. I know that when using QWidgets you can handle tablet events using QTabletEvent (example), but how I can handle pen input in QML (using MouseArea does not work and I had no luck with PointHandler either). Does anyone know if it is possible to handle Pen input in Qt Quick?

reckless
  • 741
  • 12
  • 53

2 Answers2

1

Try using QML TapHandler: https://doc.qt.io/qt-5/qml-qtquick-taphandler.html

acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
Albertino80
  • 1,063
  • 7
  • 21
  • Isn't `TapHandler` the same as `PointHandler`. I have tried this `PointHandler { id: handler acceptedDevices: PointerDevice.TouchScreen | PointerDevice.Stylus }` – reckless Dec 04 '19 at 17:48
  • 2
    Maybe there is something not working properly. I suggest to study this: https://github.com/dragly/hello-remarkable here I can see a `class TabletWindow : public QQuickWindow` that handles the `tabletEvent` and sends to a child `class PaintedCanvas : public QQuickPaintedItem` – Albertino80 Dec 04 '19 at 22:28
  • That's a very useful example thanks. It seems like I need to subclass a custom `QQuickWindow` and from there handle the tablet events. – reckless Dec 04 '19 at 23:41
  • 2
    It seems like the Qt developers forgot to implement the handler for tablet events (there is TODO in this [code](https://code.woboq.org/qt5/qtdeclarative/src/quick/items/qquickwindow.cpp.html#2374)) – reckless Dec 05 '19 at 00:53
  • 2
    5.15 is releasing soon and will finally have TabletEvents propagating around QML properly. So the Handlers can actually finally restrict to Tablet devices. – Zanny May 11 '20 at 04:11
1

Looking at the example linked by @Albertino80 , I subclassed QQuickWindow which inherits QWindow and hence is able to receive tablet events (void tabletEvent(QTabletEvent* event). These events can then be used to emit appropriate signals that can be propapated to other QObjects. This method works ok, but it has the problem that event coordinates are not local to the item where they are consumed, instead one has to manually recalculate the position of each event by mapping the coordinates to the custom window.

reckless
  • 741
  • 12
  • 53