[PyQt] Understanding QGridLayout colspan

David Boddie dboddie at trolltech.com
Mon Aug 17 14:30:45 BST 2009


On Mon Aug 17 13:54:04 BST 2009, Albert Cervera i Areny wrote:

> With:
>
> python colspan.py 1
>
> All three widgets are drawn with the same width. Which is right. But
> starting with:
>
> python colspan.py 2
>
> (and up) the first widget (which is assigned colspan="2") uses LESS space
> than the other two. So if we have three widgets with colspan 2, 1, 1
> respectively the one with higher colspan is smaller than the other two!
> Shouldn't this be the other way round? Those with higher colspan take up
> more space?

This is because the size policy of QLineEdit overrides the effect of the
layout's management policy. You can "fix" this for the line edits in your
example by changing their horizontal size policies in the following way:

  edit1 = QLineEdit(dialog)
  edit1.setSizePolicy(QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed))
  edit2 = QLineEdit(dialog)
  edit2.setSizePolicy(QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed))
  edit3 = QLineEdit(dialog)
  edit3.setSizePolicy(QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed))

Now the first line edit should take up about twice as much space as the
others, but only really for wide enough layouts. You may need to experiment
further.

David


More information about the PyQt mailing list