QT 设置SizePolicy的例子(简单明了)

时间:2022-06-27 07:16:20
http://hi.baidu.com/cybertingred/item/e8eadaad0c7f62f615329be7
 

QPushButton *left = new QPushButton("killin' kind");
QPushButton *right = new QPushButton("Emma");

QHBoxLayout *layout = new QHBoxLayout(this);

layout->addWidget(left);
layout->addStretch();
layout->addWidget(right);

QSizePolicy policy = left->sizePolicy();
policy.setHorizontalStretch(1);
policy.setVerticalStretch(1);
policy.setHorizontalPolicy(QSizePolicy::Minimum);
left->setSizePolicy(policy);

policy = right->sizePolicy();
policy.setVerticalStretch(1);
policy.setHorizontalStretch(3);
policy.setHorizontalPolicy(QSizePolicy::Minimum);
right->setSizePolicy(policy);

http://blog.csdn.net/skykingf/article/details/8273992