[PyQt] Using custom widgets with QtDesigner?

David Boddie david at boddie.org.uk
Mon May 21 20:00:23 BST 2007


On Monday 21 May 2007 02:22:09 +0200, Karlo Lozovina wrote:

> Hi all, I'm a newbie in PyQt(4) world, convert from wxWidgets/wxPython
> combo.

Welcome to our world! :-)

> I've done some simple applications in the following manner: I design
> my GUI using Designer and convert single .ui file to Python code with
> pyuic4, then I usually make a class that inherits a
> Ui_SomethingSomething class, and do all the work in that inherited
> class. And that workes just well for small apps, and one (somewhat
> large) class.

OK. That's good to hear.

> Now I want to make an application that has a more complex UI, with
> widgets responding to many custom signals. It should look like this:
> one QTabWidget with a dozen of tabs, in each of the tabs a lot of
> QTreeWidgets, QPushButtons, QLineEdits, and so on for all the tabs.

I imagine that it might not be convenient to use Designer's built-in tab
editor if you have so many tabs.

> I would really like if it could be possible to somehow design those tabs
> separately from the main UI, and put each of them in separate .ui
> files and Python files. Also, It would be great if I could combine
> those tabs in Designer, and not have to manually code that part.

It might be difficult to do what you're asking just with standard widgets,
if I understand you correctly. You seem to want to include the contents of
several .ui files in a tab widget and be able to preview the finished
tab widget in Designer, and there's no obvious mechanism for doing that
apart from using custom widget plugins.

Note that, when I say "plugin", I'm not suggesting that you learn C++. It's
possible to add custom widgets to Designer without having to use a C++
compiler. :-)

It should be possible for you to create simple plugins that show the contents
of .ui files for the pages in the tab widget. These could be included in the
application as normal widgets, and would be processed correctly by pyuic4.
The only extra code you need to write is to declare the widgets to Designer.

Take a look in the examples/designer/plugins directory of the PyQt4 package
to see how this can be done.

David


More information about the PyQt mailing list