首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >“没有设置环境变量PYSIDE_DESIGNER_PLUGINS,因此退出。”

“没有设置环境变量PYSIDE_DESIGNER_PLUGINS,因此退出。”
EN

Stack Overflow用户
提问于 2021-07-26 11:03:30
回答 2查看 5.1K关注 0票数 6

我已经安装了开源的qt创建者(免费版本),并创建了非常简单的桌面应用程序。我能够创建简单的窗口,但是当我运行时,我会收到以下错误:

我试着遵循这一页,但无法理解如何解决这个问题。

https://www.qt.io/blog/qt-for-python-6.1

代码语言:javascript
运行
复制
Environment variable PYSIDE_DESIGNER_PLUGINS is not set, bailing out.
No instance of QPyDesignerCustomWidgetCollection was found.

Python文件

代码语言:javascript
运行
复制
# This Python file uses the following encoding: utf-8
import os
from pathlib import Path
import sys

from PySide6.QtWidgets import QApplication, QMainWindow
from PySide6.QtCore import QFile
from PySide6.QtUiTools import QUiLoader


    class test(QMainWindow):
        def __init__(self):
            super(test, self).__init__()
            self.load_ui()
    
        def load_ui(self):
            loader = QUiLoader()
            path = os.fspath(Path(__file__).resolve().parent / "form.ui")
            ui_file = QFile(path)
            ui_file.open(QFile.ReadOnly)
            loader.load(ui_file, self)
            ui_file.close()
    
    
    if __name__ == "__main__":
        app = QApplication([])
        widget = test()
        widget.show()
        sys.exit(app.exec_())

添加xml

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>test3</class>
 <widget class="QMainWindow" name="test3">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>1332</width>
    <height>702</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>test3</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QCheckBox" name="checkBox">
    <property name="geometry">
     <rect>
      <x>300</x>
      <y>240</y>
      <width>70</width>
      <height>17</height>
     </rect>
    </property>
    <property name="text">
     <string>CheckBox</string>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menuBar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>1332</width>
     <height>21</height>
    </rect>
   </property>
   <widget class="QMenu" name="menuFile">
    <property name="title">
     <string>File</string>
    </property>
    <addaction name="actionOpen"/>
    <addaction name="actionsave"/>
   </widget>
   <widget class="QMenu" name="menuEdit">
    <property name="title">
     <string>Edit</string>
    </property>
   </widget>
   <widget class="QMenu" name="menuArchive_and_update_indicator">
    <property name="title">
     <string>Archive and update indicator</string>
    </property>
   </widget>
   <addaction name="menuFile"/>
   <addaction name="menuEdit"/>
   <addaction name="menuArchive_and_update_indicator"/>
  </widget>
  <action name="actionOpen">
   <property name="text">
    <string>Open</string>
   </property>
  </action>
  <action name="actionsave">
   <property name="text">
    <string>Save</string>
   </property>
  </action>
 </widget>
 <resources/>
 <connections/>
</ui>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-07-31 19:55:16

您正在从PySide6中的一个名为“自定义小部件”的新的实验性特性中看到一条信息。要使消息保持沉默,可以将变量"PYSIDE_DESIGNER_PLUGINS“设置为”“。用于当前文件夹。

https://www.qt.io/blog/qt-for-python-6.1声明:

为Linux和Windows提供了一个新的实验性插件,它提供>支持用Python编写自定义小部件,然后可以从Qt设计器中选择>用于布局。需要一些额外的魔法才能在macOS上启用此功能。我们希望在6.1.1中做好准备!

有关此功能的更多信息可以在这里找到:

https://doc-snapshots.qt.io/qtforpython-dev/tutorials/basictutorial/uifiles.html#custom-widgets-in-qt-designer

票数 6
EN

Stack Overflow用户

发布于 2022-07-14 02:26:45

有一种方法可以使

代码语言:javascript
运行
复制
Environment variable PYSIDE_DESIGNER_PLUGINS is not set, bailing out.

“消息消失”是将PYSIDE_DESIGNER_PLUGINS (例如,os.environ["PYSIDE_DESIGNER_PLUGINS"]=".")设置为具有空白register*.py文件的文件夹,例如,将空白文件命名为register_dummy.py

你还会有

代码语言:javascript
运行
复制
No instance of QPyDesignerCustomWidgetCollection was found.

不过,因为register_dummy.py文件不调用QPyDesignerCustomWidgetCollection.registerCustomWidget函数。为了摆脱这个问题,您只需制作一个自定义小部件,也许可以使用在可接受的答案中引用的链接中提到的wigglywidget,也可以在site-packages/PySide6/examples/widgetbinding中找到。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68528717

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档