在 QWebEngineView 上检测鼠标点击
Detect mouse clicks on QWebEngineView
如何检测 QWebEngineView 小部件中的鼠标点击?
我试过了,但没用:
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)
假设视图是 QWebEngineView 对象,并且您想跟踪它的鼠标事件,那么您应该使用 focusProxy,它是处理这些类型事件的内部小部件。另一方面,你必须正确地应用继承。
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)
如何检测 QWebEngineView 小部件中的鼠标点击?
我试过了,但没用:
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)
假设视图是 QWebEngineView 对象,并且您想跟踪它的鼠标事件,那么您应该使用 focusProxy,它是处理这些类型事件的内部小部件。另一方面,你必须正确地应用继承。
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)