首页 > 解决方案 > 无法在 Qt 设计器(macos)中显示自定义 PyQt5 小部件插件

问题描述

我想使用 python(3.7 和 pyqt5)为 Qt Designer 制作一个自定义小部件插件。一切都应该工作,但它没有出现在 Qt Designer 中。

这是我经过多次试验和错误以及其他有类似问题的其他人的一点帮助后所做的事情(Qt Designer: could not find custom PyQt widget plugins and Custom QWidgets. How do I build/get the pyqt5 plugin for Qt Designer on马克?

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)
[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

输出的相关部分是这样的:

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"

并接近尾声

loaded library "Python.framework/Versions/3.7/Python"
ModuleNotFoundError: No module named 'PyQt5'
ModuleNotFoundError: No module named 'PyQt5'

无论如何,这就是我目前的状态。我不明白为什么 Qt Designer 找不到 PyQt5 模块,或者我还能尝试什么让它工作。

标签: pythonmacospyqtpyqt5qt-designer

解决方案


这是一个 ‍♂️ momemt 所以,我在 PyQt 参考指南上找到了这个,我不知何故忽略了它

  • 有关定义新 Qt 信号、插槽和属性及其插件的自定义小部件的简单但完整且完整记录的示例,请查看 PyQt5 源包的示例/设计器/插件目录

好的。做过某事。运行演示。它工作正常。将整个插件目录复制到其他地方。还好。所以我一定做了一些时髦的命名文件夹之类的东西。无论如何,现在我将致力于制作我自己的插件。因为愚蠢而沮丧的日子。但很高兴它有效。


推荐阅读