[PyQt] Link between a QWebViev and a JavaScript program

projetmbc projetmbc at club-internet.fr
Fri Apr 24 10:10:26 BST 2009


Marcell Mars a écrit :
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
> from PyQt4.QtWebKit import *
>
> myWebKit = QWebView()
> myWebKit.show()
>
> myWebKit.setUrl(QUrl("http://www.google.com"))
>
> myWebKit.page().mainFrame().evaluateJavaScript(open('jquery.js').read())
>
> myWebKit.page().mainFrame().evaluateJavaScript("""$(document).ready(function()
> { $("body").css("background", "#f00");});""")


Indeed the line

                
myWebKit.page().mainFrame().evaluateJavaScript("""$(document).ready(function()

	{ $("body").css("background", "#f00");});""")


must be changed to

                
self.webView.page().mainFrame().evaluateJavaScript("""$("body").css("background", 
"#f00");""")

With this modification, everything is ok.

Thanks.
Christophe.



More information about the PyQt mailing list