qt - qt QML 可折叠嵌套 ListView 与 PropertyAnimation
问题描述
我是 QT QML 的新手,我打算制作一个带有平滑动画的 ListView。我看到了这个https://gist.github.com/elpuri/3753756代码。我尝试在折叠期间添加 PropertyAnimation 并展开代码。但是失败了,我应该如何让它工作?
我正计划添加状态和翻译,但它不适用于两个不同的组件,
nestedModel.setProperty(index, "collapsed", !collapsed)
nestedModel.state = (collapsed.state === "COLLAPSED") ? "COLLAPSED" : "EXPANDED";
然后对于状态和转换,
delegate: Rectangle {
id: rect_change
color: "blue"
//height: 200
width: 300
border.color: "black"
border.width: 2
state: "COLLAPSED"
states: [
State {
name: "COLLAPSED"
PropertyChanges { target: rect_change; height: 0; }
},
State {
name: "EXPANDED"
PropertyChanges { target: rect_change; height: 200; }
}
]
transitions: [
Transition {
from: "EXPANDED"
to: "COLLAPSED"
PropertyAnimation { property: "height"; duration: 400; }
},
Transition {
from: "COLLAPSED"
to: "EXPANDED"
PropertyAnimation { property: "height"; duration: 400; }
}
]
}
解决方案
为了更简单的实现,摆脱你的状态和转换,只使用 a Behavior
on height
。您可以更改Loader
链接到的示例中的 ,如下所示:
Loader {
id: subItemLoader
sourceComponent: subItemColumnDelegate
onStatusChanged: if (status == Loader.Ready) item.model = subItems
clip: true
height: collapsed ? 0 : subItems.count * 40
Behavior on height {
NumberAnimation {
duration: 400
}
}
}
推荐阅读
- javascript - 将矩范围导入 Angular 4.x 应用程序(ES6) - 没有兼容的调用签名错误?
- html - 我已经尝试让这个@media 代码工作 30 分钟,但我仍然找不到答案
- junit - Junit:org.mockito.exceptions.misusing.MissingMethodInvocationException:
- hive - 为什么单个计数与蜂巢中的总体计数不同
- iis - Laravel 尝试从旧文件夹加载文件
- python-3.x - 无法在 sqlite 数据库中插入唯一值
- mysql - 将 PHP 变量传递给 MySQL 触发器#nette
- jquery - 为什么 html() 会丢失类分配?
- javascript - 多个集合的单一模式:MEAN
- selenium - 在黄瓜(java)中重用两个功能文件之间的公共步骤定义