QWebView: notify python when I clicked on a certain web eleemnt

Дамјан Георгиевски gdamjan at gmail.com
Mon Feb 21 17:09:12 CET 2011


> I have a web page (existing page, can't modify it) and I would like
> to browse it in a QtWebview. (This is already working)
> 
> Now I Wonder how I could achieve following behaviour:
> 
> When I click on a certain element e.g. "<span id="clickme"></a>"
> I would like to notify my python script.
> 
> What is important:
> I don't want to change anything else in the web pages behaviour (This
> means if clicking on this element will call some java script
> functions, load a pag, then this should still happen.


You can inject JavaScript using the method 
QWebElement::evaluateJavaScript()

Also you can insert a Python object in the JS runtime with 
QWebFrame::addToJavaScriptWindowObject()
see here:
http://pysnippet.blogspot.com/2010/01/calling-python-from-javascript-in-
pyqts.html


so make a Python object with some methods you'd wish to call, then 
evaluate some small JS that will bind the click event on your element to 
the method of the Python object.


-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Teaching a pig to sing wastes your time & annoys the pig.




More information about the Python-list mailing list