简体   繁体   English

无法获得自定义PyQt5小部件插件以显示在Qt设计器中(macos)

[英]Can't get custom PyQt5 widget plugin to show up in Qt designer (macos)

I would like to make a custom widget plugin for Qt Designer using python (3.7 with pyqt5). 我想使用python(3.7和pyqt5)为Qt Designer创建一个自定义的小部件插件。 Everything should work, but it doesn't show up in Qt Designer. 一切正常,但不会在Qt Designer中显示。

Here is what I have done so far after much trial and error and a little help from others with similar issues ( Qt Designer: could not find custom PyQt widget plugins and Custom QWidgets. How do I build/get the pyqt5 plugin for Qt Designer on Mac? ) 经过大量的尝试和错误以及其他有类似问题的人的帮助,这是我到目前为止所做的事情( Qt Designer:找不到自定义PyQt小部件插件自定义QWidgets。如何在以下位置构建/获取Qt Designer的pyqt5插件: Mac?

  • I installed Qt Designer (Creator) 5.13 from the Qt website. 我从Qt网站安装了Qt Designer(Creator)5.13。

  • I installed SIP (4.9.18) and PyQt5 (5.13.0) from source rather than pip because it was necessary to get the libpyqt5.dylib file that is necessary (no pyqt5-tools for mac). 我从源而不是pip安装了SIP(4.9.18)和PyQt5(5.13.0),因为有必要获取必要的libpyqt5.dylib文件(对于Mac,没有pyqt5-tools)。 I put this file in the /Users/[user]/Qt/5.13.0/clang_64/plugins/designer directory 我将此文件放在/ Users / [用户] /Qt/5.13.0/clang_64/plugins/designer目录中

  • I just want to get the setup correct before making my own plugin. 我只想在制作自己的插件之前正确设置设置。 So, I downloaded analogclock.py and analogclockplugin.py from https://github.com/baoboa/pyqt5/tree/master/examples/designer/plugins and modified the plugins.py file like this: 因此,我从https://github.com/baoboa/pyqt5/tree/master/examples/designer/plugins下载了Analogclock.py和Analogclockplugin.py,并修改了plugins.py文件,如下所示:

from PyQt5.QtCore import QLibraryInfo, QProcess, QProcessEnvironment


# Tell Qt Designer where it can find the directory containing the plugins and
# Python where it can find the widgets.
env = QProcessEnvironment.systemEnvironment()
env.insert('PYQTDESIGNERPATH', '[path to the plugin.py files]/designer_plugins')
env.insert('PYTHONPATH', '[path to the widgets]/designer_widgets')

# Start Designer.
designer = QProcess()
designer.setProcessEnvironment(env)
designer_bin = QLibraryInfo.location(QLibraryInfo.BinariesPath)

designer_bin = '/Users/[user]/Qt/5.13.0/clang_64/bin/Designer.app/Contents/MacOS/Designer'

designer.start(designer_bin)
designer.waitForFinished(-1)
  • I ran plugins.py. 我运行了plugins.py。 Qt Designer opens correctly, and when I checked the Designer-->About Plugins I see libpyqt5.dylib inside Loaded Plugins. Qt Designer正确打开,并且当我检查了Designer-> About Plugins时,我在Loaded Plugins中看到libpyqt5.dylib。 However, the PyAnalogClock widget was not inside of it and the plugin widget was not in the left-side widget box. 但是,PyAnalogClock窗口小部件不在其中,并且插件窗口小部件不在左侧窗口小部件框中。

  • I tried to debug by setting environmental variables from the terminal like this: 我试图通过从终端设置环境变量来进行调试,如下所示:

[user]$ export QT_DEBUG_PLUGINS=1
[user]$ export PYQTDESIGNERPATH='[path to the widgets]/designer_widgets'
[user]$ export PYTHONPATH='[path to the widgets]/designer_widgets'

[user]$ /Users/[user]/Qt/5.13.0/clang_64/bin/Designer.app/Contents/MacOS/Designer

The relevant portion of the output was this: 输出的相关部分是这样的:

Found metadata in lib /Users/[user]/Qt/5.13.0/clang_64/plugins/designer/libpyqt5.dylib, metadata=
{
    "IID": "org.qt-project.Qt.QDesignerCustomWidgetCollectionInterface",
    "archreq": 0,
    "className": "PyCustomWidgets",
    "debug": false,
    "version": 331008
}


loaded library "/Users/[user]/Qt/5.13.0/clang_64/plugins/designer/libpyqt5.dylib"

and toward the end 直到最后

loaded library "Python.framework/Versions/3.7/Python"
ModuleNotFoundError: No module named 'PyQt5'
ModuleNotFoundError: No module named 'PyQt5'
  • When I did not export PYQTDESIGNERPATH and PYTHONPATH from the command line, this error disappeared. 当我没有从命令行导出PYQTDESIGNERPATH和PYTHONPATH时,此错误消失了。 But of course, then Qt doesn't know where the files are. 但是,当然,然后Qt不知道文件在哪里。

In any case, that is my current state. 无论如何,这就是我目前的状态。 I do not understand why the PyQt5 module cannot be found by Qt Designer or what else I can try to get this to work. 我不明白为什么Qt Designer无法找到PyQt5模块,或者还有什么我可以尝试使其工作的。

here is an 🤦‍♂️ momemt So, I found this on the PyQt reference guide which I had somehow overlooked 这是一个🤦‍♂️妈妈,所以我在PyQt参考指南上发现了这个,但我却以某种方式忽略了它

  • For a simple but complete and fully documented example of a custom widget that defines new Qt signals, slots and properties, and its plugin, look in the examples/designer/plugins directory of the PyQt5 source package 有关定义新的Qt信号,插槽和属性及其插件的自定义窗口小部件的简单但完整的文档,请查看PyQt5源程序包的examples / designer / plugins目录。

ok. 好。 did that. 做过某事。 ran the demo. 运行演示。 it works fine. 它工作正常。 Copied the whole plugins directory somewhere else. 将整个插件目录复制到其他位置。 still fine. 还可以 So I must have done something funky naming the folders or something. 所以我一定做了一些时髦的命名文件夹之类的事情。 anyway, now I will just work on making my own plugin. 无论如何,现在我将致力于制作自己的插件。 days of frustration because of being dumb. 由于愚蠢而沮丧的日子。 but happy it works. 但很高兴它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 Virtualenv(Ubuntu)中运行的 Qt 设计器中显示自定义 PyQt5 小部件插件 - Can't get custom PyQt5 widget plugin to show up in Qt designer running in Virtualenv (Ubuntu) 使用 PyQt5 在 Qt Designer 中的自定义(升级)小部件中获取另一个小部件的当前值 - Get current value of another widget in a custom (promoted) widget in Qt Designer using PyQt5 Qt Designer和PyQt5自定义插件加载TypeError - Qt Designer and PyQt5 custom plugin loading TypeError 在 macOS (Sierra) 上安装 PyQt5(包括 Qt Designer) - Installing PyQt5 (incl. Qt Designer) on macOS (Sierra) PyQt5 从 model 获取数据以在 QListView 中显示自定义小部件 - PyQt5 get data from model to show custom widget in QListView 使用QT4 Designer无法在PyQT4中使用自定义插槽 - Can't get custom slot working in PyQT4 with QT4 designer 您可以在 Qt Designer (PyQt5) 中配置按键事件处理吗? - Can you configure key event handling in Qt Designer (PyQt5)? 如何为 WINDOWS 10 的 PyQt5 安装 Qt Designer - how can I install Qt Designer for PyQt5 for WINDOWS 10 Qt Designer:找不到自定义PyQt小部件插件 - Qt Designer: could not find custom PyQt widget plugins Qt 设计器由于没有 qt 插件在 pyqt5 中初始化错误而无法启动 - Qt designer failed to start due to no qt plugin initialized error in pyqt5 Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM