How to stretch/shrink HTML Page to fit in QWebView window

为君一笑 提交于 2019-12-12 03:48:24

问题


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?


回答1:


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>

Hope this helps.



来源:https://stackoverflow.com/questions/10810895/how-to-stretch-shrink-html-page-to-fit-in-qwebview-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!