Disabling zoom in QWebEngine under Qt 5.9.4
-
We are running a fullscreen QWebEngine app compiled in Qt 5.9.4 for aarch64 platform with wayland+weston. Some of the devices running the app are touchscreens, which allow to interact with displayed pages (mostly custom made html templates). On the touchscreens, it's possible to zoom the page by using the pinch gesture, we would like to disable any zooming at all because all of the displayed content is made to fit fullscreen perfectly.
I have tried many different ways without luck, the only way that works is using runJavaScript to overwrite the meta viewport tag, but I'm not really a fan of this solution as it may interfere with pages actually using some custom viewport settings.
I have tried using setZoomFactor (which didn't work at all), adding --disable-pinch to the startup command which also didn't work, I also wanted to catch the pinch gesture event by installing an event filter on the QWebPage->focusProxy(), but it only returns basic touch events (TouchBegin,TouchEnd,TouchUpdate etc) and I don't know how to determine if it's a zooming event or not.
We cannot change the Qt version. Is it possible in any other way than running the javascript?
-
Hello hanzoc,
we did the following hack, it worked fine with Qt 5.9:
src/core/render_widget_host_view_qt.cpp | 3 +++
1 file changed, 3 insertions(+)diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp
index 2326dbdf..9fc68819 100644
--- a/src/core/render_widget_host_view_qt.cpp
+++ b/src/core/render_widget_host_view_qt.cpp
@@ -288,6 +288,9 @@ RenderWidgetHostViewQt::RenderWidgetHostViewQt(content::RenderWidgetHost *widget
}
#endif // QT_NO_ACCESSIBILITY- // Hack: Disable pinch gesture
- m_gestureProvider.SetMultiTouchZoomSupportEnabled(false);
- if (GetTextInputManager())
GetTextInputManager()->AddObserver(this);
--
2.19.2However, in Qt 5.12, this hack is not required, instead QtWebEngine understands:
export QTWEBENGINE_CHROMIUM_FLAGS=--disable-pinch
<start your application>