如何拉伸/缩小HTML页面以适应QWebView窗口 [英] How to stretch/shrink HTML Page to fit in QWebView window

查看:609
本文介绍了如何拉伸/缩小HTML页面以适应QWebView窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用QWebView使用setHTML方法呈现html页面。在HTML页面主体部分,我提到了HTML页面的宽度和高度,如果我们通过调用setGeometry(x,y,w,h)在运行时更改QWebView窗口的宽度和高度,那么如何使html页面调整自己,以适应内容完全适应在QWebView窗口中?

I am using QWebView to render a html page using setHTML method. In the html page body section I am mentioning width and height for the html page, if we are changing the width and hegiht of the QWebView window at run time by calling setGeometry(x,y,w,h), then how to make the html page adjust itself to fit the content fully in streched QWebView window?

推荐答案

您需要处理窗口.onresize()事件在JavaScript中。在HTML中插入以下代码...

You need to handle window.onresize() event in javascript. Insert following code in your html...

<script text = "javascript">

window.onresize = function(event) {

    var newWidth = window.innerWidth;
    var newHeight = window.innerHeight;

    // Code to adjust your contents..
}

</script>

希望这有助于您。

这篇关于如何拉伸/缩小HTML页面以适应QWebView窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆