[PyQt] Toolbar widget sizing problems

David Boddie david at boddie.org.uk
Sat Sep 6 15:33:38 BST 2008

On Saturday 06 September 2008, Scott Price wrote:

> Some more poking around revealed that while QLineEdit.setGeometry() and
> QLineEdit.setSizePolicy() are disregarded by the toolbar, that
> QLineEdit.setFixedSize() _is_ respected!

Since you are putting the line edit inside a group box, you might want to
try changing the size policy of that instead.

> It results in the appropriately 
> sized line-edit being shown centered in the middle of the toolbar, with its
> label on the far left.  A minor detail, but one I'll have to address.
> Preferably the line-edit should be in the far left also.

You may want to add a stretch to the layout containing the line edit:


> The test change to a QTextEdit gave me the idea that perhaps the toolbar is
> only interested in the default size of the widget in question.  This was
> shown by the size of the text edit when added being equal to its default
> size when picked off the QDesigner toolbox to add to a widget.  Apparently
> the .setFixedSize() affects the basic size of the widget in a way that
> setGeometry() and setSizePolicy() do not.

The way the size requirements of widgets are communicated in nested layouts
isn't always obvious. You might find the documentation on layouts to be
helpful, but more experimentation may be required:



More information about the PyQt mailing list