Qt WebEngineView:禁用内容选择
如何在QML中禁用在WebEngineView中选择内容Qt WebEngineView:禁用内容选择,qt,qml,Qt,Qml,如何在QML中禁用在WebEngineView中选择内容 WebEngineView { id: webEngineView width: 600 * contentZoomFactor height: parent.height anchors.horizontalCenter: parent.horizontalCenter zoomFactor: contentZoomFactor onContextMenuRequested: {
WebEngineView {
id: webEngineView
width: 600 * contentZoomFactor
height: parent.height
anchors.horizontalCenter: parent.horizontalCenter
zoomFactor: contentZoomFactor
onContextMenuRequested: {
request.accepted = true;
}
}
您可以通过注入一点JavaScript来在主体上设置禁用选择的样式 下面是一个例子: 创建名为disableUserSelection.js的JavaScript文件,只需一个函数:
(function () {
document.body.style.webkitUserSelect = 'none';
document.body.style.webkitUserDrag = 'none';
})();
然后将其作为用户脚本注入到您的网页中:
WebEngineScript {
id: disableSelectionScript
injectionPoint: WebEngineScript.DocumentReady
sourceUrl: "qrc:/disableUserSelection.js"
worldId: WebEngineScript.MainWorld
}
userScripts: [disableSelectionScript]
这应该可以做到。您可以通过注入一点JavaScript在正文上设置一个禁用选择的样式来做到这一点 下面是一个例子: 创建名为disableUserSelection.js的JavaScript文件,只需一个函数:
(function () {
document.body.style.webkitUserSelect = 'none';
document.body.style.webkitUserDrag = 'none';
})();
然后将其作为用户脚本注入到您的网页中:
WebEngineScript {
id: disableSelectionScript
injectionPoint: WebEngineScript.DocumentReady
sourceUrl: "qrc:/disableUserSelection.js"
worldId: WebEngineScript.MainWorld
}
userScripts: [disableSelectionScript]
这就可以了。您只需使用鼠标earea在WebEngineView上创建一个透明矩形,然后处理鼠标事件,我只想禁用选择内容,其他功能(如url单击)应该可以工作您只需使用鼠标在WebEngineView上创建一个透明的矩形,然后处理鼠标事件我只想禁用选择内容,其他功能(如url单击)应该可以工作