pyqt 渲染html

时间:2023-05-21 22:53:14
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
import sys class MainWindow(QMainWindow): def __init__(self ):
super(QMainWindow, self).__init__()
self.setWindowTitle('QWebView打开网页例子')
self.setGeometry(, , , )
#self.browser = QWebEngineView()
# 加载html代码
self.browser = QWebEngineView()
self.browser.setHtml('''
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1>Hello PyQt5</h1>
<h1>Hello PyQt5</h1>
<h1>hello PyQt5</h1>
<h1>hello PyQt5</h1>
<h1>hello PyQt5</h1>
<h1>Hello PyQt5</h1> </body>
</html> '''
) self.setCentralWidget(self.browser) if __name__ == '__main__':
app = QApplication(sys.argv) win = MainWindow()
win.show()
sys.exit(app.exec_())