Qt sizeHint

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!