Код: Выделить всё
Код: Выделить всё
import time
from PyQt5.QtCore import QUrl
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineScript
class MyWebPageView(QtWebEngineView):
def __init__(svg,*args,**kwargs):
super().__init__(*args,**kwargs)
# Create script object
js_script = QWebEngineScript()
js_script.setSourceCode(
"""
alert("qwebenginescript");
const mynamespace = { myfunction: function() { alert("success");}};
"""
)
js_script.setInjectionPoint(QWebEngineScript.DocumentCreation)
# Add the script to the page
self.page().scripts().insert(js_script)
time.sleep(3) #to be sure this is not a timing issue
# Load the SVG into the page
self.load(QUrl("file:///path/to/svg.svg"))
Код: Выделить всё
js: Uncaught ReferenceError: mynamespace is not defined
(Примечание: это продолжение этого вопроса: https:// stackoverflow.com/posts/79059688)
Подробнее здесь: https://stackoverflow.com/questions/790 ... in-html-do