用QtDesiger设计UI界面显示网页内容出现的问题
我想将网页页面显示在用QtDesiger设计的界面上,因为QtDesiger没有QtWebEngineWidgets控件,已经手动安装,编译后的文件名为“图表_UI.PY”,内容如下:from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import QtWebEngineWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(821, 530)
self.groupBox = QtWidgets.QGroupBox(Form)
self.groupBox.setGeometry(QtCore.QRect(290, 80, 521, 441))
self.groupBox.setObjectName("groupBox")
self.browser = QtWebEngineWidgets.QWebEngineView(self.groupBox)
self.browser.setGeometry(QtCore.QRect(9, 19, 501, 411))
self.browser.setObjectName("browser")
self.label = QtWidgets.QLabel(Form)
self.label.setGeometry(QtCore.QRect(330, 10, 191, 51))
font = QtGui.QFont()
font.setFamily("宋体")
font.setPointSize(18)
self.label.setFont(font)
self.label.setObjectName("label")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.groupBox.setTitle(_translate("Form", "图表展示区"))
self.label.setText(_translate("Form", "图表可视化"))
***********************************************************************************
使用代码和界面分离的方式实现显示,代码如下:
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtCore import QUrl
from 图表_UI import Ui_Form
import os
import sys
class Chart_Form(QMainWindow, Ui_Form):
def __init__(self, parent=None):
super(Chart_Form, self).__init__(parent)
self.setupUi(self)
self.browser.load(QUrl(https://www.baidu.com/))
self.setCentralWidget(self.browser)
if __name__ == "__main__":
app = QApplication(sys.argv)
mainWindow = QWidget()
ui = Chart_Form()
ui.setupUi(mainWindow)
mainWindow.show()
sys.exit(app.exec_())
执行时代码无报错提示,但是就是在显示区中无内容!
如果去掉所有继承,单独用以下代码是可以显示的:
self.browser = QtWebEngineWidgets.QWebEngineView()
self.browser.load(QUrl(https://www.baidu.com/))
self.setCentralWidget(self.browser)
请高手指教,是哪儿出问题了,谢谢!