我正在使用 PySide2.QtWebEngineWidgets.QWebEngineView() 在其上设置 Html 以显示如下所示的基本页面。
该 html 文件在浏览器中工作正常,因为它的所有文件都位于与 html 文件相关的同一文件夹中。
将 Html 设置为以下文件后,我收到此异常:
Qt 错误:
Uncaught ReferenceError: require is not defined
这是否与 Qt 不像常规浏览器那样找不到相关文件有关?或者还有什么我应该做的吗?或者 QWebEngineView 不够先进,无法执行 javascript?如果是这样我应该使用什么?
我只想创建一个网页小部件并加载我的 Html,如下所示。其他一切都是由 Html 代码完成的。
重现:
将以下 html 代码另存为 html 文件
运行这段代码:
from PySide2 import QtCore, QtWidgets, QtGui
from PySide2.QtWebEngineWidgets import QWebEngineView
editor = QWebEngineView()
htmlfile = 'C:/myHtmlFile.html'
with open(htmlfile, 'r') as f:
html = f.read()
editor.setHtml(html)
editor.show()
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
</head>
<body>
<div id="container" style="width:800px;height:600px;border:1px solid grey"></div>
<script src="monaco-editor/min/vs/loader.js"></script>
<script>
require.config({ paths: { 'vs': 'monaco-editor/min/vs' }});
require(['vs/editor/editor.main'], function() {
var editor = monaco.editor.create(document.getElementById('container'), {
value: [
'function x() {',
'\tconsole.log("Hello world!");',
'}'
].join('\n'),
language: 'javascript',
fontFamily:"Verdana",
theme: "vs-dark"
});
});
</script>
</body>
</html>
慕丝7291255
相关分类