dvulanov
dvulanov

Reputation: 155

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

I want to be able to create my own custom widgets in Qt Designer using the pyqt5 plugin on my Mac!

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

( this tutorial was taken from https://www.ics.com/blog/integrating-python-based-custom-widget-qt-designer )

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?

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.

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.

Thanks for any help

Upvotes: 1

Views: 1541

Answers (1)

dvulanov
dvulanov

Reputation: 155

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.

Upvotes: 1

Related Questions