Unsolved EventFilter how to ignore mouseMoveEvent when receiving QGestureEvent
-
Hello,
I have a widget and otherWidget that has implemented mouseMoveEvent. I want to catch Gesture events on otherWidget with widget so I use eventFilter. It works well but problem is that I want to ignore mouseMoveEvent when I receive pinchGestureEvent. Let's say otherWidget comes from some library that I can't change code. What is the solution here?
Now I'm getting mouseMoveEvent and QPinchGestureEvent at the same time.Relevant code:
#ifndef WIDGET_H #define WIDGET_H #include <QWidget> class OtherWidget; class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = 0); ~Widget(); protected: bool eventFilter(QObject *watched, QEvent *event); private: OtherWidget *otherWidget; }; class OtherWidget : public QWidget { Q_OBJECT public: OtherWidget(QWidget *parent = 0); ~OtherWidget(); protected: void mouseMoveEvent(QMouseEvent *event); }; #endif // WIDGET_H
#include <QDebug> #include <QMouseEvent> #include <QGestureEvent> Widget::Widget(QWidget *parent) : QWidget(parent) { resize(800, 480); otherWidget = new OtherWidget(this); otherWidget->setGeometry(0, 0, 600, 480); otherWidget->grabGesture(Qt::PinchGesture); otherWidget->setAttribute(Qt::WA_AcceptTouchEvents); otherWidget->installEventFilter(this); } Widget::~Widget() { } bool Widget::eventFilter(QObject *watched, QEvent *event) { if (event->type() == QEvent::Gesture) { QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(event); if(QGesture *tempPinch = gestureEvent->gesture(Qt::PinchGesture)) { QPinchGesture *pinch = static_cast<QPinchGesture *>(tempPinch); qDebug() << pinch->scaleFactor(); } return true; } return QObject::eventFilter(watched, event); } OtherWidget::OtherWidget(QWidget *parent) : QWidget(parent) { } OtherWidget::~OtherWidget() { } void OtherWidget::mouseMoveEvent(QMouseEvent *event) { qDebug() << event->pos(); }
-
@Eligijus said in EventFilter how to ignore mouseMoveEvent when receiving QGestureEvent:
Let's say otherWidget comes from some library that I can't change code. What is the solution here?
How about QObject::installEventFilter? Move your Widget::eventFilter into separate class and then invoke installEventFilter(eventFilterClassObject) on Widget.
-
Refer https://stackoverflow.com/questions/29838086/how-to-disable-mouseevent-during-pinch-zoom for more details.