QLayout布局时自动占满全部的空间。

QLayout子类布局时会自动占满全部的空间,和一般需要多大空间占多大空间的要求不符合,很烦人。

 

案例:

本来一个容器简单的放几个组件会剩余很大的空间,就那么剩余就好。

结果呢?把全部的空间都占据了,然后组件之间还有很多的空白。

 

解决方案:

指定对齐方式:QLayout.setAlignment( Qt.AlignTop )

 

 

void QBoxLayout::addWidget(QWidget * widget, int stretch = 0, Qt::Alignment alignment = 0)

Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment.

The stretch factor applies only in the direction of the QBoxLayout, and is relative to the other boxes and widgets in this QBoxLayout. Widgets and boxes with higher stretch factors grow more.

If the stretch factor is 0 and nothing else in the QBoxLayout has a stretch factor greater than zero, the space is distributed according to the QWidget:sizePolicy() of each widget that's involved.

The alignment is specified by alignment. The default alignment is 0, which means that the widget fills the entire cell.

 

posted @ 2015-09-01 15:11  宁静的天空  阅读(3669)  评论(1编辑  收藏  举报