http://blog.csdn.net/zhangxufei/article/details/50825057
addStretch()
void QBoxLayout::addStretch(int stretch = 0)
Adds a stretchable space (a QSpacerItem) with zero minimum size and stretch factor stretch to the end of this box layout.
函数的作用是:在布局器中增加一个伸缩量,里面的参数表示QSpacerItem的个数,默认值为零,会将你放在layout中的空间压缩成默认的大小。
示例:
上面图片可以看做下面的图片:
label1 = new QLabel(tr("label1"));
label2 = new QLabel(tr("label2"));
label3 = new QLabel(tr("label3"));
label4 = new QLabel(tr("label4"));
QVBoxLayout *layout1 = new QVBoxLayout();
layout1->addWidget(label1);
layout1->addWidget(label2);
layout1->addStretch();//增加伸缩量
layout1->addWidget(label3);
QVBoxLayout *layout2 = new QVBoxLayout();
layout2->addStretch();
layout2->addWidget(label4);
layout2->addStretch();
QHBoxLayout *mainlayout = new QHBoxLayout();
mainlayout->addLayout(layout2);
mainlayout->addStretch();//增加伸缩量
mainlayout->addLayout(layout1);
其中addStretch()函数用于在Label标签间增加伸缩量!!!
可以这样理解,addStretch()函数占了除了label之外空白地方。。