简体   繁体   English

Qt Android手势问题

[英]Qt Android gesture issue

Upon writing a simple Android application in Qt, I encountered an uncomfortable dilemma: 在Qt中编写一个简单的Android应用程序时,我遇到了一个不舒服的难题:

I have a subclass of QWidget called PlotView, and have reimplemented the event-function from it: 我有一个名为PlotView的QWidget子类,并从中重新实现了事件功能:

bool PlotView::event(QEvent *event){

    if(event->type() == QEvent::Gesture){
        emit gestureEvent(static_cast<QGestureEvent*>(event));
        return true;
    }
    return QWidget::event(event); \\Line A

}

Also I have the following lines in the class constructor: 我在类构造函数中也有以下几行:

this->grabGesture(Qt::SwipeGesture);
this->grabGesture(Qt::PanGesture);
this->grabGesture(Qt::PinchGesture);
this->setAttribute(Qt::WA_AcceptTouchEvents);

What I find very peculiar is that when running the application like this, it does not recognize any gestures. 我发现非常奇怪的是,当像这样运行应用程序时,它无法识别任何手势。 However, when removing the last line of the function (Line A above), the gestures are suddenly recognized, but the widget is not painted. 但是,当删除函数的最后一行(上面的A行)时,会突然识别出手势,但未绘制窗口小部件。

Some specs: I am currently running Qt 5.2.0, compiling on a Samsung Galaxy Note 10.1 GT-N8010 running Android 4.1.2. 一些规格:我目前正在运行Qt 5.2.0,在运行Android 4.1.2的Samsung Galaxy Note 10.1 GT-N8010上进行编译。

Does anyone have any suggestions to how I could make this run with both the widget being painted and gesture recognition? 有人对我如何在绘制小部件和手势识别时如何进行运行有任何建议吗?

It seems adding the lines 似乎增加了界限

this->grabGesture(Qt::SwipeGesture);
this->grabGesture(Qt::PanGesture);
this->grabGesture(Qt::PinchGesture);
this->setAttribute(Qt::WA_AcceptTouchEvents);

to the parent class constructor fixed the problem. 到父类构造函数解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM