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布局器中。

最新文章

  1. C语言小练习一
  2. [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绘制线条属性讲解
  3. html兼容性
  4. cvs版本控制器
  5. hdu 5351 规律+大数
  6. strrchr函数
  7. JAVA:23种设计模式详解(转)
  8. Linux安装中文man手冊
  9. Cocos2D v2.0至v3.x简洁转换指南(四)
  10. the python challenge闯关记录(9-16)
  11. hadoop管理命令
  12. Kafka Streams简介: 让流处理变得更简单
  13. 一个ping大包不通问题的解决过程
  14. Swagger2限定接口范围
  15. liunx必知必会(1)
  16. 你不知道的JavasScript上篇·第五章·原型·上
  17. Python常见面试(习题)——水仙花数
  18. NET WebAPi之断点续传下载(下)
  19. 【Python】【fmt】
  20. C# AtomicLong

热门文章

  1. js绝招
  2. 《C++游戏开发》十六 游戏中的寻路算法(二):迷宫&A*算法基础
  3. php之快速入门学习-18(PHP 面向对象)
  4. [C#]记录程序耗时的方法【转发】
  5. java 泛型 精析
  6. js setTimeout 传递带参数的函数的2种方式
  7. TransactionScope 的基本原理简介
  8. Linux生成高强度密码
  9. idea搭建简易ssm项目
  10. js hasChildNodes()指针对元素节点子节点多个的话 true