首页 > 其他分享 >Pyside或Pyqt的 QWebEngineView 载入html为空白的问题

Pyside或Pyqt的 QWebEngineView 载入html为空白的问题

时间:2022-10-11 12:00:59浏览次数:75  
标签:Pyside signal Pyqt 载入 html QWebEngineView import save

我想用Pyside6的QWebEngineView组件来载入一个本地的html网页,在解决了路径错误的问题后,使用load方法载入仍然是空白一片,

最后改成读取文件,改用setHtml载入,终于能显示了

示例代码如下

# --coding:utf-8--
import folium
from PySide6 import QtWidgets, QtWebEngineWidgets, QtCore
#from PySide2 import QtWidgets, QtWebEngineWidgets, QtCore

import sys
import signal
import io

app = QtWidgets.QApplication(sys.argv)

signal.signal(signal.SIGINT, signal.SIG_DFL)

view = QtWebEngineWidgets.QWebEngineView()
m = folium.Map(location=[3.474087, 108.370123], zoom_start=5)
m.save("save.html")

# 这种方法载入失败
# view.load("file:///save.html")
# 这种方法载入成功
with open("save.html", "rb") as f:
    view.setHtml(f.read().decode())

view.show()

app.exec_()

 

 

标签:Pyside,signal,Pyqt,载入,html,QWebEngineView,import,save
From: https://www.cnblogs.com/cfld/p/16778764.html

相关文章