Strange issue when using Matplotlib with PyQt4

Hello,

I tried to embed a Matplotlib FigureCanvas into a QTabWidget.
But at the first start of my script - the main.py in the attatched example -
the widget in the Tab is incorrectly sized.
If I embed the FigureCanvas in a QTabWidget the widget is to big, but if I put
it in a QWidget it is shown correctly.

Sorry, but this is my first try of Matplotlib and I don't know what I could
have done wrong - maybe this is just because it's nearly 3 o'clock in the
night and I'm to tired to find this mistake. :wink:

Thanks for help,
Lukas

PyQt4_MPL.tar.bz2 (2.23 KB)

Lukas Hetzenecker a écrit :

I tried to embed a Matplotlib FigureCanvas into a QTabWidget.
But at the first start of my script - the main.py in the attatched example - the widget in the Tab is incorrectly sized.
If I embed the FigureCanvas in a QTabWidget the widget is to big, but if I put it in a QWidget it is shown correctly.
  

I'm not sure that is a pure MatPlotLib issue. Have you try with a big standard widget instead of the FigureCanvas ?

Christophe

Hello,

I've tried to resize the QTabWidget, I've searched for examples on the
internet, added a QTabWidget and used this as the Mainwindows central widget -
but exactly the same happened.

It works if I replace the FigureCanvas with a Qt Widget - for example a text
edit or a QWebView.

···

Am Sonntag 19 Juli 2009 11:54:12 schrieb projetmbc:

Lukas Hetzenecker a écrit :
> I tried to embed a Matplotlib FigureCanvas into a QTabWidget.
> But at the first start of my script - the main.py in the attatched
> example - the widget in the Tab is incorrectly sized.
> If I embed the FigureCanvas in a QTabWidget the widget is to big, but if
> I put it in a QWidget it is shown correctly.

I'm not sure that is a pure MatPlotLib issue. Have you try with a big
standard widget instead of the FigureCanvas ?

Christophe

Hm.. I added a resize() after the show():

class Plot_tab(QTabWidget, tab):
    def __init__(self):
        super(Plot_tab, self).__init__()
        self.setupUi(self)

        self.show()
        self.resize(self.size().width()+1, self.size().height()+1)
        self.resize(self.size().width()-1, self.size().height()-1)

if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)

    plot_t = Plot_tab()

    sys.exit(app.exec_())

Now it works, but I really want to know why..?
Is there a way to avoid this ugly workaround?

Thanks,
Lukas

···

Am Sonntag 19 Juli 2009 12:58:53 schrieb Lukas Hetzenecker:

Hello,

I've tried to resize the QTabWidget, I've searched for examples on the
internet, added a QTabWidget and used this as the Mainwindows central
widget - but exactly the same happened.

It works if I replace the FigureCanvas with a Qt Widget - for example a
text edit or a QWebView.

Am Sonntag 19 Juli 2009 11:54:12 schrieb projetmbc:
> Lukas Hetzenecker a écrit :
> > I tried to embed a Matplotlib FigureCanvas into a QTabWidget.
> > But at the first start of my script - the main.py in the attatched
> > example - the widget in the Tab is incorrectly sized.
> > If I embed the FigureCanvas in a QTabWidget the widget is to big, but
> > if I put it in a QWidget it is shown correctly.
>
> I'm not sure that is a pure MatPlotLib issue. Have you try with a big
> standard widget instead of the FigureCanvas ?
>
> Christophe

---------------------------------------------------------------------------
--- Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Sorry for annoying you, but I attatched a new example to this message: I've
rewritten the PyQt4-example from the website to draw the Figure in a tab
widget. The same happens :wink:

matplotlib_examples.zip (3.37 KB)

···

Am Montag 20 Juli 2009 21:58:46 schrieb Lukas Hetzenecker:

Hm.. I added a resize() after the show():

class Plot_tab(QTabWidget, tab):
    def __init__(self):
        super(Plot_tab, self).__init__()
        self.setupUi(self)

        self.show()
        self.resize(self.size().width()+1, self.size().height()+1)
        self.resize(self.size().width()-1, self.size().height()-1)

if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)

    plot_t = Plot_tab()

    sys.exit(app.exec_())

Now it works, but I really want to know why..?
Is there a way to avoid this ugly workaround?

Thanks,
Lukas

Am Sonntag 19 Juli 2009 12:58:53 schrieb Lukas Hetzenecker:
> Hello,
>
> I've tried to resize the QTabWidget, I've searched for examples on the
> internet, added a QTabWidget and used this as the Mainwindows central
> widget - but exactly the same happened.
>
> It works if I replace the FigureCanvas with a Qt Widget - for example a
> text edit or a QWebView.
>
> Am Sonntag 19 Juli 2009 11:54:12 schrieb projetmbc:
> > Lukas Hetzenecker a écrit :
> > > I tried to embed a Matplotlib FigureCanvas into a QTabWidget.
> > > But at the first start of my script - the main.py in the attatched
> > > example - the widget in the Tab is incorrectly sized.
> > > If I embed the FigureCanvas in a QTabWidget the widget is to big, but
> > > if I put it in a QWidget it is shown correctly.
> >
> > I'm not sure that is a pure MatPlotLib issue. Have you try with a big
> > standard widget instead of the FigureCanvas ?
> >
> > Christophe
>
> -------------------------------------------------------------------------
>-- --- Enter the BlackBerry Developer Challenge
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full
> prize details at: http://p.sf.net/sfu/Challenge
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users

---------------------------------------------------------------------------
--- Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

In your original post, you said:

"the widget in the Tab is incorrectly sized.
If I embed the FigureCanvas in a QTabWidget the widget is to big, but if I put
it in a QWidget it is shown correctly."

Could you be more specific? What does "incorrectly sized" mean? What
do you mean by the widget is "too big", as opposed to "shown
correctly"? Is this really a PyQt issue, or is it specific to
matplotlib? If the latter we should continue the discussion on the mpl
mailing list instead of cross-posting.

Darren

···

On Tue, Jul 21, 2009 at 12:06 PM, Lukas Hetzenecker<LuHe@...1843...> wrote:

Sorry for annoying you, but I attatched a new example to this message: I've
rewritten the PyQt4-example from the website to draw the Figure in a tab
widget. The same happens :wink:

Hello,
the matplotlib widget has an incorrect default size (the left one in the
attatched screenshot).
I couldn't reproduce this behaviour with any Qt widget - so it seems that this
is specific to matplotlib. But as I'm not really sure of the cause I posted it
to both lists.

Lukas

screen5.png

···

Am Dienstag 21 Juli 2009 20:31:55 schrieb Darren Dale:

On Tue, Jul 21, 2009 at 12:06 PM, Lukas Hetzenecker<LuHe@...1843...> wrote:
> Sorry for annoying you, but I attatched a new example to this message:
> I've rewritten the PyQt4-example from the website to draw the Figure in a
> tab widget. The same happens :wink:

In your original post, you said:

"the widget in the Tab is incorrectly sized.
If I embed the FigureCanvas in a QTabWidget the widget is to big, but if I
put it in a QWidget it is shown correctly."

Could you be more specific? What does "incorrectly sized" mean? What
do you mean by the widget is "too big", as opposed to "shown
correctly"? Is this really a PyQt issue, or is it specific to
matplotlib? If the latter we should continue the discussion on the mpl
mailing list instead of cross-posting.

Darren

Please keep in mind that these are both heavily subscribed lists. It
would be better not to burden the pyqt list with suspected matplotlib
problems.

What versions of qt, pyqt and matplotlib are you using? I have
qt-4.5.2, PyQt-4.5.2, and an up to date matplotlib svn checkout, and I
don't see a problem. Maybe recent changes in svn have fixed the
problem, you could try downloading backend_qt4.py and
backend_qt4agg.py from
http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/backends/
if you can't build an svn checkout.

Darren

···

On Tue, Jul 21, 2009 at 2:47 PM, Lukas Hetzenecker<LuHe@...1843...> wrote:

Hello,
the matplotlib widget has an incorrect default size (the left one in the
attatched screenshot).
I couldn't reproduce this behaviour with any Qt widget - so it seems that this
is specific to matplotlib. But as I'm not really sure of the cause I posted it
to both lists.

Forgot the attachment.

lh_test.png

···

On Tue, Jul 21, 2009 at 3:01 PM, Darren Dale<dsdale24@...287...> wrote:

On Tue, Jul 21, 2009 at 2:47 PM, Lukas Hetzenecker<LuHe@...1843...> wrote:

Hello,
the matplotlib widget has an incorrect default size (the left one in the
attatched screenshot).
I couldn't reproduce this behaviour with any Qt widget - so it seems that this
is specific to matplotlib. But as I'm not really sure of the cause I posted it
to both lists.

Please keep in mind that these are both heavily subscribed lists. It
would be better not to burden the pyqt list with suspected matplotlib
problems.

What versions of qt, pyqt and matplotlib are you using? I have
qt-4.5.2, PyQt-4.5.2, and an up to date matplotlib svn checkout, and I
don't see a problem. Maybe recent changes in svn have fixed the
problem, you could try downloading backend_qt4.py and
backend_qt4agg.py from
http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/backends/
if you can't build an svn checkout.

Hello,
Yes, the problem was really related to my version of matplot: i used matplot
0.98.5.2-4.fc11 before.
I tried it with the latest svn revision (r7279) and it worked.

Thanks,
Lukas

···

Am Dienstag 21 Juli 2009 21:02:03 schrieb Darren Dale:

On Tue, Jul 21, 2009 at 3:01 PM, Darren Dale<dsdale24@...287...> wrote:
> On Tue, Jul 21, 2009 at 2:47 PM, Lukas Hetzenecker<LuHe@...1843...> wrote:
>> Hello,
>> the matplotlib widget has an incorrect default size (the left one in the
>> attatched screenshot).
>> I couldn't reproduce this behaviour with any Qt widget - so it seems
>> that this is specific to matplotlib. But as I'm not really sure of the
>> cause I posted it to both lists.
>
> Please keep in mind that these are both heavily subscribed lists. It
> would be better not to burden the pyqt list with suspected matplotlib
> problems.
>
> What versions of qt, pyqt and matplotlib are you using? I have
> qt-4.5.2, PyQt-4.5.2, and an up to date matplotlib svn checkout, and I
> don't see a problem. Maybe recent changes in svn have fixed the
> problem, you could try downloading backend_qt4.py and
> backend_qt4agg.py from
> http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/
>lib/matplotlib/backends/ if you can't build an svn checkout.

Forgot the attachment.