赞
踩
QWebEngineView — PyQt Documentation v6.6.0
关键代码:self.widget_figure = QtWebEngineWidgets.QWebEngineView(parent=Dialog)
注意,显示网页使用的是QWebEngineView,可以通过Qt Designer的提升功能实现,关于pyqt显示pyecharts图的操作细节请参考下文:
PyQt6与Pyecharts交互_pyside6 pyqt6 pyecharts-CSDN博客
- # Form implementation generated from reading ui file 'fig_progress.ui'
- #
- # Created by: PyQt6 UI code generator 6.6.1
- #
- # WARNING: Any manual changes made to this file will be lost when pyuic6 is
- # run again. Do not edit this file unless you know what you are doing.
-
-
- from PyQt6 import QtCore, QtGui, QtWidgets
- from PyQt6 import QtWebEngineWidgets
-
- class Ui_Dialog(object):
- def setupUi(self, Dialog):
- Dialog.setObjectName("Dialog")
- Dialog.resize(749, 463)
- self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
- self.verticalLayout.setObjectName("verticalLayout")
- self.verticalLayout_all = QtWidgets.QVBoxLayout()
- self.verticalLayout_all.setObjectName("verticalLayout_all")
- self.widget_figure = QtWebEngineWidgets.QWebEngineView(parent=Dialog)
- self.widget_figure.setObjectName("widget_figure")
- self.verticalLayout_all.addWidget(self.widget_figure)
- self.frame_progress = QtWidgets.QFrame(parent=Dialog)
- self.frame_progress.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
- self.frame_progress.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
- self.frame_progress.setObjectName("frame_progress")
- self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.frame_progress)
- self.verticalLayout_3.setObjectName("verticalLayout_3")
- self.verticalLayout_fig_progress = QtWidgets.QVBoxLayout()
- self.verticalLayout_fig_progress.setObjectName("verticalLayout_fig_progress")
- self.label = QtWidgets.QLabel(parent=self.frame_progress)
- font = QtGui.QFont()
- font.setPointSize(10)
- self.label.setFont(font)
- self.label.setObjectName("label")
- self.verticalLayout_fig_progress.addWidget(self.label)
- self.progressBar = QtWidgets.QProgressBar(parent=self.frame_progress)
- self.progressBar.setProperty("value", 24)
- self.progressBar.setObjectName("progressBar")
- self.verticalLayout_fig_progress.addWidget(self.progressBar)
- self.verticalLayout_3.addLayout(self.verticalLayout_fig_progress)
- self.verticalLayout_3.setStretch(0, 2)
- self.verticalLayout_all.addWidget(self.frame_progress)
- self.verticalLayout_all.setStretch(0, 10)
- self.verticalLayout_all.setStretch(1, 2)
- self.verticalLayout.addLayout(self.verticalLayout_all)
-
- self.retranslateUi(Dialog)
- QtCore.QMetaObject.connectSlotsByName(Dialog)
-
- def retranslateUi(self, Dialog):
- _translate = QtCore.QCoreApplication.translate
- Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
- self.label.setText(_translate("Dialog", "图像加载中,请等待..."))
-
增加进度条显示网页加载进度。
- import sys
- import fig_progress
- from PyQt6.QtWidgets import QApplication, QDialog
- from PyQt6.QtCore import QUrl, QFileInfo
-
-
- class Ui_CDSN(fig_progress.Ui_Dialog, QDialog):
- def __init__(self):
- super().__init__()
- self.setupUi(self)
-
- self.frame_progress.hide()
- self.widget_figure.page().loadProgress.connect(self.on_load_progress)
-
- url = QUrl("file:" + QFileInfo("my_figure.html").absoluteFilePath())
- self.widget_figure.load(url)
- self.show()
-
- def on_load_progress(self, progress):
- self.frame_progress.show()
- self.progressBar.setValue(progress)
- if progress == 100:
- self.frame_progress.hide()
-
-
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- ui = Ui_CDSN()
- app.exec()
-
关于QProgressBar,更多细节可参考
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。