QWebview/webkit disable selection of text
Asked Answered
W

3

7

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

Whelan answered 13/10, 2010 at 23:29 Comment(0)
H
10

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.

Haggai answered 27/12, 2010 at 9:26 Comment(1)
Works nicely for text, but still if I click-and-drag starting over an image, the image follows the pointer (I was hoping to avoid that too). Edit: solution in #2040905Rozina
J
1

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.

Jeaninejeanlouis answered 14/12, 2016 at 10:23 Comment(0)
F
-1

Try this method:

def mousePressEvent(self, event):
    if event.pos().x() in range(self.frameRight - self.vScrollWidth+1,self.frameRight+1) or event.pos().y() in range(self.frameBottom+1 - self.hScrollHeight,self.frameBottom+1):
        self.dragScroll = True
        super(myWeb,self).mousePressEvent(event)
def mouseMoveEvent(self,event):
    if self.dragScroll == True:
        super(myWeb,self).mouseMoveEvent(event)
Flareup answered 18/7, 2017 at 9:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.