ListView列宽自适应,设置ListView.Column[0].Width := -1;

使用TListView列表显示内容,如果列内容过长,就会显示成‘XXX…’形式,此时如果双击列标题,列宽将变为自适应。用代码设置如下:

1、设置ListView.Column[0].Width := -1;//列宽根据列内容自适应,此时保证列内容都可见。

2、设置ListView.Column[0].Width := -2;//列宽根据列标题自适应,此时保证列标题可见。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现横向的 `ListView`,可以在外层 `ListView` 的 `orientation` 属性中设置为 `ListView.Horizontal`。同时,需要将内层 `ListView` 的宽度设置为外层 `ListView` 中每个选项的宽度之和,以确保内层选项能够全部展示出来,可以通过外层 `ListView` 的 `contentWidth` 属性来获取。 下面是修改后的示例代码: ```qml import QtQuick 2.0 import QtQuick.Controls 2.5 ListView { id: outerListView width: 400 height: 50 orientation: ListView.Horizontal model: outerModel delegate: ItemDelegate { text: model.label width: 100 ListView { id: innerListView width: outerListView.contentWidth height: 50 model: model.children visible: expanded orientation: ListView.Horizontal delegate: ItemDelegate { text: model.label width: 100 highlight: checked ? Rectangle { color: "lightblue" } : null onClicked: { if (multiSelect) { checked = !checked; } else { outerListView.currentIndex = -1; checked = true; } } } } Rectangle { id: expandIcon anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter width: 10 height: 10 color: "black" transform: expanded ? Rotation { origin.x: 5; origin.y: 5; angle: 90 } : Rotation { origin.x: 5; origin.y: 5; angle: 0 } MouseArea { anchors.fill: parent onClicked: expanded = !expanded } } property bool expanded: false property bool multiSelect: false property bool checked: false } } ``` 这样,就可以通过设置 `orientation` 属性将外层 `ListView` 设置为横向,同时将内层 `ListView` 的宽度设置为外层 `ListView` 中每个选项的宽度之和,来实现横向的 `ListView` 了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值