我的问题的解决办法可能很简单,但我却不理解。我正在尝试用PyQt5将一个HTML文件加载到一个PyQt5中。我的做法是:
self.webView = QtWebEngineWidgets.QWebEngineView(self.splitter)
html = r"C:\DATI\git\webgis\map.html"
self.webView.setHtml(html)唯一能得到的是一个表示HTML文件的路径和名称的字符串:
C:\DATI\git\webgis\map.html
我的map.html看起来是这样的:
<html>
<head>
<title>Simple Map</title>
<link rel="stylesheet" href="https://openlayers.org/en/v4.5.0/css/ol.css" type="text/css">
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://openlayers.org/en/v4.5.0/build/ol.js"></script>
<script src=".js/qwebchannel.js"></script>
<style>
body { padding: 0; margin: 0; }
html, body, #map { height: 100%; }
</style>
</head>
<body>
<div id="map" class="map"></div>
<script src="./js/map.js"></script>
</body>
</html>奇怪的是(至少对我来说),如果我做了self.webView.setHtml("<html><head></head><body><h1>ciao</h1></body></html>"),这将正确地呈现HTML。
我遗漏了什么?
https://stackoverflow.com/questions/47679599
复制相似问题