python - Is it possible to trigger a mousePressEvent artificially on a QWebView? -
due astronomically atrocious bug on pyqt4, need fire mousepressevent artificially on qwebview last breath of hope. obscure reason, qwebview's linkclicked , urlchanged signals not pass qurl when clicked link has javascript involved (it not work on youtube videos, example) and when link clicked left mouse button. qurl can accessed when link clicked middle , right buttons.
class cqwebview(qtwebkit.qwebview): def mousepressevent(self, event): if type(event) == qtgui.qmouseevent: if event.button() == qtcore.qt.leftbutton: # fire qtcore.qt.middlebutton event here, # can bloody link afterwards. elif event.button() == qtcore.qt.middlebutton: self.emit(qtcore.signal("open_in_new_tab")) # example elif event.button() == qtcore.qt.rightbutton: self.emit(qtcore.signal("xxx")) # example
so, literally want "click artificially", click without clicking, trigger event of clicking middle right button on link, can catch qurl correctly.
you can using qttest
module well. set event filter on web view , check left click mouse events , send middle mouse click
def __init__(...) self.ui_web_view.installeventfilter(self) def eventfilter(self, obj, event): if obj == self.ui_web_view: if event.type() == qtcore.qevent.mousebuttonpress: if event.button() == qtcore.qt.leftbutton: print 'handled' qttest.qtest.mouseclick(self.ui_web_view, qtcore.qt.middlebutton, qtcore.qt.nomodifier, event.pos()) return true return false
Comments
Post a Comment