[PyQt] Calling Custom Widget from Designer Code

Phil Thompson phil at riverbankcomputing.com
Wed Jan 30 19:39:47 GMT 2008


On Wednesday 30 January 2008, Clowers, Brian H wrote:
> So I'm stumped.  I've created a GUI in designer and have successfully
> added a matplotlib canvas to a mainwindow by promoting a custom widget
> class.  I've named the canvas "mpl_widget".  Now my problem is the
> following:  I would like to be able to be able to update and clear the
> matplotlib canvas but I cannot seem to access it when I building the
> GUI.  I've shown my problem below.  Basically I'd like to access the
> widget and by extension the normal functions associated with the
> matplotlib API.  Any ideas on how to make this work?  It would seem
> silly to have to define all of the specific functions to access the
> matplotlib API in the custom widget class.  Any help would be greatly
> appreciated.  (To run the attached example files you'll need matplotlib,
> numpy, and obviously PyQt4)
>
> Cheers,
>
> Brian
>
> class Main_Window(QMainWindow):
>     def __init__(self):
>         QMainWindow.__init__(self)
>         self.ui = Ui_MainWindow()
>         self.ui.setupUi(self)
>
>
>         x = N.arange(0,10, 0.2)
>         y = N.sin(x)
>         ###The Problem Area###
>         self.mpl_widget.ax.plot(x,y)
>         ######################
>
>  <<Subplot.py>>  <<ui_Subplot.py>>  <<mpl_custom_widget.py>>

mpl_widget is an attribute of self.ui, not self.

Phil


More information about the PyQt mailing list