PyQt - How to prevent a dialog being resized?

David Boddie dboddie at trolltech.com
Tue Apr 1 15:42:07 CEST 2008


On Apr 1, 12:12 am, Kelie <kf9... at gmail.com> wrote:

> > My question is as subject. I tried something like this and it doesn't
> > work.
> >
> > def resizeEvent(self, event):
> >     self.size = event.oldSize()
> >
> > Any hint?
> 
> If you use the Qt designer you can set the minimum- and maximum window
> size to the same value, which disables resize as well. Tested with Qt4
> on Linux 2.6. But I'm pretty sure that there could be a much cleaner
> way to do this.

You can give a window a fixed size by calling its setFixedSize() method,
but this requires you to decide its exact size in pixels.

A better alternative is to call setSizeConstraint() on the window's
layout with a value of SetFixedSize:
 
http://www.riverbankcomputing.com/Docs/PyQt4/html/qlayout.html#SizeConstraint-enum

This way, the layout will figure out how much space the window requires and
force it to remain at that size from then on.

David
-- 
David Boddie
Lead Technical Writer, Trolltech ASA



More information about the Python-list mailing list