首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

PyQt加载UI文件

1.动态加载

import sysfrom PySide6 import QtCore,QtWidgetsfrom PySide6.QtWidgets import *from PySide6.QtCore import QFilefrom PySide6.QtUiTools import QUiLoaderclass readfile(QWidget):   def __init__(self):       super().__init__()       qfile=QFile("test.ui")       qfile.open(QFile.ReadOnly)       qfile.close()       self.ui=QUiLoader().load(qfile,self)           self.__create_connections()   def __create_connections(self):                   self.ui.pushButton.clicked.connect(self.open_file)         def open_file(self):             fname,_ = QFileDialog.getOpenFileName(self,"打开文件", '.')       if fname:                     self.ui.lineEdit.setText(fname)                         with open(fname,'r') as f:           content = f.read()           self.ui.textBrowser.setText(str(content))   if __name__ == '__main__':#QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)#QApplication.setAttribute(Qt.AA_ShareOpenGLContexts)app = QApplication(sys.argv)w = readfile()w.show()     sys.exit(app.exec())

动态加载出有错误信息,但不影响运行

错误信息如下:

qt.pysideplugin: Environment variable PYSIDE_DESIGNER_PLUGINS is not set, bailing out.qt.pysideplugin: No instance of QPyDesignerCustomWidgetCollection was found.Qt WebEngine seems to be initialized from a plugin. Please set Qt::AA_ShareOpenGLContexts using QCoreApplication::setAttribute and QSGRendererInterface::OpenGLRhi using QQuickWindow::setGraphicsApi before constructing QGuiApplication.

  • 发表于:
  • 原文链接https://page.om.qq.com/page/Ome12BO3dYqYd6pHkRr6XvTQ0
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券