Reputation: 281
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.
Upvotes: 4
Views: 3187
Reputation: 9964
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>
Upvotes: 1
Reputation: 7687
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 use findText("")
to force a deselection.Upvotes: 5