QML:WebEngineView 无法在 ScrollView 中滚动(也可滑动)

问题描述 投票:0回答:1

我对 WebEngineView 有一些不便。我将它像其他元素一样放置在滚动视图中。只需要播放一些 YouTube 视频即可。 因此,当我滚动 ScrollView 时,当鼠标位于 WebEngineView 区域上时,它将不再滚动。

ApplicationWindow {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")
    
    ScrollView
    {
        id: myScrollView
        anchors.fill: parent;
        Rectangle
        {            
            ...
        }
        
        Text ...
        Text ...
        other stuff
        
        WebEngineView
        {
            id: myWebEngineView
            Component.onCompleted:
            {
                loadHtml(model.modelData.someHTMLData);
            }                
        }
    }
}

正如我所发现的。您可以在 WebEngineView 上执行

enabled = false
。但这使得它无法点击。我也尝试在其中添加 MouseArea,但没有帮助。将其包装在 Item 中也不起作用。

qt qml scrollview qwebengineview
1个回答
0
投票

我能够让它与

Flickable
一起工作:

  • 确保 Flickable contentWidth 和 contentHeight 设置正确
  • 确保 WebEngineView 宽度和高度设置正确
  • (可选)配置 Flickable 的滚动条
Flickable
{
    id: myScrollView
    anchors.fill: parent
    ScrollBar.vertical: ScrollBar { policy: ScrollBar.AlwaysOn; width: 20 }
    clip: true
    contentWidth: myWebEngineView.width
    contentHeight: myWebEngineView.height
    WebEngineView
    {
        id: myWebEngineView
        width: myScrollView.width - 20
        height: Math.max(contentsSize.height, 500)
        Component.onCompleted: url = "https://stackoverflow.com/questions/78632674/qml-webengineview-cant-be-scrolled-in-scrollview-flickable-too"
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.