[Development] QTabletEvent in QML
Rutledge Shawn
Shawn.Rutledge at digia.com
Fri Jul 11 11:58:11 CEST 2014
On 11 Jul 2014, at 10:34 AM, Dean Floyd wrote:
> I have been using the Wacom Cintiq HD 24 Touch for some of my research efforts, and I have tried to use MultiPointTouchArea to handle the touch events, however, this has not lead to a great deal of success. To remedy the situation, I decided to use the Wacom SDK to intercept these events and create my own QML component to do what MultiPointTouchArea usually does, which isn't awfully fast with the signal emitting and all, but sufficiently smooth - I use touch events to control a camera in a 3D scene graph.
Yeah there is QTBUG-39572 for Linux, but if you are using the Wacom SDK I suppose you must be on Windows. We plan to get touch working with Wacom touch devices. I guess your Cintiq is different than the Bamboo relative-touch device (more like a touchpad) which I test with sometimes.
> Now, I would like to draw using the Wacom Pen, and, although I can do this through QWidget::tabletEvent(), I was not able to find a suitable QML component which offers the same tabletEvent() functionality. I see some examples using MouseArea to draw with a pen, but I would like to be able to distinguish between a mouse and a pen device. In other words, I would like to intercept QTabletEvent events within QML. Is there a way to do this? If not, could somebody confirm that this is not possible? I would highly appreciate any help. Thank you.
No there is no support for QTabletEvents in QtQuick 2 yet. I experimented with it during a hackathon last year; the patch which adds support for them is
https://codereview.qt-project.org/#/c/74202/
But after you've got the events in QtQuick, what next? We are also missing public API for creating and manipulating polylines and "ink" objects. You could take the events individually and then try to use Canvas in QML, or implement your own means of using QPainterPath in C++, or use Qt.labs.shapes from
https://codereview.qt-project.org/#/admin/projects/playground/scenegraph
I tried to use the latter approach. It depends whether you want to create vector shapes that can be manipulated later, in small quantities and unfortunately without antialiasing; or to have an art-oriented painting program, in which case you might want to try Krita. It will be ported to Qt 5 eventually. But I'm thinking more about vector drawing...
We don't have polylines (sequences of lines, arcs, Bezier curves etc.) in Qt Quick because we need to figure out how to render them antialiased (maybe even without relying on MSAA) and also animatable. But what would the code look like to apply an animation to one of the control points within a polyline? You wouldn't want every point to be a QObject just to be able to make the occasional binding; and usually the points would come from non-QML data sources like sequences of tablet events, or SVG paths. A JS API for appending points to a path is not enough.
An even stickier problem is how to serialize the Item graph in memory (after you have drawn some new shapes with your tablet) into a QML file. I tried and got a hacky incomplete solution working, but it became evident that QML just isn't designed for that. So if you want to create a vector drawing program in the short term, you need to create your own C++ model anyway. So then you might as well handle the tablet events in C++ too. To integrate with Qt Quick you could wrap the whole drawing renderer into a QQuickItem subclass which implements its own updatePaintNode() to render the vector shapes, or have one of those per shape.
So there are several problems left to solve, and then maybe there's a chance Qt.labs.shapes could be converted into something worth shipping with Qt. Maybe we could even build a complete framework for vector drawing applications. I would like to, because as was just discussed in another thread, GraphicsView is at this point the easier solution to code up this type of use case, but it's older and isn't really the way forward for the future.
More information about the Development
mailing list