I use this script to start qt designer with my custom widgets (in Python 3) visible:
#!/usr/bin/env python3
import os, sys, subprocess
curDir = os.path.dirname(os.path.abspath(__file__))
params = list(sys.argv) # copy list
params[0] = 'designer' # "designer-qt4" on Linux
widgetsDir = os.path.join(curDir, 'wic', 'widgets')
# add search path for custom widgets and plugins for designer
os.putenv('PYQTDESIGNERPATH', widgetsDir)
subprocess.Popen(params)
But it looks like designer is using python 2.7 to use the widget plugins:
vic@ubuntu:~/wic$ python3 qt_designer.pyw
vic@ubuntu:~/wic$ File "/home/vic/wic/wic/widgets/w_date_edit_plugin.py", line 63
app.exec()
^
SyntaxError: invalid syntax
How to instruct designer to use Python 3, not Python 2?
I use Kubuntu 11.10, KDE 4.7.2, python3.2 and python2.7, PyQt v4.8.5 compiled for Python 3
It looks like PyQt does not allow for side-by-side installation of the designer plugin that handles custom widgets (
libpythonplugin.so). So there will normally be a single plugin linked against either python2, or python3, but not both.It would appear that Kubuntu currently installs the python2 version of the plugin (on my linux system, it’s the other way around). If you want a python3 version of the plugin, just compile a replacement from source.
EDIT
To compile a replacement, first ensure you have the
sippackages installed. I am no expert on ubuntu, but I think you will need thepython-sip-devandpython3-sip-devpackages (plus any dependencies, of course).Next, download the PyQt4 sources that match the version installed on your system. I was able to find some ubuntu pyqt source packages here.
Now unpack the tarball, cd into the resulting source directory (looks like it should be
PyQt-x11-gpl-4.8.5for Kubuntu 11.10), and then configure the build using python3:If that completes without error, build it (but do not install it):
Using the above configuration options it takes about 5 mins to compile pyqt on my old i686-AMD64-X2-6000 system. Once complete, the
libpythonplugin.soplugin should be in thePyQt-x11-gpl-4.8.5/designerdirectory.You can now backup and remove the existing plugin (on my system it’s in the
/usr/lib/qt/plugins/designerdirectory), and copy over your new plugin.