我有一个 QWebView 可以加载一些网页,但是当鼠标按下并拖动它时会出现问题,它会选择所有阻碍它的东西。
有什么办法可以摆脱这个??我不想选择文本和其他项目。,
如果我限制 mouseMove 和 mousePress,那么这些事件的其他功能也会受到限制,这是我不想要的。
我尝试了很多在 QWebView/Qwebpage 中找到任何方法但没有找到任何方法,我需要在 webkit 中做些什么吗?
请帮忙
如果您控制正在加载的内容,则可以使用 css:
body { -webkit-user-select: none; }
否则,您可能会使用此规则添加用户样式表。
如果您想要 QT 答案,也许这是一个选项:
class MyWebView : public QWebView
{
protected:
virtual void mouseMoveEvent(QMouseEvent *) { /* dummy implementation */ }
public:
MyWebView(QWidget* parent) : QWebView(parent) { }
}
它覆盖了原始功能并实现了在您的 webview 中只有新闻和发布事件可用。这在 QT 4.8 上对我有用。
试试这个方法:
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)