3

I use qml WebView QT 5.2.

WebView {    
    anchors.fill: parent
    url: "http://google.com"   
}

Loaded page content is scaled depending on WebView width. How can I get default scale like in browser?

left picture my WebView, right - Google Chrome enter image description here

Dima Portenko
  • 3,443
  • 5
  • 35
  • 48
  • 1
    Hi there, try to play with **QtWebKit.experimental** by `import QtWebKit.experimental 1.0 ` look at [QtWebKit.experimental](http://rschroll.github.io/beru/2013/08/21/qtwebview.experimental.html) – Redanium Mar 13 '14 at 02:00
  • @Redanium thanks for the tip. Not really what I'm looking for. But interesting information anyway. – Dima Portenko Mar 13 '14 at 10:13

2 Answers2

3

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"
}
...

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

------------------------------------------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 Android Browser

------------------------------------------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 Chrome Browser

------------------------------------------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"

user-agent Ipad-Macosx/Safari

Redanium
  • 879
  • 5
  • 18
  • Did you try this code? Doesn't make any effect for me. I'm using OS X 10.9.2 and QT 5.2. – Dima Portenko Mar 14 '14 at 10:58
  • yep, it worked on windows 7 64, Qt 5.2.1 and I even played with different user-agent strings .e.g Android Webkit user-agent, you got the same content as in android mobile browser...etc check this [User Agent String](http://www.useragentstring.com/pages/useragentstring.php) and play with it. – Redanium Mar 14 '14 at 13:58
  • I've read more about User Agent. I've just need find right combination of user agent string and website I want to display. – Dima Portenko Mar 14 '14 at 14:14
1

Although this topic is pretty old, I had just encountered the same issue with QT 5.11 in a Ubuntu Touch app. Turned out that I just had to set the following:

    QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

(or QApplication, respectively)

Note that this must be set before the application instance is created:

int main(int argc, char *argv[])
{
    QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication *app = new QGuiApplication(argc, (char**)argv);

This lead to the webview scaling the same way the native browser on ubuntu touch does (Morph browser). I did not need to set any user agent information.

For those also working with Ubuntu Touch, the MainView size does have a direct impact on content scaling in the webview. I left the defaults set by the creation process (clickable create), which is:

   width: units.gu(45)
   height: units.gu(75)

This leads to correct scalingon the device (in this case, a Volla Phone).

user826955
  • 3,137
  • 2
  • 30
  • 71