Qt sizeHint

Just for the record I am sending Sebastian’s message to the list

···

---------- Forwarded message ----------
From: Sebastian Voigt <>

Date: 2 February 2011 17:23
Subject: Re: [Matplotlib-users] Qt sizeHint
To: Fernando Cosso <>

Hi Fernando,

I changed your MplCanvas class. The sizeHint function is not needed,

if this produces the desired baviour:

class MplCanvas(FigureCanvas):

    def __init__(self):

        self.fig = Figure(linewidth=0)

        FigureCanvas.__init__(self, self.fig)

        self._text = r'$\alpha > \beta$'

        self._g = self.fig.suptitle(self._text)

self.renderer = self.get_renderer()

        bbox = self._g.get_window_extent(self.renderer)

        self.setFixedHeight(bbox.height)

        self.setFixedWidth(bbox.width)

Ahoi,

    Sebastian

Am 02.02.2011 22:41, schrieb Fernando Cosso:

Dear List

  I am a really newbie in Python, Matlibplot and Qt but I am still

making huge progress in my project.

  I am now stuck trying to make a custom widget for Qt Desginer

using matplotlib to display a Latex formula. I would like the
Latex label to provide Qt with the correct size, with enough space
to fit the text and nothing else.

  I know from Qt that I should re implement the sizeHint method but

I don’t know how to get the minimum size.

  I tried the get_window_extent() but I need a renderer for that.



  Any idea?



  This is what I have so far



  from PyQt4 import QtGui

  from PyQt4 import QtCore

  from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg

as FigureCanvas

  from matplotlib.figure import Figure



  class MplCanvas(FigureCanvas):

      def __init__(self):

          self.fig = Figure(linewidth=0)

          FigureCanvas.__init__(self, self.fig)

          self._text = r'$\alpha > \beta$'

          self._g = self.fig.suptitle(self._text)

          FigureCanvas.setSizePolicy(self,

                                     QtGui.QSizePolicy.Expanding,

                                     QtGui.QSizePolicy.Expanding)

          FigureCanvas.updateGeometry(self)



      def sizeHint(self):



          print(self._g.get_window_extent())



          return QtCore.QSize(something1, something2)





  class Plot2D(QtGui.QWidget):

      def __init__(self, parent = None):

          QtGui.QWidget.__init__(self, parent)

          self.canvas = MplCanvas()

          self.vbl = QtGui.QVBoxLayout()

          self.vbl.addWidget(self.canvas)

          self.setLayout(self.vbl)



  if __name__ == "__main__":



      import sys

      app = QtGui.QApplication(sys.argv)

      widget = Plot2D()

      widget.show()

      sys.exit(app.exec_())



  Anything is appreciated!


Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires February 28th, so secure your free ArcSight Logger TODAY! http://p.sf.net/sfu/arcsight-sfd2d



Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users