One Finger Swipe / Gestures
-
Hello,
so, after spending hours trying to make sense of the documentation, various forums, the mailing list and whatever else google serviced me, it seems like one finger gestures are not enabled in Qt by default, which is something I do not understand.
For one: The
Qt::SwipeGesture
as part of theQGestureRecognizer
registers with three fingers instead of one. It is used in the Gesture example (here) for the current Qt Version (as time of writing: Qt 5.5) and in the documentation it is described - or at least pictured - with one finger (see here). Which, to be fair, should be expected. 95% of my interaction with tablets and smartphones is with one finger.
It is also not mentioned anywhere how this gesture needs three fingers instead of one, leading to tons of confused posts on stackoverflow, for instance, about how Swipes don't work, only to then recognize that they need three fingers (for instance: here - this is from september 2014!).This seems to be known already, there were bugreports about it and even in the mailing list I found entries, one is especially notable: click me. It's from nearly a year ago (February 2015):
"There are also long-standing bugs in the gesture framework, as well as limitations of its design. (Try qtbase/examples/widgets/gestures/imagegestures: you will see that two fingers are required to do anything, because we have unsolved problems preventing us from enabling single-finger panning or swiping by default; and there’s still a bug with pinch zooming too.) But usually you are better off writing multi-touch applications with Qt Quick anyway. It doesn’t make any use of QGestureEvents so far."
To add to that confusion, there's the
QNativeGestureEvent
class documented (here), but there's not documentation or no examples about how to use it and it's incompatible withQWidget::grabGesture()
, so if I expected to find platform-native gestures (as one finger swipe) in there, I was disappointed as well.The documentation then mentioned the possibility of writing your own GestureRecognizer to be able to handle gestures other than the default ones, which is fair, although I find it to be overblown for a simple one finger swipe gesture. As I said, this seems to be the most standard gesture in mobile development and I'm confused as to why it's not supported by Qt.
As such, I'm left dumbfounded:
- Is there really no native Qt way of getting one-finger gestures? Why? Am I just blind? Is there a plan to enable them in the near future? (I haven't found anything yet in the upcoming 5.6 and 5.7 versions)
- What are
QNativeGestureEvents
? Do they even apply to my situation? Can I access them in a way I haven't found yet? - Why does the documentation not mention the specifics of
Qt::SwipeGesture
? - Is there a default code to add one finger swipe gestures to a self written GestureRecognizer? I'm obviously not the first person to stumble over the issue, anything I can look up and/or copy?
The only basic answer I seem to have found is "use QtQuick and QML instead of flat c++ qt if you want to do mobile development", which is somewhat unsatisfactory.
-
To be short in answer:
Think about single finger swype gesture as the same as simple mouse move. By default Qt maps touch events to mouse.If one needs scrolling functionality by single finger, then wrap anything with
QScrollArea
andQScroller
:QScroller::grabGesture(any_Scrolable_Widget->viewport(), QScroller::LeftMouseButtonGesture);
I wrote more about it in a blog:
http://nootka-app.blogspot.com/2015/11/story-of-porting-complex-qt-application_18.htmlThe only basic answer I seem to have found is "use QtQuick and QML instead of flat c++ qt if you want to do mobile development", which is somewhat unsatisfactory.
In my case, (I hope such cases are much, much more) it is more constructive to write a few mobile-capable-widgets more, also learn about styling more, than porting complex c++/QtWidgets app (already tested and quite robust) to QML.
-
Thanks for your answer, SeeLook.
Think about single finger swype gesture as the same as simple mouse move. By default Qt maps touch events to mouse.
This is extremely weird to me. Interaction on a mobile touch device differs from interaction with mouse/keyboard on a desktop / laptop. In fact, I'd expect multiplatform apps to accomodate that with different control schemes - one for mouse, one for touch. I don't really see a reason for handling things like this: One finger gestures and mouse movements are in 95% of all contexts completely different things.
I'm sure there are reasons for handling things like they are handled, I just don't see them. Anyone able to enlighten me?
-
As I remember, I thought similarly to You before I got hands wet in adopting to mobile platform.
I thought: 'I have mouse interaction and now I need to add touch interaction'But in practice, I changed my mind.
95% of touch interaction was already done by mapping touch to mouse. So it is obvious that allQPushButton
-s, check boxes and almost all click-able widgets just works with touch.
If You like, see screens of my app:
https://www.youtube.com/watch?v=dUX6ThWMTi8
At the beginning of the video all is managed through touch events to distinguish behavior from mouse , but at time about 1:12 there is swipe gesture started from top left corner (menu) and this is ordinary mousePress/mouseMove/mouseRelease.I tried to understand why...
and I answered myself that, our brain is more flexible than API :-) (so far)Anyway, if one prefer to have touch only interaction for mobile it is configurable by:
qApp->setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents); qApp->setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents); // true or false as the second argument to switch it on/off
-
Still same shit even in Qt5.8.0 Beta.
There are tons of bugs in bugreports.qt.io still waiting to get resolved more than 6 years.
Bullshit
Their bugreport departmant drive me crazy.
Somebody has to punch their faces.
I've been through this crap a couple of times before.
Nobody care. Damn. -
@MrKozmon please keep the commenting civil.
There are bugs that are not being looked at due to lack of people in different areas.
If you have bugs that you would like to see fixed, the best place is bugreports and codereview. Providing help there is appreciated. Ideas on how to fix things help, and even better if you can fix a bug an commit it to the codebase.
-
@Qt-embedded-developer I'm sorry but I don't remember well...
It was long time ago and I ported my app to QML since then.
In QML it is much much easier to achieve such things.
I tried to dig the oldQtWidgets
code but I've not found where it was yet.