Matplotlib+Qt. Problem with plot resizing

Hi, list!

I have a problem with embedding matplotlib in Qt based GUI. I read manual and look at
example "embedding_in_qt4.py". I create GUI with QtDesigner. For matplotlib plot I create
a QWidget. Then in runtime I embed a matplotlib plot im my GUI, into this QWidget. Here some code:

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure

class dlgStatist( QDialog, Ui_dlgStatistics ):
  def __init__( self, iface ):
    QDialog.__init__( self )
    self.iface = iface
    self.setupUi( self )
    
    # prepare figure
    self.figure = Figure()
    #self.figure.set_figsize_inches( ( 4.3, 4.2 ) )
    self.axes = self.figure.add_subplot( 111 )
    self.figure.suptitle( "Frequency distribution", fontsize = 12 )
    self.axes.grid( True )
    self.canvas = FigureCanvas( self.figure )
    self.canvas.setParent( self.widgetPlot )
                .......

All looks fine, but when user change window size, matplotlib plot doesn't resized. I try to set
SizePolicy to matplotlib figure (as explained in example) but this don't help.
Where is my mistake and can anyone give me a little example how to embed matplotlib plot
in GUI created with QtDesigner? I really need resizible plot into Qt dialog.

Sorry for my bad English, I'm Ukrainian.

Python 2.5.4
PyQT 4.4.3
numpy 1.3.0
matplotlib 0.98.5.3

Alexander Bruy

-- реклама -----------------------------------------------------------
Создай свой сайт бесплатно! www.hostpro.ua

2009/7/17 Alexander Bruy <voltron@…2684…>

Hi, list!

I have a problem with embedding matplotlib in Qt based GUI. I read manual and look at

example “embedding_in_qt4.py”. I create GUI with QtDesigner. For matplotlib plot I create

a QWidget. Then in runtime I embed a matplotlib plot im my GUI, into this QWidget. Here some code:

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas

from matplotlib.figure import Figure

class dlgStatist( QDialog, Ui_dlgStatistics ):

    def __init__( self, iface ):

            QDialog.__init__( self )

            self.iface = iface

            self.setupUi( self )



            # prepare figure

            self.figure = Figure()

            #self.figure.set_figsize_inches( ( 4.3, 4.2 ) )

            self.axes = self.figure.add_subplot( 111 )

            self.figure.suptitle( "Frequency distribution", fontsize = 12 )

            self.axes.grid( True )

            self.canvas = FigureCanvas( self.figure )

            self.canvas.setParent( self.widgetPlot )

            .......

All looks fine, but when user change window size, matplotlib plot doesn’t resized. I try to set

SizePolicy to matplotlib figure (as explained in example) but this don’t help.

Where is my mistake and can anyone give me a little example how to embed matplotlib plot

in GUI created with QtDesigner? I really need resizible plot into Qt dialog.

Sorry for my bad English, I’m Ukrainian.

Python 2.5.4

PyQT 4.4.3

numpy 1.3.0

matplotlib 0.98.5.3

Please post a short, complete, self-contained script demonstrating the problem.

I create a small example, see attachment. There is a simple dialog with QWidget, at which
matplotlib plot is drawn. When dialog resized the plot don't change it's size.
I'm would be grateful for an indication of my errors and working example.

Regards,
  Alexander Bruy

-- реклама -----------------------------------------------------------
Создай свой сайт бесплатно! www.hostpro.ua

···

2009/17/07 Darren Dale <dsdale24@...287...> wrote:

Please post a short, complete, self-contained script demonstrating the
problem.

2009/7/19 Alexander Bruy <voltron@...2684...>:

I create a small example, see attachment.

no attachment :slight_smile:

···

--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi