QtWebEngine rendering native Qt widgets in the DOM?

I want to rewrite a Qt application in HTML and provide QtWebEngine for rendering it. I fully understand that the HTML page will be displayed and run in QtWebEngine.

However, I’m very interested, and I can’t find the documentation - apologies if I look in the wrong place - to know if QtWebEngine allows DOM elements to be "replaced" with native Qt widgets. For example, can <div id="myWidget"> be a QOpenGLWidget? Is this completely pointless?

For example, I would like to be able to:

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

and magically, so that my QOpenGLWidget appears in the DOM instead of "myWidget". My HTML code could only be displayed by QtWebEngine, not necessarily by other browsers, so if there is a solution that means it will not work in Chrome / Firefox / IE, this is absolutely normal with me.

... Or will I need to use javascript running in a QtWebEngine instance to find out the position of "myWidget" and how to draw the QOpenGLWidget pixel data at that position? I really do not want to go this way, because it does not allow you to use things like HTML dialogs at the top of "myWidget".

I would really appreciate any information here. An example (if possible) would be fantastic. Thank you very much in advance.

+1
source share
1 answer

Solution for QtWebKit :

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

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

See an example here.

And another example here

... seems to be no longer valid for new QtWebEngine .

+2
source

Source: https://habr.com/ru/post/986194/


All Articles