QtWebEngine rendering native Qt widgets in DOM?

妖精的绣舞 提交于 2019-12-13 02:26:32

问题


I am looking to rewrite a Qt application in HTML, and have QtWebEngine to render it for me. I fully understand that a HTML page will display and run in QtWebEngine.

However, one thing I am really interested in, and am unable to find documentation on - apologies if I'm looking in the wrong places - is to know if QtWebEngine allows for elements of the DOM to be "swapped" for native Qt widgets. For example, could a <div id="myWidget"> actually be a QOpenGLWidget? Is this completely nonsensical?

e.g I'd love to be able to do:

<body>
<h1>Example</h1>
<div id="myWidget">
</div>
<p>Some text</p>
</body>

and magically have my QOpenGLWidget rendered in the DOM in the place of "myWidget". My HTML could only ever be rendered by QtWebEngine, not necessarily by other browsers, so if there is a solution that means it wouldn't work in Chrome/Firefox/IE that is absolutely fine with me.

...Or would I have to use javascript running in the QtWebEngine instance to find out the position of "myWidget" and draw the QOpenGLWidget pixel data in that position myself? I really don't want to go down this route as it does not allow for things like HTML dialogs over the top of "myWidget".

I'd really appreciate any info here. An example (if this is even possible) would be fantastic. Many thanks in advance.


回答1:


Solution for QtWebKit:

You will need to subclass QWebPluginFactory and create your widget in its create method. Then you could embed your widgets in HTML with <object> tag:

<object type="application/x-qt-plugin" name="myWdget" classid="QOpenGLWidget">
</object>

See example here

And another example here

...seems not valid anymore for new QtWebEngine.



来源:https://stackoverflow.com/questions/28661280/qtwebengine-rendering-native-qt-widgets-in-dom

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!