且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何设置 WebView 内容比例(qml QT 5.2)

更新时间:2023-11-13 10:41:58

要实现与您的问题 图 2 中相同的缩放,您必须设置 user-agent 属性 WebViewchrome one 如下:

To achieve the same scaling as in Picture 2 from you question , you have to set the user-agent property of WebView to the chrome one as follow :

import QtWebKit.experimental 1.0
...
WebView {    
anchors.fill: parent
url: "http://google.com"   
experimental.userAgent:"Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36  (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36"
}
...

[更新]注意来自 3 个不同用户代理字符串的 3 个图像之间的区别

[Update] notice the difference between the 3 images from 3 different user-agent strings

------------------------------------------用户代理 Android 浏览器------------------------------------------------

------------------------------------------User-agent Android Browser------------------------------------------------

"Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30    (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"

------------------------------------------user-agent Chrome 浏览器------------------------------------------------

------------------------------------------user-agent Chrome Browser------------------------------------------------

"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36"

------------------------------------------user-agent Ipad-Macosx/Safari---------------------------------

------------------------------------------user-agent Ipad-Macosx/Safari------------------------------------------------

"Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25"