문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top