Last active
December 27, 2015 01:59
-
-
Save tao4yu/7248648 to your computer and use it in GitHub Desktop.
PySide 本地 QObject 对象与 QtWebKit 中的JavaScript 对象之间的互操作。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add external css file to webkit | |
self.view.settings().setUserStyleSheetUrl(QtCore.QUrl.fromLocalFile("selectElem.css")) | |
# Add Local QObject and expose its slots and properties to JavaScript Context | |
self.view.page().currentFrame().addToJavaScriptWindowObject('htmlTextEdit', self.htmlTextEdit) | |
# Load Local jquery file to webkit | |
jqueryfile = QtCore.QFile("jquery-1.10.2.min.js"); | |
jqueryfile.open(QtCore.QIODevice.ReadOnly | QtCore.QIODevice.Text); | |
jQueryJs = jqueryfile.readAll().data(); | |
jqueryfile.close(); | |
# webkit execute external js file | |
self.view.page().currentFrame().evaluateJavaScript(jQueryJs) | |
code = "var flag2 = null;\ | |
$().ready(function(){\ | |
$('*').click(function(){\ | |
if(flag2 != null){\ | |
flag2.removeClass('elemselected');\ | |
}\ | |
flag2 = $(this);\ | |
htmlTextEdit.setPlainText($(this).html());\ | |
$(this).addClass('elemselected');\ | |
return false;\ | |
});\ | |
}); null;" | |
# webkit execute js code | |
self.view.page().mainFrame().evaluateJavaScript(code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment