问题
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.
回答1:
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:
- QTouchEvent
- QMouseEvent
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.
回答2:
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
来源:https://stackoverflow.com/questions/46152927/swipeview-detect-on-release-event-qml-qt