Custom QWidgets. How do I build/get the pyqt5 plugin for Qt Designer on Mac?

会有一股神秘感。 提交于 2019-12-06 22:09:33

As my comment explained: the Qt designer plugin can be built via the reference link (SIP/PyQt5 via RiverBank and Qt src via Qt).

  • Make sure your Qt versions match, although Qt docs do say plugins of lower versions should work with Designers on higher versions, but I'm sure there's a limit.
  • Build inside a python venv, as suggested.
  • You'll need xtool dev pkg for building.
  • Everything built really easy for me.
  • This will place your pyqt5.dylib plugin right in your Qt/clang_64/plugins/designer folder (it will also build it in pyqt5 make folder)

At this point I expected things to work. The plugin shows that it loads fine inside Designer.

Some extra notes:

  • 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

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...

  • 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)
  • after that came, missing PyQt5.sip module
    • for this, I installed (pip install) pyqt5-sip and then put in in my PYTHONPATH

After that, everything finally worked and I could see my custom plugins inside Qt Designer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!