I am trying to make the mousePressEvent and mouseMoveEvent event work to move my app window from QtWebChannel.
I am using self.setWindowFlags (QtCore.Qt.FramelessWindowHint) to remove window flag and use a custom one with html, css and js.
Inside the html I have a div with id "header" that has the custom window flag, I would like to keep the left mouse button pressed, the window could be dragged as if it were a conventional window flag.
The close, minimize and maximize buttons already have their respective functions when clicking with a backend but I am having problems creating a function that allows moving the window from the <div id="header"> . . . </ div >.
How do I run the mousePressEvent and mouseMoveEvent events inside the QtWebChannel to move the window and simulate a traditional window flag?
from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets, QtWebChannel
from PyQt5.QtCore import QPoint
class Backend(QtCore.QObject):
    valueChanged = QtCore.pyqtSignal(str)
    def __init__(self, parent=None):
        super().__init__(parent)
        self._value = ""
    @QtCore.pyqtProperty(str)
    def value(self):
        return self._value
    @value.setter
    def value(self, v):
        self._value = v
        self.valueChanged.emit(v)
class Widget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.webEngineView = QtWebEngineWidgets.QWebEngineView()
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.resize(650, 610)
        self.setWindowOpacity(0.99)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("favicon.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.setWindowIcon(icon)
        lay = QtWidgets.QVBoxLayout(self)
        lay.setContentsMargins(0, 0, 0, 0)
        lay.addWidget(self.webEngineView)
        backend = Backend(self)
        backend.valueChanged.connect(self.foo_function)
        self.channel = QtWebChannel.QWebChannel()
        self.channel.registerObject("backend", backend)
        self.webEngineView.page().setWebChannel(self.channel)
        path = "http://localhost"
        self.webEngineView.setUrl(QtCore.QUrl(path))
    @QtCore.pyqtSlot(str)
    def foo_function(self, value):
        print("JS:", value)
if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    w = Widget()
    w.show()
    sys.exit(app.exec_())
Fragment html code
<div id="header" style="top: 0;" class="header">
    <button ondblclick="$('#div_console').fadeIn('fast')" class="ui-btn modales" id="btn_title" value="title" title="Bankus"><i style="color:#007bff" class="fas fa-eye"></i></button>
    <span id="title_text">Bankus 1.0</span>
    <button title="Cerrar" id="btn_exit" value="exit" onclick="json($(this))" class="ui-btn closee modales"><svg viewBox="0 0 10 10"><polygon points="10.2,0.7 9.5,0 5.1,4.4 0.7,0 0,0.7 4.4,5.1 0,9.5 0.7,10.2 5.1,5.8 9.5,10.2 10.2,9.5 5.8,5.1" /></svg></button>
    <button title="Maximizar" id="btn_maxi" value="maxi" onclick="json($(this))" class="ui-btn maximize modales"><svg viewBox="0 0 10 10"><path d="M0,0v10h10V0H0z M9,9H1V1h8V9z" /></svg></button>
    <button title="Retaurar" id="btn_maxi" value="norm" onclick="json($(this))" class="ui-btn maximize modales invisi"><svg viewBox="0 0 10.2 10.1"><path d="M2.1,0v2H0v8.1h8.2v-2h2V0H2.1z M7.2,9.2H1.1V3h6.1V9.2z M9.2,7.1h-1V2H3.1V1h6.1V7.1z" /></svg></button>
    <button title="Minimizar" id="btn_mini" value="mini" onclick="json($(this))" class="ui-btn minimize modales"><svg x="0px" y="0px" viewBox="0 0 10.2 1"><rect x="0" y="50%" width="10.2" height="1" /></svg></button>
    <button title="Captura de pantalla" id="btn_capt" value="capt" onclick="json($(this))" class="ui-btn modales"><svg id="capture" xmlns="http://www.w3.org/2000/svg" data-name="Layer 1" viewBox="0 0 64 64"><polygon fill="none" stroke="#010101" stroke-miterlimit="10" stroke-width="4" points="47 12 42.88 8 21.12 8 17 12 2 12 2 56 62 56 62 12 47 12"/><circle cx="32" cy="34" r="14" fill="none" stroke="#010101" stroke-miterlimit="10" stroke-width="4"/><path fill="none" stroke="#010101" stroke-miterlimit="10" stroke-width="2" d="M10,21h0a1,1,0,0,1-1-1H9a1,1,0,0,1,1-1h0a1,1,0,0,1,1,1h0A1,1,0,0,1,10,21Z"/></svg></button>
</div>
Full html code on github: https://github.com/onimac92/bankus/blob/master/index.html
Code minimal html:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
    margin: 0;
}
#header {
    width: 100%;
    height: 30px;
    background: red;
    position: absolute;
}
</style>
</head>
<body>
<div id="header"></div>
</body>
</html>
