[PyQt] Defining a custom slot in Designer
David Boddie
david at boddie.org.uk
Sat Jan 17 20:31:03 GMT 2009
On Sat Jan 17 17:19:44 GMT 2009, Henrik Pauli wrote:
> I was messing around in Designer today and I wanted to add my QMainWindow
> a new slot. The ui file has it, but the moment I try to loadUi it, I get
> the following:
>
> Traceback (most recent call last):
> File "./testclient.py", line 11, in <module>
> w = uic.loadUi("testclient.ui")
> File "/usr/lib/python2.6/site-packages/PyQt4/uic/__init__.py", line 106,
> in loadUi
> return loader.DynamicUILoader().loadUi(uifile, baseinstance)
[...]
> File
> "/usr/lib/python2.6/site-packages/PyQt4/uic/Loader/qobjectcreator.py", line
> 75, in getSlot
> return getattr(object, slotname)
> AttributeError: executeCommand
>
> So how do I add this to my widget?
How did you add the slot to the testclient.ui file?
> Of course, I could work around this by doing all of it in python instead of
> Designer, but I wonder if this is possible at all.
You could use auto-connection to connect signals from objects in the .ui
file to slots you define in a Python implementation, but you need to use
pyuic4 to generate code for a class, and derive a new subclass from this in
Python. The new slots also have to follow a naming convention.
http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections
I'm not aware of a mechanism that lets you add slots to .ui files loaded
at run-time, unless you use uic.loadUiType() to create a widget class from
which you can derive a new subclass . You would presumably be able to write
the code for the new slots in the subclass.
Maybe you can give some more information about what you're trying to do.
David
More information about the PyQt
mailing list