QWebView 禁用右键单击文本选择

发布于 2024-12-17 00:24:38 字数 94 浏览 6 评论 0 原文

在 Windows 上使用 QWebView 查看的网页上的任何文本上单击鼠标右键,即可选择光标下的单词。我想禁用此行为,但在文档中找不到任何参考。

Right-clicking on any text on a webpage viewed with QWebView on Windows selects the word under the cursor. I want to disable this behaviour, but can't find any reference in the docs.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

皓月长歌 2024-12-24 00:24:38

这种偏好似乎深入到 Webkit(为 QWebView 和 Google Chrome 等许多引擎提供支持的引擎)。有一个 Webkit 错误,其中涉及围绕右侧所需行为的一些讨论- 单击一些文本,但此讨论(以及后续更改)发生在 Webkit 被分支以创建 href="http://trac.webkit.org/wiki/QtWebKitRelease20" rel="noreferrer">QtWebkitRelease20 (与 Qt 4.7.x 一起发布的版本) - 我认为这是为什么您想要的行为在 Chrome 中可见,但在 Qt 中不可见。还有另一个即将推出的分支 QtWebkitRelease22,它将作为 Qt 4.8< 的一部分包含在内/strong> - 我认为您所追求的更改将在该版本中实现。

所以我认为你的选择是:

This preference looks to be deep into Webkit (the engine that powers QWebView and Google Chrome among many others). There is a Webkit bug that involves a bit of discussion around the desired behaviour on right-clicking some text, but this discussion (and subsequent changes) occurred after Webkit was branched to create QtWebkitRelease20 (the version released with Qt 4.7.x) - I think this is why the behaviour you want is visible in Chrome but not Qt. There is another upcoming branch, QtWebkitRelease22, which will be included as part of Qt 4.8 - I think the change you're after will be implemented in that release.

So your options as I see them are either:

北座城市 2024-12-24 00:24:38

我们可以使用 JavaScript 函数来禁用多个浏览器上的文本选择,如下

<script type="text/javascript">

function disableSelection(target){
if (typeof target.onselectstart!="undefined") //For IE 
    target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //For Firefox
    target.style.MozUserSelect="none"
else //All other route (For Opera)
    target.onmousedown=function(){return false}
target.style.cursor = "default"
}
 </script>

调用此函数

<script type="text/javascript">
   disableSelection(document.body)
</script>

We can use a JavaScript function to Disable select of Text on Multiple browsers as follow

<script type="text/javascript">

function disableSelection(target){
if (typeof target.onselectstart!="undefined") //For IE 
    target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //For Firefox
    target.style.MozUserSelect="none"
else //All other route (For Opera)
    target.onmousedown=function(){return false}
target.style.cursor = "default"
}
 </script>

Call to this function

<script type="text/javascript">
   disableSelection(document.body)
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文