Python QT开发(七)pyside2 QFormLayout的几个重要属性

本文深入解析了QFormLayout的功能特性,包括插入、移除及添加行的方法,以及表单换行策略的三种模式:不换行、自适应换行和强制换行。此外,还介绍了如何通过setWidget函数逐个添加控件,并设置了ItemRole的角色。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

QFormLayout

n行两列表单,提供了一套insertRowremoveRowaddRow的方法,此类默认第一列为QLabel,支持第一列只提供字符串而不提供QLabel对象

表单换行策略

setRowWrapPolicy(RowWrapPolicy policy)

ConstantValueDescription
QFormLayout::DontWrapRows0一直在一行Fields are always laid out next to their label. This is the default policy for all styles except Qt Extended styles.
QFormLayout::WrapLongRows1自适应,如果空间不够则两行Labels are given enough horizontal space to fit the widest label, and the rest of the space is given to the fields. If the minimum size of a field pair is wider than the available space, the field is wrapped to the next line. This is the default policy for Qt Extended styles.
QFormLayout::WrapAllRows2一直两行Fields are always laid out below their label.

setWidget(int row, ItemRole role, QWidget *widget)

不使用addrow一类的整行添加,也可以逐个添加,使用此函数需要设置ItemRole

ConstantValueDescription
QFormLayout::LabelRole0标签列A label widget.
QFormLayout::FieldRole1输入框列A field widget.
QFormLayout::SpanningRole2单控件占用整行A widget that spans label and field columns.

 

| 版权声明: 本站文章采用 CC 4.0 BY-SA 协议 进行许可,转载请附上原文出处链接和本声明。
| 本文链接: Cologic Blog - QLayout窗口布局 - https://www.coologic.cn/2017/12/690/ 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值