c++ - iOS 上的 QGestures

标签 c++ ios qt gesture

我正在尝试像这样在 ios 上使用 qt 手势:

#ifndef SWIPESTACKWIDGET_H
#define SWIPESTACKWIDGET_H

#include <QStackedWidget>
#include <QSwipeGesture>

class SwipeStackWidget : public QStackedWidget
{
Q_OBJECT
public:
    explicit SwipeStackWidget(QWidget *parent = 0);

    bool event(QEvent *event);
    bool gestureEvent(QGestureEvent *event);
    void swipeTriggered(QSwipeGesture *gesture);
signals:

public slots:

};

#endif // SWIPESTACKWIDGET_H

#include "swipestackwidget.h"

#include <QDebug>

SwipeStackWidget::SwipeStackWidget(QWidget *parent) :
    QStackedWidget(parent)
{
    setAttribute(Qt::WA_AcceptTouchEvents);
    grabGesture(Qt::TapGesture);
    grabGesture(Qt::TapAndHoldGesture);
    grabGesture(Qt::PanGesture);
    grabGesture(Qt::PinchGesture);
    grabGesture(Qt::SwipeGesture);
}

bool SwipeStackWidget::event(QEvent *event)
{
    if (event->type() == QEvent::Gesture)
        return gestureEvent(static_cast<QGestureEvent*>(event));
    return QWidget::event(event);
}

bool SwipeStackWidget::gestureEvent(QGestureEvent *event)
{
    qDebug() << "gestureEvent():" << event->gestures().size();
    if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
        swipeTriggered(static_cast<QSwipeGesture *>(swipe));
    if (QGesture *pan = event->gesture(Qt::PanGesture))
        qDebug() << "Pan";
    if (QGesture *pinch = event->gesture(Qt::PinchGesture))
        qDebug() << "Pinch";
    if (QGesture *pinch = event->gesture(Qt::TapGesture))
        qDebug() << "Tap";
    if (QGesture *pinch = event->gesture(Qt::TapAndHoldGesture))
        qDebug() << "Tapandhold";
    return true;
}

void SwipeStackWidget::swipeTriggered(QSwipeGesture *gesture)
{
    qDebug() << "swipeTriggered()";
    if (gesture->state() == Qt::GestureFinished) {
        if (gesture->horizontalDirection() == QSwipeGesture::Left) {
            qDebug() << "swipeTriggered(): swipe to previous";
            setCurrentIndex( std::max( 0, currentIndex()-1) );
        } else if (gesture->horizontalDirection() == QSwipeGesture::Right) {
            qDebug() << "swipeTriggered(): swipe to next";
            setCurrentIndex( std::min( count()-1, currentIndex()+1) );
        }
        update();
    }
}

我可以编译代码并在iphone上执行。我确实可靠地接收到制表符手势和 tabAndHold。 Pan 和 Pimch 有时确实会发生。滑动是个大问题:

  1. 它只出现在 3 个手指上
  2. 仅在向底部或向右滑动时出现
  3. 只是偶尔出现
  4. 滑动到底部有时会被识别为下一个,有时会被识别为向左滑动

有没有人有在 ios 上使用 QGestures 的经验并且可以帮助我?

我的测试类直接在主窗口中使用,我也在主窗口中使用 grabGestures 命令,但我不在那里处理手势。

最佳答案

我可以确认它需要三个手指。我在 iPad 上使用 PyQt Qt5.3.1 进行了测试。 (此外,平移需要两根手指。)

我怀疑 Qt 是那样设计的,所以跨平台是一样的(选择 Ubuntu 上常见的手指计数,因为 Canonical 可能贡献了很多代码?)

在 iOS SDK 中,一些基本手势类可针对手指数量和方向进行配置。 Read more.这是唯一相关的,因为它意味着 Qt 可以轻松配置 Qt 订阅的原生手势,如果他们订阅原生手势的话。您可以查看 Qt 的代码(针对 iOS 平台抽象 QPA 和他们的其他手势相关代码)来验证他们是否设计了 3 个手指进行滑动(这不是错误。)

但是iOS平台上的三指向上滑动物理手势应该是“隐藏应用程序并显示系统托盘”的意思吧? (这是我的经验,我无法引用 iOS HIG,也不知道 App Store 的要求。)如果是这样,那么应用程序应该订阅 Qt 的滑动手势并遵循指南。

但是您也可以在 Qt 中为单指滑动实现识别器吗?

关于c++ - iOS 上的 QGestures,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24725088/

相关文章:

c++ - 试图在类中设置对 const 引用成员的引用

c++ - .NET C# 调用 C++ native Win32 DLL 时出现问题

C++ 从两个线程访问 Int 变量。线程安全?

ios - Xcode Playground : new pages cannot refer to source files

c++ - 抑制代码内部的 "unused parameter"警告

c++ - 如何在 Qt 样式表中创建阴影?

c++ - 在 C++ 中从 Python 模拟导入功能

c++ - 管道通信 C++

iphone - 自定义委托(delegate)仅在从 UIButton 选择器 ARC 保留问题直接调用时才有效

iOS : Icon occasionally fails to transfer to device