qt - 如何在 qt 5.9.6 中滚动 webengineview 的位置
问题描述
我正在运行最小的 webengineview 示例,并插入了一个按钮来向下移动页面。代码如下。我尝试使用 scrollPosition 但似乎滚动位置仅用于获取滚动位置。有没有办法将按钮点击链接到页面上的位置?谢谢
import QtQuick 2.0
import QtQuick.Window 2.0
import QtWebEngine 1.3
import QtQuick.Controls 1.4
Window {
width: 1024
height: 750
visible: true
Rectangle {
anchors.fill: parent
WebEngineView {
id:page
anchors.fill: parent
url: "http://www.qt.io"
}
Button {
id: buttondown
anchors {
bottom: parent.bottom
horizontalCenter: parent.horizontalCenter
}
width: 100
height: 50
text: "DOWN"
onClicked:{
page.scrollPosition(1,1)
}
}
}
}
解决方案
像这样编辑了 qml 文件,现在页面通常是滚动的。但是,如果要显示的 html 具有 index.html,则页面无法正确滚动。有人知道为什么吗?
import QtQuick 2.0
import QtQuick.Window 2.0
import QtWebEngine 1.3
import QtQuick.Controls 1.4
Window {
width: 1024
height: 750
visible: true
Rectangle {
anchors.fill: parent
WebEngineView {
id:web
anchors.fill: parent
url: "http://www.qt.io"
}
Button {
id: buttondown
anchors {
bottom: parent.bottom
horizontalCenter: parent.horizontalCenter
}
width: 100
height: 50
text: "DOWN"
onClicked:{
web.runJavaScript("window.scrollBy(%1,%2);".arg(0).arg(10));
}
}
}
}
推荐阅读
- xamarin - 如何使用“xamarin + Xam.Plugin.Webview”跨平台处理导航错误
- python - 为什么这段代码在我运行时会给我一个 NameError?
- ios - 在UILabel上使用捏合手势调整字体和标签框架的大小?
- maven - 是否可以使用 pom.xml 属性并忽略命令行参数?
- angular - 角度属性绑定
- amazon-redshift - 从红移查询编辑器中的字符变量中提取年份
- java - 在满足条件之前,如何使用加载屏幕正确暂停主线程而不冻结 UI,
- javascript - 用户如何通过 input=file 发送恶意软件代码
- unix - 整理出每个重复名字的最小值
- c++ - 测试 .txt 文件中的重复用户名