Issue
How can I detect mouse clicks in QWebEngineView widget?
I tried this but doesn't work:
class MyWin(QtWidgets.QMainWindow):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.view.installEventFilter(self)
def eventFilter(self, obj, event):
if event.type() == event.MouseButtonPress:
print ("Widget click")
return super(QtWidgets.QMainWindow, self).eventFilter(obj, event)
Solution
Assuming that the view is the QWebEngineView object and you want to track its mouse event then you should use the focusProxy which is an internal widget that handles these types of events. On the other hand you must correctly apply inheritance.
class MyWin(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MyWin, self).__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.view.focusProxy().installEventFilter(self)
def eventFilter(self, obj, event):
if obj is self.ui.view.focusProxy() and event.type() == event.MouseButtonPress:
print("Widget click")
return super(MyWin, self).eventFilter(obj, event)
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.