[PyQt] Force the ratio of a widget

Frédéric frederic.mantegazza at gbiloba.org
Wed Jan 14 13:46:28 GMT 2009


Hello,

I have a frame with 5 buttons in cross. I want this frame always be
square while resizing the window. This frame is in a horizontal layout,
and does not expand. So, it is always at its minimum width. But its
height can increase, leading to non-square ratio.

What I would like to do is to force the square ratio, by changing the
width as soon as the height changes. For that, I overwrited the
resizeEvent() method with the following:

def resizeEvent(self, event):
    size = event.size()
    if size.height() != size.width():
         self.resize(size.height(), size.height())

It works half the way; the frame remains square, but its parent (the
layout) does not resize, so I  can't see the entire frame. In fact, the
layout remains at the minimum width of the frame.

Any idea to correct this?

thanks,

--
   Frédéric



More information about the PyQt mailing list