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.
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步