[PyQt] Force the ratio of a widget

Frédéric frederic.mantegazza at gbiloba.org
Wed Jan 14 16:10:30 GMT 2009


Le 14/1/2009, "Doug Bell" <dougb at bellz.org> a écrit:

>Try overriding QLayoutItem.hasHeightForWidth() and
>QLayoutItem.heightForWidth(w) in a custom layout.

It does not seems to work :o( The layout does not remains sqaure...

Here is part the code involved:

def hasHeightForWidth(self):
    return True

def heightForWidth(self, width):
    return width

...
mainWindow = uic.loadUi("mainWindow.ui")
mainWindow.myGridLayout.heightForWidth = \
    types.MethodType(heightForWidth, mainWindow.myGridLayout)
mainWindow.myGridLayout.hasHeightForWidth = \
    types.MethodType(hasHeightForWidth, mainWindow.myGridLayout)
...

Could it come from the fact I'm using the uic module to load my GUI? Or
because I dynamically rebind the methods (from a python point of view,
it works, as I checked that my methods are called)?

BTW, is it possible to do the opposite, setting the width from the
height? I didn't find any methods, which is strange from Qt...

--
   Frédéric



More information about the PyQt mailing list