[PyKDE] Using custom components and Qt Designer with QWidgetFactory in PyQt

Truls A. Tangstad kerfue+pykde at herocamp.org
Wed Nov 3 20:26:02 GMT 2004

On Wed, Nov 03, 2004 at 03:50:25PM -0200, Gustavo Barbieri wrote:
> On Wed, 3 Nov 2004 17:55:49 +0100, Truls A. Tangstad
> <kerfue+pykde at herocamp.org> wrote:
> > We've almost fully converted to designing all dialogboxes and other
> > application windows in Qt Designer to use in our PyQt application, but
> > I've come into a difficulty with wanting to use custom widgets
> > created in Python with the Qt Designer designed dialogs.
> > 
> > I've noted a tutorial[1] doing just that by embedding python code into
> > the Comments field of the form, but that only seems to work when using
> > pyuic to create python-code from the .ui-files. We use QWidgetFactory
> > exclusively to generate the widgets runtime from the .ui-files, and
> > using pyuic would put us back into gui-design stoneage again (gui
> > mixed too much with other code, and hard to redesign components).
> > 
> > Is there a way to use Qt Designer to embed python-created components
> > into dialogs etc. when they are loaded with QWidgetFactory inty our
> > python application?
> > 
> > [1] - http://www.pycs.net/lateral/stories/27.html
> http://www.ic.unicamp.br/~ra008849/downloads/pyqt-tutorial.tar.bz2
> Is the rewite of that tutorial, but made right (instead of quick).
> There you can see how to do that. The problem is that you cannot see
> the preview or edit elements as before, but at least you keep things
> separated. You could use a pixmap to mimic your component.
> People that are writing another designer for qt/kde said they'll
> improve this area.
> http://www.kde-apps.org/content/show.php?content=14796

The tutorial goes a long way to convince me that it's possible to use
pyuic to keep .ui to .py conversion pretty transparent, and still keep
the .ui-file the first class source of the design. I think I had the
idea that using pyuic was something most people did once, then threw
it away and added the resulting .py-file to the source code.

I'm still more interested in a QWidgetFactory-solution though, where
the .ui-files can be loaded directly at runtime, and so you never have
to have a "compile"-step in the development cycle. 

Maybe a possible solution might be to create a QWidgetFactory
replacement that runtime uses pyuic and execs the result... if nothing
else this allows custom components specified in the Designer to be
created correctly since pyuic uses code from the Comments field which
QWidgetFactory ignores.

Truls A. Tangstad - <kerfue+pykde at h e r o c a m p.org>

More information about the PyQt mailing list