How can I embed a custom QWidget in a QWebEngineView or page?

Viewed 1516

I know it is possible to do this with the deprecated class QtWebkit as shown here.

I would like to know if similar work can be done with the new QtWebEngine framework? I could not find a method to create plugin in a web page (QWebEnginePage). Is this related to the plugin technology in Chromium?

I'm currently just exploring the possibility of achieving this with Qt 5.5.

2 Answers

Instead of embedding a QWidget in a QWebEngineView, you can have a QWidget as the child of a QWebEngineView. You may need to fiddle a bit with positions, transparency, and/or stacking order but it is doable. You can coordinate between the QWebEngineView and the native Qt code using a QWebChannel.

I have this working tolerably well on DomTerm (hhtps::/github.com/PerBothner/DomTerm). DomTerm is a rather complicated (partly because it supports lots of configurations including running on other frameworks besides Qt and using iframes instead QWidgets). However, handling the "embedded" QWidgets is relatively simple. If there is interest I can explain more how it works, and the most relevant sections of the code.

Related