QWebView 禁用右键单击文本选择
在 Windows 上使用 QWebView
查看的网页上的任何文本上单击鼠标右键,即可选择光标下的单词。我想禁用此行为,但在文档中找不到任何参考。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
在 Windows 上使用 QWebView
查看的网页上的任何文本上单击鼠标右键,即可选择光标下的单词。我想禁用此行为,但在文档中找不到任何参考。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
这种偏好似乎深入到 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> - 我认为您所追求的更改将在该版本中实现。所以我认为你的选择是:
QWidget::setContextMenuPolicy(Qt::NoContextMenu)
如果是的话,就会完成这项工作。QWebView::selectionChanged()< /code>
signal
然后使用findText("")
强制取消选择。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:
QWidget::setContextMenuPolicy(Qt::NoContextMenu)
will do the job if so.QWebView::selectionChanged()
signal
and then usefindText("")
to force a deselection.我们可以使用 JavaScript 函数来禁用多个浏览器上的文本选择,如下
调用此函数
We can use a JavaScript function to Disable select of Text on Multiple browsers as follow
Call to this function