1

I need to detect when the user release the finger from the screen. I'm doing an application with SwipeView, but when the finger remove from the screen I need to detect the minimum slide also.

There is a method for this ? Or maybe if I detect when the finger leave the screen on the ApplicatioWindow. Thanks.

Mr. Developer
  • 3,295
  • 7
  • 43
  • 110

2 Answers2

0

I guess that the best method for your application is to use a ListView with horizontal orientation and delegate is a "page" and now you can detect

ListView is inherited from Flickable and you can detect the mouse event now. http://doc.qt.io/qt-5/qml-qtquick-listview.html

yekmen
  • 127
  • 9
  • I didn't ask the best mode to slide a content...mi question ask how to do detect a release touch event from swipeview – Mr. Developer Sep 11 '17 at 12:29
  • With this method you can detect your touch release with this signal : http://doc.qt.io/qt-5/qml-qtquick-flickable.html#movementEnded-signal – yekmen Sep 11 '17 at 12:30
  • I don't think that you can detect the mouse release with SwipeView, this is why I propose to you another solution ... – yekmen Sep 11 '17 at 12:35
  • thank you, but this don't answer my question...otherwise I would use Flickable controller. I need to use SwipeView – Mr. Developer Sep 11 '17 at 12:39
0

In the very beginning of my QML learning I had a similar problem: I wanted to detect mouse events without interfering with the rest of the application.

It might not be the right solution, maybe it is very bad style or hacky but it works, and might help you.

The idea is to build a C++ item that I use somewhere as parent node to all nodes I want to spy on their mouse events. In this Item I hook in the childMouseEventFilter by reimplementing it as follows:

bool MouseEventListener::childMouseEventFilter(QQuickItem *item, QEvent *event)
{
    emit mouseEventHappend();
    event->ignore(); // Don't know if that is right. I think I should not have it here.
    return QQuickItem::childMouseEventFilter(item, event);
}

In this solution I don't check what kind of mouse event I got, but you might, and emit different signals depending on it.
If used on a touch device, there will be two events you might be interested in:

Check the QEvent.type() to handle them appropriately. The interesting types are:

  • QEvent::MouseButtonPress
  • QEvent::MouseButtonRelease
  • QEvent::MouseMove
  • QEvent::TouchBegin
  • QEvent::TouchCancel
  • QEvent::TouchEnd
  • QEvent::TouchUpdate

More: http://doc.qt.io/qt-5/qevent.html#Type-enum

Especially the touch events offer nice information about the start of the gesture and the last leg of the finger movement, that might be of interest to you.