c++ - Qt/QML:WebEngineView调整高度

标签 c++ qt qml webengine

我在ListView中有一堆WebEngineViews。例如:

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;
                }
            }
        }
    }
}

关于c++ - Qt/QML:WebEngineView调整高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42965087/

相关文章:

qt - Qml 菜单弹出延迟

c++ - 允许托管环境中的托管代码回调非托管代码

c++ - 从 PROP_ENTRY 转换为 PROP_ENTRY_TYPE

c++ - 从仅包含其迭代器的列表中删除元素

c++ - 如何更改当前工作目录?

c++ - T 为 QPointF 时的模板转换运算符

javascript - 在 JS 中使用 LocalStorage

image - 如何在 QML 中添加和使用资源?

c++ - 使用自定义构造函数将对象实例化为类属性 (C++)

c++ - 对象将自身存储到数据库中