显示嵌入的HTML代码的网页 的案例
import os
import sys
from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QIcon
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import QMainWindow, QHBoxLayout, QPushButton, QMessageBox, QApplication
'''
显示嵌入的HTML网页 的案例
'''
class InnerHtmlDemo(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
# 设置定位和左上角坐标
self.setGeometry(300, 300, 360, 260)
# 设置窗口标题
self.setWindowTitle('显示嵌入的HTML网页 的演示')
# 设置窗口图标
# self.setWindowIcon(QIcon('../web.ico'))
self.browser = QWebEngineView()
self.browser.setHtml('''
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>测试页面</title>
</head>
<body>
<h1>测试标题H1</h1>
<h2>显示嵌入的HTML代码的网页</h2>
<h3>测试标题H1</h3>
<h4>测试标题H1</h4>
</body>
</html>
''')
self.setCentralWidget(self.browser)
if __name__ == '__main__':
app = QApplication(sys.argv)
# 设置应用图标
app.setWindowIcon(QIcon('../web.ico'))
w = InnerHtmlDemo()
w.show()
sys.exit(app.exec_())