[PyQt] javascript does not execute method in exposed QT object

JC Francois jc.francois at gmail.com
Sat Mar 15 11:17:21 GMT 2014


Hi,

I just started writing a rich text editor based on QWebView. In order 
for the Bold, Italics and Underline buttons
to reflect the attributes of the text under the cursor I am trying to 
get javascript to call a method in my MainWindow
object to change the "checked" status of the toolbar button. But the 
method never gets executed.

In the test case below "Hello World! " gets added to the Web View every 
time I move the cursor but the 'Bold' toolbar
button never gets checked. Excerpt:

In my MainWindow __Init__ I have:
     self.webView = QWebView()
     self.webPage = self.webView.page()
self.webPage.mainFrame().addToJavaScriptWindowObject("mainWindow", self)
     self.connect(self.webPage, SIGNAL("microFocusChanged()"), 
self.handle_microChange)

     def handle_microChange(self):
         js = 'function test() {document.write("Hello World! "); 
window.mainWindow.checkBold();} test();'
         self.webPage.mainFrame().evaluateJavaScript(js)

     def checkBold(self):
         self.action_Bold.setChecked(True)

Questions:
Why doesn't checkBold get executed while the test() javascript function 
runs?
Does the QTWebKit Bridge work in PyQt?

Platform: Linux, Windows / python 3.2.3 / QT 4.8.5 / PyQt 4.9.1



More information about the PyQt mailing list