Support for gestures like swiping in PyQt5

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Support for gestures like swiping in PyQt5

Frans Fürst
I'm trying to make a PyQt5 application for Android react to swipe gestures (in order to let the user swipe through pictures). I didn't find much documentation about this (neither for C++ nor Python) but I came up with an approach which looks plausible to me:

class MyViewer(QtWidgets.QLabel):
    def __init__(self, parent=None):
        super().__init__(parent=parent)
        self.grabGesture(QtCore.Qt.SwipeGesture)

    def event(self, event):
        if event.type() == QtCore.QEvent.Gesture:  # <= this won't happen
            print("Hello event!")
        return super().event(event)
The app runs without errors but the event() method does not receive any events that look like gestures (at least on Android an Linux, but I don't know if I have to expect gestures work on Linux at all).

I've posted a question on StackOverflow, but with no answers yet: https://stackoverflow.com/questions/66304454/receive-gestures-in-pyqt5-for-android

Are there any known issues with gestures on Android with PyQt5?
Did I forget something important? Or am I on a totally wrong path here?

Reply | Threaded
Open this post in threaded view
|

Re: Support for gestures like swiping in PyQt5

Giuseppe Corbelli
On 2/24/21 9:40 AM, Frans Fürst wrote:

> I'm trying to make a PyQt5 application for Android react to swipe
> gestures (in order to let the user swipe through pictures). I didn't
> find much documentation about this (neither for C++ nor Python) but I
> came up with an approach which looks plausible to me:
>
> |class MyViewer(QtWidgets.QLabel): def __init__(self, parent=None):
> super().__init__(parent=parent) self.grabGesture(QtCore.Qt.SwipeGesture)
> def event(self, event): if event.type() == QtCore.QEvent.Gesture: # <=
> this won't happen print("Hello event!") return super().event(event)|
>
> The app runs without errors but the event() method does not receive any
> events that look like gestures (at least on Android an Linux, but I
> don't know if I have to expect gestures work on Linux at all).
>
> I've posted a question on StackOverflow, but with no answers yet:
> https://stackoverflow.com/questions/66304454/receive-gestures-in-pyqt5-for-android 
> <https://stackoverflow.com/questions/66304454/receive-gestures-in-pyqt5-for-android>
>
> Are there any known issues with gestures on Android with PyQt5?
> Did I forget something important? Or am I on a totally wrong path here?

As far as I can tell you're on the right path.
I assume you've started from
https://doc.qt.io/qt-5/gestures-overview.html

On a desktop platform it does not likely work out of the box:
https://stackoverflow.com/questions/49287314/qgestureevent-for-mouse

--
Giuseppe Corbelli