如何在QML中禁用触摸事件?

时间:2017-06-01 02:18:49

标签: qt qml qtquick2

------------------------更新---------------------- -

现在我已经阻止了光标的移动,但现在我该如何禁用触摸事件?

在我的应用程序中,如果我触摸我的应用程序,我不希望光标移动到我触摸的位置,所以我必须禁用所有触摸事件,我使用eventFileter,但它不能正常工作好。

主窗口:

QQuickWindow* win = qobject_cast<QQuickWindow *>(engine.rootObjects()[0]);
//win->showMaximized();
gHwnd = (HWND)win->winId();
DisableTouchFeedback(gHwnd);
pObject->installEventFilter(new QTouchEventFilter);      

事件过滤器:

class QTouchEventFilter: public QObject
{
    Q_OBJECT
public:

    QTouchEventFilter(QObject *parent = 0) : QObject(parent)
    {
    }

    protected:

    bool eventFilter(QObject * p_obj, QEvent * p_event)
    {
        if (p_event->type() == QEvent::FocusIn ||
                p_event->type() ==   QEvent::CursorChange ||
                p_event->type() == QEvent::TouchBegin ||
                p_event->type() == QEvent::TouchUpdate ||
                p_event->type() == QEvent::TouchEnd ||
                p_event->type() == QEvent::TouchCancel||
                p_event->type() == QEvent::MouseButtonDblClick||
                p_event->type() == QEvent::MouseButtonPress ||
                p_event->type() == QEvent::MouseButtonRelease ||
                p_event->type() == QEvent::MouseMove ||
                p_event->type() == QEvent::MouseTrackingChange||
                p_event->type() == QEvent::Gesture
                )

        {
            qInfo()<<"----------------------"<<p_event->type();
            p_event->ignore();
            return true;
        }
        qInfo()<<"+++++++++++++++++++"<<p_event->type();
        return false;
    }
};

有没有像在qml中设置acceptTouchEvents(false)的方法?

0 个答案:

没有答案