一个简单的解决方案是使用QWebEngineView
,在我的情况下,我可以在 Qt Designer 中找到它:
但是如果你没有它,没有问题,因为有一个小部件。在上一个答案中,我指出了它是如何完成的QVideoWidget
,但在你的情况下,你应该只改变
Promoted class name: QWebEngineView
Header file: PyQt5.QtWebEngineWidgets
测试.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWebEngineView" name="widget" native="true"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QWebEngineView</class>
<extends>QWidget</extends>
<header>PyQt5.QtWebEngineWidgets</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
主文件
import os
import sys
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets, uic
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
path_ui = os.path.join(os.path.dirname(__file__), "test.ui")
window = uic.loadUi(path_ui)
window.widget.load(QtCore.QUrl("https://stackoverflow.com/"))
window.show()
sys.exit(app.exec_())