Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QWebview/webkit disable selection of text

I have a QWebView which loads some webpage, but the problem when mouse is pressed and dragged it selectes everything which comes in its way.

Is there any way I can get rid of this?? I dont want text and other items to be selected.,

If I restrict mouseMove and mousePress then it other functionality with these event also gets restricted which is what I dont want.

I tried alot to find any way in QWebView/Qwebpage but doesnt find any, do i need to do something in webkit?

Please help

like image 631
user269062 Avatar asked Oct 13 '10 23:10

user269062


2 Answers

If you control the content that is being loaded, you can use css:

body { -webkit-user-select: none; }

Otherwise you might add a user stylesheet with this rule.

like image 66
OlliM Avatar answered Sep 28 '22 00:09

OlliM


If you want a QT answer, maybe this is an option:

class MyWebView : public QWebView
{
protected:
   virtual void mouseMoveEvent(QMouseEvent *) { /* dummy implementation */ }
public:
   MyWebView(QWidget* parent) : QWebView(parent) { }
}

It overrides the original function and achieves that only press and release events are available in your webview. This worked for me on QT 4.8.

like image 31
user1234 Avatar answered Sep 28 '22 02:09

user1234