Initializing forms in PyQT

Torsten Marek shlomme at gmx.net
Fri Nov 21 07:08:00 EST 2003


tanner at rogers.com schrieb:
> I'm new to Python & PyQT so please bear with me.
> 
> I have a collection of QT Designer generated .ui files that will comprise
> the app interface. These are compiled using pyuic under Eric3.
> 
> My problem is that these .ui files are still evolving, and that my mods to
> the the forms' code get clobbered whenever I regenerate the .ui files.
> 
You are not supposed to put any code in there.
> Is there a method to embed python code in the actual .ui files themselves?
> Or is there an accepted method of having a form either manually or
> automatically initialize itself by calling a seperate file?
> 
> (The source code of Eric3 generally seems to organize related .ui files into
> subdirectories, each of which contains an __init__.py file. I'm not sure of
> the mechanics of how/when this file is handled.)
> 
> QT Designer generates stubs for SLOTS in it's code. I wish to over-ride
> replace the SLOTS fuctions through the use of my seperate file. Any help or
> comments is appreciated.
Yes, just use the signal/slot mechanism of Qt Designer to generate the 
slots (don't bother that they have C++ names) and just write your Python 
  (!, no C++-to-Python translation) into the editor of Designer. The 
functions are saved in the .ui.h file, which will be scanned by pyuic 
and added to your Python class. You might also want to add the -x switch 
to pyuic, so that it adds code to show the class (but I do not know 
whether this works, because I never used it).
But remember, the normal way of using those Qt Designer generated files 
is to subclass them, if you want to do something more complex.

If you have more questions, maybe you want to have a look at the 
PyQt/PyKDE mailing list (addresses are on the PyQt page, 
www.riverbankcomputing.co.uk)

greets

Torsten






More information about the Python-list mailing list