如何将人工QKeyEvent发送到QWebEngineView? [英] How to send artificial QKeyEvent to QWebEngineView?

查看:128
本文介绍了如何将人工QKeyEvent发送到QWebEngineView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:我正在使用自定义的屏幕键盘创建一个小型Web浏览器。

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

与Qt WebKit配合使用几乎可以正常工作( QWeb * 类),但是由于WebKit中的错误而导致崩溃...由于在Qt 5.4.0之后转移到Qt WebEngine,因此无法修复。

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.

因此,我决定按照简短的webkit-> webengine过渡指南,将内容移至Qt WebEngine( QWebEngine * 类)。
QWebElement 的警告部分之后,我设法显示/隐藏屏幕键盘(现在需要运行异步JS代码)。
但是我在如何将人工按键事件发送到网页上抓狂。

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.

我尝试了一些东西:


  • QCoreApplication :: postEvent(m_webview,event)不起作用什么,当它与旧的 QWeb 一起工作时;

  • 可以通过运行JavaScript发送密钥,但是我发现这太脏了

  • QCoreApplication::postEvent(m_webview, event) doesn't do anything, when it was working with the old QWeb stuff;
  • It's possible to send keys by running JavaScript but I find this too dirty

谢谢

推荐答案

我想现在唯一实现此目的的可能性是
使用 QAction 通过使用例如以下内容将事件发送到WebView: / p>

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 ) ) );






我想该功能将在Qt 5.5中添加.1,如下所示:


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

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

这篇关于如何将人工QKeyEvent发送到QWebEngineView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆