QWebView disables text selection when right-clicking

Right-clicking on any text on a web page viewed with QWebView on Windows selects the word under the cursor. I want to disable this behavior, but cannot find the link in the docs.

+4
source share
2 answers

This preference looks deep in Webkit (an engine that includes QWebView and Google Chrome among many others). There is a QtWebkitRelease20 error (version released with Qt 4.7.x ) - I think that’s why the behavior you want is visible in Chrome , but not Qt . There is another upcoming QtWebkitRelease22 branch that will be included as part of Qt 4.8 . I think that the change you will then be implemented in this version.

So, your options, as I see them, are as follows:

+5
source

We can use the JavaScript function to disable text selection in several browsers, following

 <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 this function

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

Source: https://habr.com/ru/post/1381583/


All Articles