I have simple application based on PyQT5. I need to get DOM element that is under mouse cursor when the mouse button is clicked.
Ok. Will answer myself:
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.view = QWebView(self)
self.view.installEventFilter(self)
# create other components here
def eventFilter(self, obj, event):
if obj == self.view:
if (event.type() == QEvent.MouseButtonRelease):
htc = self.view.page().mainFrame().hitTestContent(event.pos())
e = htc.element()
if e:
#do somesing with e
return True
return QMainWindow.eventFilter(obj, event)