How to capture mouse events in webengineview



  • I tried to implement mouseMoveEvent in WebEngineView class.

    But after reading from the internet (https://bugreports.qt.io/browse/QTBUG-43602) got to know that QWebEngineView doesn't capture mouseEvents and it's a limitation.

    Also suggestion was given as to monitor QObject::childEvent of the QWebEngineView and install an event filter when a new child QWidget appear during page loads

    how do I do this?



  • Had the same issue. Even the topic is quite old I publish here my solution for anyone that might have this issue now.

    Note that I need to track the mouse, so I call setMouseTracking(true); in the constructor.

    class CustomWebEngineView: public QWebEngineView {
    public:
        explicit CustomWebEngineView(QWidget *parent = nullptr): QWebEngineView(parent) {
            QApplication::instance()->installEventFilter(this);
            setMouseTracking(true);
        }
    
    protected:
        bool eventFilter(QObject *object, QEvent *event) {
            if (object->parent() == this && event->type() == QEvent::MouseMove) {
                mouseMoveEvent(static_cast<QMouseEvent *>(event));
            }
    
            return false;
        }
    };
    
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.