Search code examples
javascripthtmlqtqtwebkitqwebview

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


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?


Solution

  • 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.