[PyQt] Link between a QWebViev and a JavaScript program

Marcell Mars marcell.mars at gmail.com
Sun Apr 19 23:05:56 BST 2009


the simplest example of loading jquery.js (geti it from
http://jqueryjs.googlecode.com/files/jquery-1.3.2.js and put it in the
same directory with the snippet below) after loading html and then
using jquery syntax to change the background color into red:

run it in python interactive shell or better in ipython:

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");});""")


More information about the PyQt mailing list