PySide:QWebView's Mouse move and Mouse press events Freezing html document
<p>I am trying to make a QwebView window move whenever I drag the mouse within the window (not the title bar) while at the same time events in the html documents can trigger.</p>

<p>Here is my implementation of it</p>

<pre><code>import sys
import json
import threading
from time import sleep
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtWebKit import QWebView, QWebSettings
from PySide.QtNetwork import QNetworkRequest
from PySide.QtCore import QObject, Slot, Signal

#html_str="".join((open("/root/adstar_gui_generate.html","r").readlines()))
html_str=""" 
&lt;!doctype&gt;
&lt;body&gt;
&lt;html&gt;
 &lt;div class="btns"&gt;Books&lt;/div&gt;
 &lt;div class="btns"&gt;Enteraintment&lt;/div&gt;
 &lt;div class="btns"&gt;Sport&lt;/div&gt;
&lt;/html&gt;
&lt;style&gt;
.btns{
    display:inline-block;
    color:white;
    background:black;
}
.btns:hover{
    background:green;
    cursor:pointer;
}
&lt;/style&gt;
&lt;/body&gt;
&lt;/doctype&gt;

"""


class move_win(QObject):
    def __init__(self):
        super(move_win,self).__init__()

    @Slot(str)    
    def move(self,pos):
        print pos
        pos=json.loads(pos)
        #x_w = event.pos().X
        #y_w = event.pos().X
        dial.webview.move(pos["x"],pos["y"])    


class web_view(QWebView):
    def __init__(self):
        super(web_view,self).__init__()
        self.mousedown=None
        self.mouseup=None
    def mouseReleaseEvent(self,event):
        self.mouseup=True
        self.mousedown=False

    def mousePressEvent(self, event):
        #self.offset = event.pos()
        self.offset = event.pos()
        self.mouseup=False
        self.mousedown=True

    def mouseMoveEvent(self, event):
        if self.mousedown is True:
            x=event.globalX()
            y=event.globalY()
            x_w = self.offset.x()
            y_w = self.offset.y()
            self.move(x-x_w, y-y_w)


if __name__=="__main__":
    Qapp=QApplication(sys.argv)
    t=web_view()
    t.settings().setAttribute(QWebSettings.WebAttribute.DeveloperExtrasEnabled, True)
    t.setHtml(html_str)
    t.show()
    QCoreApplication.processEvents()
    Qapp.exec_()
</code></pre>

<p>Running the above codes, One can see that hovering over the html buttons does not work most of the time (the color of the button does not change neither the cursor).
<hr>
<strong>My thoughts</strong></p>

<p>I am assuming that this is due to mousePressEvent and mouseMoveEvents of QWebview Itself (well my implementation of it) preventing or causing the html document to freeze.</p>

<p><hr>
<strong>Note</strong></p>

<p>If I commented out the mousePressEvent and mouseMoveEvent from the class web_view. hovering over the html buttons works (the buttons change color and the cursor changes)</p>

<p>I tried creating a QThread to determine if an asynchronous approach can be the solution (same bad luck)...</p>

<p><strong>Question:</strong></p>

<p>How can drag the QWebView Window without causing the html document in the window to freeze ( A simple approach will be welcomed since I am new to PySide)</p>

<p>You forgot to call super methods of mouse*Event.</p>

<p>Reason: Those methods are called event handler. Since you overridden it and didn't call default implementation, QWebView have no chance to know mouse states (But it was not "freezed").</p>

<p><a href="https://doc.qt.io/qt-4.8/eventsandfilters.html" rel="nofollow">Qt events overview</a></p>

<pre><code>class web_view(QWebView):
    def __init__(self):
        super(web_view,self).__init__()
        self.mousedown=None
        self.mouseup=None

    def mouseReleaseEvent(self,event):
        self.mouseup=True
        self.mousedown=False
        super(web_view, self).mouseReleaseEvent(event)    # here

    def mousePressEvent(self, event):
        #self.offset = event.pos()
        self.offset = event.pos()
        self.mouseup=False
        self.mousedown=True
        super(web_view, self).mousePressEvent(event)    # here

    def mouseMoveEvent(self, event):
        if self.mousedown is True:
            x=event.globalX()
            y=event.globalY()
            x_w = self.offset.x()
            y_w = self.offset.y()
            self.move(x-x_w, y-y_w)
        super(web_view, self).mouseMoveEvent(event)    # here
</code></pre>

python pyqt pyside