I have simple application based on PyQT5. I need to get DOM element that is under mouse cursor when the mouse button is clicked.
问问题
690 次
1 回答
1
好的。会回答自己:
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)
于 2016-03-28T19:39:21.997 回答