From 3c3ee5f15038e8fea3e634a6b08188db7ac8f856 Mon Sep 17 00:00:00 2001 From: romibi Date: Fri, 10 Jun 2016 11:07:19 +0200 Subject: [PATCH] Fix WebPreview not updating when using QtWebEngine (cherry picked from commit 101848c405a81911bf0404b35c0046664c1d2303) --- src/qtui/webpreviewitem.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/qtui/webpreviewitem.cpp b/src/qtui/webpreviewitem.cpp index ebee5eac..aafe5dce 100644 --- a/src/qtui/webpreviewitem.cpp +++ b/src/qtui/webpreviewitem.cpp @@ -33,14 +33,39 @@ #include #include + +#ifdef HAVE_WEBENGINE +// QGraphicsProxyWidget does not stay synced with QWebEngineView, therefore we modify QWebEngineView +// and manually trigger an update of the proxyItem on UpdateRequest Event. See: http://stackoverflow.com/a/30920209 +// and http://lists.qt-project.org/pipermail/development/2016-March/025280.html (At least in Qt5.6) +class CustomWebView : public QWebEngineView { + +private: + QGraphicsProxyWidget *proxyItem; +public: + CustomWebView(QGraphicsProxyWidget *pItem) { + proxyItem = pItem; + } + bool event(QEvent *event) { + if (event->type() == QEvent::UpdateRequest) + { + proxyItem->update(); + } + + return QWebEngineView::event(event); + } +}; +#endif + WebPreviewItem::WebPreviewItem(const QUrl &url) : QGraphicsItem(0), // needs to be a top level item as we otherwise cannot guarantee that it's on top of other chatlines _boundingRect(0, 0, 400, 300) { qreal frameWidth = 5; + QGraphicsProxyWidget *proxyItem = new QGraphicsProxyWidget(this); #ifdef HAVE_WEBENGINE - QWebEngineView *webView = new QWebEngineView; + QWebEngineView *webView = new CustomWebView(proxyItem); webView->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false); #elif defined HAVE_WEBKIT QWebView *webView = new QWebView; @@ -49,7 +74,6 @@ WebPreviewItem::WebPreviewItem(const QUrl &url) webView->load(url); webView->setDisabled(true); webView->resize(1000, 750); - QGraphicsProxyWidget *proxyItem = new QGraphicsProxyWidget(this); proxyItem->setWidget(webView); proxyItem->setAcceptHoverEvents(false); -- 2.20.1