代码之家  ›  专栏  ›  技术社区  ›  Mr. Developer

SwipeView在释放事件QML-QT时检测

  •  1
  • Mr. Developer  · 技术社区  · 7 年前

    我正在用SwipeView做一个应用程序,但当手指从屏幕上移开时,我还需要检测最小滑动。

    有什么办法吗?或者,如果我检测到手指何时离开应用程序窗口上的屏幕。

    2 回复  |  直到 7 年前
        1
  •  0
  •   derM - not here for BOT dreams    7 年前

    在我学习QML的一开始,我遇到了一个类似的问题:我想在不干扰应用程序其余部分的情况下检测鼠标事件。

    正当 解决方案,也许是这样 非常糟糕的风格 黑客 但它是有效的,可能会帮助你。

    监视他们的鼠标事件 . 在这个 Item childMouseEventFilter 通过如下方式重新实现:

    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);
    }
    


    如果在触摸设备上使用,您可能会对两个事件感兴趣:

    检查 QEvent.type() 妥善处理。有趣的类型有:

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

    更多信息: http://doc.qt.io/qt-5/qevent.html#Type-enum

        2
  •  0
  •   yekmen    7 年前

    我想应用程序的最佳方法是使用具有水平方向的ListView,委托是“页面”,现在您可以检测到

    ListView继承自Flickable,现在可以检测鼠标事件。 http://doc.qt.io/qt-5/qml-qtquick-listview.html