【发布时间】:2019-08-29 04:34:47
【问题描述】:
我想使用 python(3.7 和 pyqt5)为 Qt Designer 制作一个自定义小部件插件。一切都应该工作,但它没有出现在 Qt Designer 中。
这是我经过多次试验和错误以及其他有类似问题的人的一点帮助(Qt Designer: could not find custom PyQt widget plugins 和 Custom QWidgets. How do I build/get the pyqt5 plugin for Qt Designer on Mac?)到目前为止所做的工作
我从 Qt 网站安装了 Qt Designer (Creator) 5.13。
我从源代码而不是 pip 安装了 SIP (4.9.18) 和 PyQt5 (5.13.0),因为有必要获取必要的 libpyqt5.dylib 文件(Mac 没有 pyqt5-tools)。我把这个文件放在/Users/[user]/Qt/5.13.0/clang_64/plugins/designer目录下
我只想在制作自己的插件之前正确设置。于是,我从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)
我运行了 plugins.py。 Qt Designer 正确打开,当我检查 Designer-->About Plugins 时,我在 Loaded Plugins 中看到 libpyqt5.dylib。但是,PyAnalogClock 小部件不在其中,插件小部件不在左侧小部件框中。
我尝试通过从终端设置环境变量来进行调试,如下所示:
[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'
- 当我没有从命令行导出 PYQTDESIGNERPATH 和 PYTHONPATH 时,这个错误消失了。但是当然,Qt 不知道文件在哪里。
无论如何,这就是我目前的状态。我不明白为什么 Qt Designer 找不到 PyQt5 模块,或者我还能尝试什么让它工作。
【问题讨论】:
-
自从我终于弄清楚如何在设计器上使用自定义插件已经过去了很长时间,如果我不完全确定,请原谅我。我没有设置 PYQTDESIGNERPATH,但我将这些插件 in 设置为自定义小部件目录(设置为 PYTHONPATH),其中有一个名为
plugins5的子目录(包含插件)和一个名为widgets的子目录(包含实际的自定义小部件)。
标签: python macos pyqt pyqt5 qt-designer