Ting
Ting

Reputation: 43

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

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.

Upvotes: 4

Views: 1979

Answers (2)

Per Bothner
Per Bothner

Reputation: 51

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.

Upvotes: 0

Nicholas Smith
Nicholas Smith

Reputation: 11764

I can't find a completely clear answer one way or another, however at the end of the porting guide there's something that would suggest it's no longer possible:

Qt WebEngine renders web pages using Skia and is not using QPainter or Qt for this purpose. The HTML5 standard also now offers much better alternatives that were not available when native controls plugins were introduced in Qt WebKit.

No QPainter would mean that there's no way to draw a QWidget during render.

Upvotes: 4

Related Questions