Using matplotlib in Qt4/Qt4 Designer

If you look at the following link it may help you get started:
What you need to do is make a ui with designer and then place a widget where ever you’d like. From there make sure you right click on the widget and select horizontal layout (This is to make sure the widget occupies the GUI fully). Then right click on the widget and click on “Promote to.” From there what you need to do is select QWidget as the base class name. Using the example file I pointed to above you would put in “MPL_Widget” for the “Promoted class name” followed by “mpl_custom_widget” in the header file: field. Click promote and you should be done. Be sure to place the in the directory of your converted ui file
(i.e. the one that was created using pyuic4). Now from your main window file (the one that controls adding data to the plot) you simply need to use the name of widget you promoted followed by etc. to manipulate the plot. For example if your promoted widget name is “plotWidget” you should be able to access the mpl API using “,y,*kwargs)” where x,y, and *kwargs are the appropriate numpy arrays and keyword arguments.
I hope that helps, and let me know if you need anythinge else.
–ps if you need the toolbar using the latest version of matplotlib you may have to uncomment some of the code and remove some of the arguments that locate the toolbar in the ui.


— On Wed, 8/6/08, Ewald Zietsman <ewald.zietsman@…287…> wrote:

From: Ewald
Zietsman <ewald.zietsman@…287…>
Subject: Re: [Matplotlib-users] Using matplotlib in Qt4/Qt4 Designer
To: clowersb@…9…
Date: Wednesday, August 6, 2008, 2:47 PM


Sorry for replying only now. Thanks for the link. I’m very new to GUI programming. Can you please explain to me how to promote a mpl widget from a regular widget? In qt3 it was possible to create a mpl widget in the form by telling the form to import your module containing the widget definition (a python class). I’m working with the qwt widgets at the moment and although they’re supposed to be fast, they don’t seem to be much faster than mpl, unless I’m doing something funny which is possible. I’m not really a programmer, but I like to tinker in order to learn as much as I can so that I can create programs to solve astrophysical problems/analyse data more efficiently (less time/less code).



On Wed, Aug 6, 2008 at 12:46 AM, B Clowers <clowersb@…9…> wrote:


It is very much a work in progress (and poorly named) but you can check out a project of mine:

I created a custom matplotlib widget that you can promote from a regular widget in Designer. I hope it helps, let me know if you have any questions. The ui files are also included in the SVN. One thing to note there was a recent change to the Qt backend that altered the nature of the toolbar so you may want to comment that part out if you are using the latest matplotlib. If it is a must have I think I’m sure I could update the code when I find some time (Currently, I’m using v 0.91 I believe). Good luck.



— On Tue, 8/5/08, Ewald Zietsman <ewald.zietsman@…287…> wrote:

From: Ewald Zietsman <ewald.zietsman@…287…>

Subject: [Matplotlib-users] Using matplotlib in Qt4/Qt4 Designer
Date: Tuesday, August 5, 2008, 10:06 AM

Hi All,

I’d like to use a matplotlib widget in a GUI app I’m working on. I have tried qwt but I know matplotlib a lot better and would like to use it instead. Is there anybody who have done this before? More specifically, does anyone know how to add a matplotlib widget as a custom widget in qt4 designer?

Any help will be greatly appreciated,

Ewald Zietsman

This SF.Net email is sponsored by the Moblin Your Move Developer’s

Build the coolest Linux based applications with Moblin SDK & win great
Grand prize is a trip for two to an Open Source event anywhere in the world

Matplotlib-users mailing list