Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    How to capture mouse events in webengineview

    General and Desktop
    webengineview
    2
    2
    3947
    Loading More Posts
    • 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
      ejos last edited by ejos

      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?

      1 Reply Last reply Reply Quote 0
      • cm0x4d
        cm0x4d last edited by

        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;
            }
        };
        
        
        1 Reply Last reply Reply Quote 2
        • First post
          Last post