[英]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'
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参考指南上发现了这个,但我却以某种方式忽略了它
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.