Animation Qt Quick TreeView展开/折叠动画

Animation Qt Quick TreeView展开/折叠动画,animation,qml,qtquick2,qt-quick,qtquickcontrols,Animation,Qml,Qtquick2,Qt Quick,Qtquickcontrols,我曾在Qt论坛()上问过这个问题,但没有得到任何回应,而那边的一个问题已经三个月没有得到回答了。。。我来了 我正在尝试在QML中为树视图的展开和折叠设置动画。我在我的应用程序的其他地方有一个flickable中的动画,其中flickable中的子对象的高度被设置动画以模拟“扩展”,我需要树视图的扩展/折叠相同(或至少相似) 我尝试在rowDelegate中的行高度上添加动画,但没有效果: Behavior on height { NumberAnimation { duration:

我曾在Qt论坛()上问过这个问题,但没有得到任何回应,而那边的一个问题已经三个月没有得到回答了。。。我来了

我正在尝试在QML中为树视图的展开和折叠设置动画。我在我的应用程序的其他地方有一个flickable中的动画,其中flickable中的子对象的高度被设置动画以模拟“扩展”,我需要树视图的扩展/折叠相同(或至少相似)

我尝试在rowDelegate中的行高度上添加动画,但没有效果:

Behavior on height {
  NumberAnimation {
    duration: 250
    easing.type: Easing.InOutQuad
}
看看Gabriel de Dietrich和Caroline Chao用Qt()打包的TreeView实现,似乎他们在父对象展开时将子数据插入到私有的“_listView”,在父对象折叠时将其删除

经过一些研究,我能够从stackoverflow的答案中找到关于这个问题的信息和一些提示

有了这些技巧,我可以在TreeView的私有属性中进行黑客攻击,得到一个相当糟糕的扩展动画

TreeView {
    id: tree
    model: myModel
    Transition {
        id: treeTransitionAnimation
        NumberAnimation { properties: "y"; duration: 300 }
    }

    Component.onCompleted: {
        if(this.__listView) {
            this.__listView.add  = treeTransitionAnimation
            this.__listView.remove  = treeTransitionAnimation
            //doesn't actually work on remove. The child items in the tree just disappear.
        }
        else {
            console.log("Something bad happened. Darn.")
        }
    }
...
这将在展开(插入)新项目时从树的顶部将其滑入。。。但这不是我需要的。我知道使用这些QML对象的私有属性是不好的做法,但我会接受任何有效的方法

还要注意的是,上述操作实际上甚至不适用于remove

在上面的数字动画中将“高度”替换为“y”也不起作用

用于树的Qt类有一个用于设置树展开和折叠动画的简单属性,但TreeView没有此类属性

有人知道如何完成这个动画吗

提前感谢您的建议

编辑 我还尝试在rowDelegate和itemDelegate中添加ListView.onAdd和ListView.onRemove处理程序,但没有效果。。。见下例:


但是“onAdd”和“onRemove”日志输出从来都没有打印过。

我能够改进我的扩展动画,但是(几乎)来自Qt的问题的最终答案是,如果不直接编辑Qt源代码,折叠动画是不可能的(甚至可能不是…?)。对许多人来说,这不是一个可行的选择,因此也不是一个答案

在发布新的Qt Controls版本并使用全新的TreeView实现进行更新之前,此问题将一直存在。
仅供参考:该链接声明“5.8已经太晚了”,因此我相信可以安全地假设这将在5.8之后出现

我正在讨论使用Qt支持对Qt源代码进行编辑的过程,但作为对上述问题的回答,答案是在Qt的当前版本中无法进行编辑。(回答此问题时当前支持的版本为5.7)

rowDelegate:     Rectangle {
        id: rowDelegateItem
        height: 100

        SequentialAnimation {
            id: collapseAnimation
            running: false
            PropertyAction { target: rowDelegateItem; property: "ListView.delayRemove"; value: true }
            NumberAnimation { target: rowDelegateItem; properties: "height"; to: 0.0; duration: 250 }
            PropertyAction { target: rowDelegateItem; property: "ListView.delayRemove"; value: false }
        }

        SequentialAnimation {
            id: addAnimation
            running: false
            PropertyAction { target: rowDelegateItem; property: "height"; value: 0 }
            NumberAnimation { target: rowDelegateItem; properties: "height"; to: 100; duration: 250 }
        }

        ListView.onRemove: {
            console.log("onRemove");
            collapseAnimation.start();
        }

        ListView.onAdd: {
            console.log("onAdd");
            addAnimation.start();
        }