QT中布局器的addStretch函数使用效果
2024-10-14 02:05:13
QBoxLayout中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中的空间压缩成默认的大小。
例如:一个layout布局器,里面有三个控件,一个放在最左边,一个放在最右边,最后一个放在layout的1/3处,这就可以通过addStretch去实现。
例:用addStretch函数实现将nLayout的布局器的空白空间平均分配
QHBoxLayout *buttonLayout = new QHBoxLayout;
QPushButton *button1;
QPushButton *button2;
QPushButton *button3; button1 = new QPushButton;
button2 = new QPushButton;
button3 = new QPushButton; buttonLayout->addStretch();
buttonLayout->addWidget(button1);
buttonLayout->addStretch();
buttonLayout->addWidget(button2);
buttonLayout->addStretch();
buttonLayout->addWidget(button3);
buttonLayout->addStretch(); buttonLayout->setContentsMargins(, , , );
运行结果:
其中四个addStretch()函数用于在button按钮间增加伸缩量,伸缩量的比例为1:1:1:6,意思就是将button以外的空白地方按设定的比例等分为9份并按照设定的顺序放入buttonLayout布局器中。
最新文章
- C语言小练习一
- [javascript svg fill stroke stroke-width x1 y1 x2 y2 line stroke-opacity fill-opacity 属性讲解] svg fill stroke stroke-width stroke-opacity fill-opacity line绘制线条属性讲解
- html兼容性
- cvs版本控制器
- hdu 5351 规律+大数
- strrchr函数
- JAVA:23种设计模式详解(转)
- Linux安装中文man手冊
- Cocos2D v2.0至v3.x简洁转换指南(四)
- the python challenge闯关记录(9-16)
- hadoop管理命令
- Kafka Streams简介: 让流处理变得更简单
- 一个ping大包不通问题的解决过程
- Swagger2限定接口范围
- liunx必知必会(1)
- 你不知道的JavasScript上篇·第五章·原型·上
- Python常见面试(习题)——水仙花数
- NET WebAPi之断点续传下载(下)
- 【Python】【fmt】
- C# AtomicLong