自定义QWidget.如何在Mac上为Qt Designer构建/获取pyqt5插件? [英] Custom QWidgets. How do I build/get the pyqt5 plugin for Qt Designer on Mac?
问题描述
我希望能够使用Mac上的pyqt5插件在Qt Designer中创建自己的自定义小部件!
I want to be able to create my own custom widgets in Qt Designer using the pyqt5 plugin on my Mac!
在我的Windows系统上,这很容易.我有/安装了pyqt5-tools,其中包含pyqt5.dll,并将其复制到Qt Designers插件目录(这些软件包均通过winPython安装).
On my windows system this is easy. I have/install pyqt5-tools, this contains pyqt5.dll and I copy this into the Qt Designers plugin directory (these packages were all installed via winPython).
- 我设置了PYQTDESIGNERPATH =.
- 在当前目录中,我有ledplugin.py和ledwidget.py
- 我启动Qt Designer并拖放自定义窗口小部件
(本教程摘自 https://www.ics.com/blog/integrating-python-based-custom-widget-qt-designer )
在Mac上,我无法确定pyqt5.dll的等效.dylib是什么?它是什么?我在哪里得到的?我该如何建造?
On my Mac, I can't figure out what the equivalent .dylib of pyqt5.dll is? What is it? Where do I get it? How do I build it?
我尝试:brew安装Qt Creator,它没有pyqt插件.我尝试:brew install pyqt5,创建:libpyqt5qmlplugin.dylib.我将其复制到Qt Designer插件目录中,并加载了插件,但它对我的.py插件/小工具文件似乎没有任何作用.
I try: brew install Qt Creator, that doesn't have the pyqt plugin. I try: brew install pyqt5, that creates: libpyqt5qmlplugin.dylib. I copy that into the Qt Designer plugin dir and the plugin loads, but it doesn't seem to do anything with my .py plugin/widget files.
如何在Mac上运行该软件?我要寻找的实际.dylib插件是什么?我什么都找不到.
How do I get this working on a Mac? What is the actual .dylib plugin I'm looking for? I can't find anything googling around.
感谢您的帮助
推荐答案
正如我的评论所述:可以通过引用链接(通过RiverBank的SIP/PyQt5和通过Qt的Qt src)构建Qt设计器插件.
As my comment explained: the Qt designer plugin can be built via the reference link (SIP/PyQt5 via RiverBank and Qt src via Qt).
- 请确保您的Qt版本匹配,尽管Qt文档确实说较低版本的插件应与较高版本的Designers配合使用,但我确定存在限制.
- 按照建议在Python venv中构建.
- 您将需要使用xtool dev pkg进行构建.
- 一切对我来说都很简单.
- 这会将您的pyqt5.dylib插件直接放在Qt/clang_64/plugins/designer文件夹中(还将在pyqt5 make文件夹中构建它)
在这一点上,我希望一切正常.该插件表明它可以在Designer中正常加载.
At this point I expected things to work. The plugin shows that it loads fine inside Designer.
一些注意事项:
- 从命令行运行可以帮助调试:Qt/clang_64/bin/Designer.app> show package>/MacOS/Designer(将其拖到终端以从命令行执行)
- 设置环境变量(>> export QT_DEBUG_PLUGINS = 1)将提供调试信息并显示很多内容,包括pyqt5.dylib可以很好地加载 小工具插件是两个文件:widget.py和widgetplugin.py文件,该文件向设计人员公开了小部件.此插件文件必须以"plugin.py"结尾
- widgetplugin.py文件可以位于许多地方:
- 在/[Designer App]/plugins/designer/python/ 中
- 在〜/user dir/.designer/plugins/python/ 中
- 在使用env var PYQTDESIGNERPATH选择的目录中
- running from command line can help with debugging: Qt/clang_64/bin/Designer.app > show package > /MacOS/Designer (drag this to a terminal to execute from command line)
- set an env variable (>>export QT_DEBUG_PLUGINS=1) will give debug info and show lots of stuff including that pyqt5.dylib loads fine
- widget plugins are two files: widget.py and the widgetplugin.py file that exposes the widget to designer. This plugin file MUST end with "plugin.py"
- widgetplugin.py files can reside in a number of places:
- in /[Designer App]/plugins/designer/python/
- in ~/user dir/.designer/plugins/python/
- in a directory of you choosing using env var PYQTDESIGNERPATH
但是,在这一点上,Designer仍然没有显示任何内容,并且我没有遇到任何错误.由于我只是构建pyqt5.dylib,所以我想我只是在其中放了一些打印语句,重新制作它并进行调试,以弄清为什么pyqt5插件可以很好地加载,但是我的自定义窗口小部件找不到了.
However, at this point still nothing showed in Designer and I had no errors to go by. Since I just built pyqt5.dylib, I figured I'd simply put a bunch of print statements in it, re-make it and debug to figure out why the pyqt5 plugin loaded fine, but my custom widgets were nowhere to be found...
- 第一个问题是无法加载python环境:
- 对于这个问题,我只是将我的(我使用brew)/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework复制到Qt/clang_64/lib(我确定有正确的PATH/您可以为此设置PYTHONPATH,我稍后会解决)
- first issue was trouble loading a python environment:
- for this issue, I simply copied my (I use brew) /usr/local/Cellar/python/3.7.2/Frameworks/Python.framework to Qt/clang_64/lib (I'm sure there's a proper PATH/PYTHONPATH you can set for this, I'll figure that out later)
- 为此,我安装了(pip install)pyqt5-sip,然后放入了我的PYTHONPATH
此后,一切都终于成功了,我可以在Qt Designer中看到我的自定义插件.
After that, everything finally worked and I could see my custom plugins inside Qt Designer.
这篇关于自定义QWidget.如何在Mac上为Qt Designer构建/获取pyqt5插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!