Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

WebView content size



  • I gave my best to search the web, unfortunately, I am stuck (being a newbie).

    I am developing a qml Application and use QtWebKit 3.0. My design involves a Column Item with stacked Rectangles one which contains a WebView. I couldn't find a way to size-to-fit the rectangle to the content of the html. For older versions of QtWebKit there seems to be better access to the conentHeight of the WebView and the only solution seems to be to choose an explicit height (see below).
    I have tried the onloadingChanged: signal to query the height after loading, to no avail. Height stays at 0 and contentHeight is -1.

    Thanks in advance, any help appreciated.

    ...
    Column {
      id: myColumn
      Rectangle {
        width: parent.width;
        height: desc.paintedHeight;
        color: "green"
        Text { text: element.description; horizontalAlignment: Text.AlignHCenter; wrapMode: Text.WordWrap; id: desc }
      }
      Rectangle {
        width: parent.width
        height: 800
        Component.onCompleted: console.log("width: " + width + " height: "+ myHtml.height)
    
        WebView {
            id: myHtml
            url: element.html
            anchors.fill: parent
            Component.onCompleted: console.log("html width: " + width + " height: "+ height)
       }
    }
    ...
    

Log in to reply