Qt/QML: WebEngineView调整高度

Qt/QML: WebEngineView adjusting height

我在一个 ListView 中有一堆 WebEngineView。例如:

ListView 
{
    model: myModel
    delegate: Component 
    {
        Item 
        {
            WebEngineView 
            {
                id: myWebView
                Component.onCompleted: loadHtml(model.modelData.htmlText, baseURL)
            }
        }
    }
}

加载 html 后如何调整项目的高度?有问题的 HTML 可能包含图像,因此我想在加载所有内容后调整 WebEngineView 的大小。我想我可以做类似的事情:

ListView 
{
    model: myModel
    delegate: Component 
    {
        Item 
        {
            WebEngineView 
            {
                id: myWebView
                Component.onCompleted: loadHtml(model.modelData.htmlText, baseURL)
                onLoadingChanged: 
                { 
                    if (!loading && loadRequest.status == WebEngineView.LoadSucceededStatus)
                    {
                        height = ???? 
                    }
                }
            }
        }
    }
}

但是我不确定应该设置多少高度。

我可以像这样用“onContentsizeChange”做我想做的事:

ListView 
{
    model: myModel
    delegate: Component 
    {
        Item 
        {
            WebEngineView 
            {
                id: myWebView
                Component.onCompleted: loadHtml(model.modelData.htmlText, baseURL)

                onContentsSizeChanged:
                {
                    myWebView.height = contentsSize.height;
                }
            }
        }
    }
}