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.
문제
Upon writing a simple Android application in Qt, I encountered an uncomfortable dilemma:
I have a subclass of QWidget called PlotView, and have reimplemented the event-function from it:
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.
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.
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.