SwipeView检测释放事件QML-QT [英] SwipeView detect on release event QML - QT

查看:435
本文介绍了SwipeView检测释放事件QML-QT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检测用户何时从屏幕上松开手指。
我正在使用SwipeView开发应用程序,但是当手指从屏幕上移开时,我还需要检测最小滑动。

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.

有一种方法可以这个 ?或者,也许我检测到手指何时离开ApplicatioWindow上的屏幕。
谢谢。

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

推荐答案

在QML学习的初期,我遇到了类似的问题:我想检测鼠标事件,而不会干扰应用程序的其余部分。

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.

这可能不是 right 解决方案,也许是非常糟糕的风格 hacky ,但是它可以工作,并且可能会对您有所帮助。

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

这个想法是构建一个C ++项,我将它用作父项我要监视其鼠标事件的所有节点的节点。在此项目中,我插入了 childMouseEventFilter ,方法如下:

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

检查 QEvent.type ()进行适当处理。有趣的类型是:

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

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

更多: 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.

这篇关于SwipeView检测释放事件QML-QT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆