[PyQt] Sip: How to properly include from other files?

David Boddie david at boddie.org.uk
Fri May 18 01:06:26 BST 2007


On Thursday 17 May 2007 11:59:16 -0400, Jason Hihn wrote:

> Hi all, I seems to have been a crazy week. Anyway, the sample seems to be
> coming from the last read %Module definition. The docs were not clear that
> there should only be one of these per entire module, and not one per file.

That's probably a result of the way modules tend to be structured, with
the file that includes all the others also containing a %Module declaration.

> Anyway, it compiles and links. I'd like to thank all of you for your help
> this far.
>
> My next question is how I can get my class to be loaded by QFormBuilder
> when it loads a UI file at runtime? In my ui file it has a widget which was
> promoted in QDesigner to my AAA class. So I want it to create an AAA widget
> when it comes across one. I don't want to use uic.

Can't you use the uic module? Note that this isn't the same as the uic tool
that works with C++.

> Basically, I do the following:
> builder=QFormBuilder()
> f=QFile(uifile)
> f.open(QFile.ReadOnly)
> widget=builder.load(f, parent)

from PyQt4 import uic
f = QFile(uifile)
f.open(QFile.ReadOnly)
widget = uic.loadUi(f, parent)

> Then I use widget.findChild() to pick up the controls at runtime and hold a
> reference to them for connections, etc.
>
> In the builder.load() call is where I need it to be able to create my
> widget. I don't know where to begin. It seem QFormBuilder has a modifiable
> plug-in path (addPluginPath()) but I am unclear as to how Python/PyQt will
> interfere with it, and what mechanisms are there to deal with it.

If the widget is supplied by a wrapped C++ class in a shared library module -
which I think is the case for you - and if you use the uic module, then you
just need to make sure that this is on the PYTHONPATH or in site-packages.

For QFormBuilder, it's probably quite a different story. The addPluginPath()
function is there to help find C++ plugins, so it won't do anything to help
find your module containing the wrapped C++ classes.

David


More information about the PyQt mailing list