Recognize arbitrary gestures in Qt5, like GestureArea in Qt4
-
Hi again! I have a custom subclass of QQuickItem that I would like to use in conjunction with MultiPointTouchArea. In particular, I would like to use the gesture recognition provided by MultiPointTouchArea, but have the events be handled by the subclass. Currently my QML is structured like this:
MyCustomItem { id: myItem width: 800; height: 600 MultiPointTouchArea { id: aTouchArea anchors.fill: parent minimumTouchPoints: 1 maximumTouchPoints: 2 onPressed: { console.log("pressed") } onReleased: { console.log("released") } } }
That's all working well so far. However, I am wondering what is the best way to notify the parent of the events (in particular gestures) detected by the MultiPointTouchArea?
Edit: Actually, I am beginning to think that MultiPointTouchArea might not be what I need in the first place. Essentially, my custom widget displays a graphical scene that I want to be able to pan and zoom using swipe and pinch gestures. I thought MultiPointTouchArea was a generic component that you could configure to detect arbitrary gestures, but it seems that is not the case. Really what I want is more like this:
http://blog.qt.io/blog/2010/10/05/getting-in-touch-with-qt-quick-gestures-and-qml/
However, it looks like that information is outdated.
Edit: Changed title (from "Custom QQuickItem, receive events from MultiPointTouchArea") to reflect new information and better match the intent of the question.
-
@kloffy You can have a look at some of its examples:
http://doc.qt.io/qt-5/qtquick-demos-photosurface-example.html
http://doc.qt.io/qt-5/qtquick-touchinteraction-pincharea-flickresize-qml.html -
@p3c0 Thank you! Yes, I did look at them, but it appears that PinchArea unfortunately has its own limitations. If I am not mistaken, in order to get both pan (1 touch) and zoom (2 touch), you have to combine it with Flickable?
The QWidget API for gestures is so nice, it is a shame QQuickItem does not have an equivalent of that:
this->grabGesture(Qt::PanGesture); this->grabGesture(Qt::PinchGesture); // ...
-
@kloffy May be
PinchArea
is only for pinch gestures. I didn't find any such element which supports panning. Qt 4 had GestureArea which supported pan, zoom, swipe, tap etc.. but it seems they discontinued it. -
@p3c0 Yes, seems like it has been removed, which is a shame. I suppose I may have to install an event filter and roll my own solution. Looking at the amount of code that deals with gesture recognition in QWidget, this is a bit of a scary prospect, though. :(
-
@kloffy You can try requesting such feature at http://bugreports.qt.io/. Or try asking here: http://lists.qt-project.org/mailman/listinfo/interest. May be there's some other alternative I'm too not aware of.