Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. EventFilter how to ignore mouseMoveEvent when receiving QGestureEvent

EventFilter how to ignore mouseMoveEvent when receiving QGestureEvent

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eligijus
    wrote on last edited by
    #1

    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();
    }
    
    1 Reply Last reply
    0
    • T Offline
      T Offline
      taedium
      wrote on last edited by
      #2

      @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.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Paraddi
        wrote on last edited by
        #3

        Refer https://stackoverflow.com/questions/29838086/how-to-disable-mouseevent-during-pinch-zoom for more details.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved