在使用python对ui.UI界面进行加载时,出现错误,但是不影响运行,这是怎么回事?
代码如下:
from PySide6.QtWidgets import QWidget, QApplication, QLabel, QPushButton
from PySide6.QtUiTools import QUiLoader
class first_window:
def __init__(self):
self.ui = QUiLoader().load("ui_1.ui")
app = QApplication()
mywindow = first_window()
mywindow.ui.show()
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.
你遇到的错误提示是关于PySide6设计器插件的问题,以及与Qt WebEngine的初始化有关。这些错误通常不会影响到程序的运行,但可能会导致某些功能或插件无法正常工作。
以下是一些建议来解决这些问题:
PYSIDE_DESIGNER_PLUGINS
环境变量未设置。你可以通过以下代码设置该环境变量,使其指向PySide6的插件目录:import os
from pathlib import Path
plugins_path = Path(os.__file__).absolute().parent / "Lib" / "site-packages" / "PySide6" / "plugins"
os.environ["PYSIDE_DESIGNER_PLUGINS"] = str(plugins_path)
请确保这个路径指向的是你的PySide6安装目录下的正确插件位置。
QGuiApplication
之前设置了Qt::AA_ShareOpenGLContexts
和QSGRendererInterface::OpenGLRhi
属性。这可以通过以下代码实现:app = QApplication([])
app.setAttribute(Qt.AA_ShareOpenGLContexts)
app.setAttribute(Qt.AA_UseOpenGLES) # 如果你使用的是嵌入式OpenGL ES
ui_1.ui
文件存在,并且没有任何错误。有时候,UI文件中的一些错误会导致加载失败或出现其他问题。【相关推荐】
UI (user interface)是程序用户的交互界面,终端窗口就是一个简易的UI,当我们想把UI做的自然,美观,功能更齐全,操作更简单时命令行方式就不便用户使用了,这时我们需要图形界面。