c++qtqwebviewqtwebengine

How to send artificial QKeyEvent to QWebEngineView?


Context: I'm creating a small web browser with a custom on-screen keyboard.

It was working almost fine with Qt WebKit (QWeb* classes) but there were crashes attributed to bugs in WebKit... which won't be fixed after Qt 5.4.0 since they're moving to Qt WebEngine.

So I decided to move the stuff to Qt WebEngine (QWebEngine* classes), following the short webkit->webengine transition guide. Following the caveat section on QWebElement, I have worked my way around showing/hiding the on-screen keyboard (which now requires running async. JS code). But I'm scratching my head on how to send artificial key events to the web page.

I have tried the some stuff:

Thanks,


Solution

  • I guess the only possibility to achieve this right now would be to make use of QAction to send an event to the WebView by using for example something like that:

    connect( this , SIGNAL( keyPressed( int ) ) , &m_webview , SLOT( handleKey( int ) ) );
    

    I suppose the functionality will be added in Qt 5.5.1 as you can see below:

    https://codereview.qt-project.org/#/c/104901/