1

I would like to make a custom widget plugin for Qt Designer using python (3.7 with pyqt5). Everything should work, but it doesn't show up in 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?)

  • I installed Qt Designer (Creator) 5.13 from the Qt website.

  • 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). I put this file in the /Users/[user]/Qt/5.13.0/clang_64/plugins/designer directory

  • 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:

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. Qt Designer opens correctly, and when I checked the Designer-->About Plugins I see libpyqt5.dylib inside Loaded Plugins. However, the PyAnalogClock widget was not inside of it and the plugin widget was not in the left-side widget box.

  • 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'
  • When I did not export PYQTDESIGNERPATH and PYTHONPATH from the command line, this error disappeared. But of course, then Qt doesn't know where the files are.

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
RIKEN IAD
  • 51
  • 4
  • A long has passed since I finally figured out how to use custom plugins on designer, so forgive me if I'm not completely sure. I've not set the PYQTDESIGNERPATH, but I got those plugins *in* a custom widget directory (set as PYTHONPATH), with a subdirectory named `plugins5` (containing the plugins) and anothe subdirectory named `widgets` (containing the actual custom widgets). – musicamante Aug 29 '19 at 05:15

1 Answers1

1

here is an ‍♂️ momemt So, I found this on the PyQt reference guide which I had somehow overlooked

  • For a simple but complete and fully documented example of a custom widget that defines new Qt signals, slots and properties, and its plugin, look in the examples/designer/plugins directory of the PyQt5 source package

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
RIKEN IAD
  • 51
  • 4
  • 1
    I know that frustration, I spent days to get it working, but that was a long time before I began to actively contribute here on SO. I remember that I used the pyqt plugin example as a source for it (maybe the same you're using, the qt quarterly 26), but too much time has passed since then and I really haven't time to walk back those steps right now. If you can get it working, it would be a very good contribution to edit this answer explaining what you did. – musicamante Aug 29 '19 at 07:15
  • I would very much appreciate some explanations, and an example of how you did it :) – matthieu Mar 10 '22 at 04:23
  • @musicamante I am trying https://www.ics.com/blog/integrating-python-based-custom-widget-qt-designer on ubuntu using the the examples/designer/plugins directory of the PyQt5 source package, the example works fine and I can get custom widget LedWidget inside PyQt Designer. But there is a glitch I cannot get the same thing working when I try to open PyQtDesigner from inside a virtualenv, any clue about what could be wrong ? – pippo1980 May 10 '22 at 23:08
  • @pippo1980 what "glitch"? Note that if you are on a venv, the plugins path must be valid for that env (or the plugin directory should be added to it). Please be more specific. – musicamante May 11 '22 at 00:11
  • In the example the plugin and the customwidget.py are passed to QProcess as env variables and designer is started in that QProcess, what happens is that qdesigner starts but no custom widget here, while it does show the custom widget when run outside the virtualenv. Need to find a copy of PyQT5 source to point you to that script: here github.com/baoboa/pyqt5/blob/master/examples/designer/plugins/… – pippo1980 5 mins ago – pippo1980 May 11 '22 at 07:24
  • https://github.com/baoboa/pyqt5/blob/master/examples/designer/plugins/plugins.py better – pippo1980 May 11 '22 at 09:01
  • mmmh could it be related to the fact that in ubuntu, designer is not installed togheter wit PyQt5 (doing pip install PyQt5) ???? the : /VirtualenviromentsContainer/VirPyQt5/lib/pythonX.X/site-packages/PyQt5/Qt5/bin required by the script doesnt actually exist so I copied the bin from directory /usr/lib/qt5/bin ... not a smart move I guess – pippo1980 May 11 '22 at 09:52
  • yep its like if I install PyQT5 in my virtual env with pip install pyqt5-tools I get an updated version compared to designer invoked by 'designer', problem is that in both normal env and virtualenviroment 'designer' will launch the system installed designer and not the one installed via pip in my virtualenviroment – pippo1980 May 11 '22 at 10:05
  • I'll try mangling # Start Designer. designer = QProcess() designer.setProcessEnvironment(env) designer_bin = QLibraryInfo.location(QLibraryInfo.BinariesPath) if sys.platform == 'darwin': designer_bin += '/Designer.app/Contents/MacOS/Designer' else: designer_bin += '/designer' designer.start(designer_bin) in the script – pippo1980 May 11 '22 at 10:07
  • think I'll need to modify plugin.py using help from https://stackoverflow.com/questions/1871549/determine-if-python-is-running-inside-virtualenv – pippo1980 May 11 '22 at 12:04
  • nope designer from pyqt5-tools uses different way to load custom widgets, just uses : pyqt5-tools designer -p PATH_to_both_widget.py_widgetplugin.py – pippo1980 May 11 '22 at 22:43
  • if try to use global Designer , it'll start in a QProcess but the custom widgets won't show up – pippo1980 May 12 '22 at 14:57