【问题标题】:qt QML collapsible nested ListView with PropertyAnimationQt QML可折叠嵌套Listed Listed with processanimation
【发布时间】:2021-06-11 03:56:22
【问题描述】:

我是 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; }
        }
    ]
}

【问题讨论】:

标签: qt listview qml collapse qpropertyanimation


【解决方案1】:

为了更简单的实现,摆脱你的状态和转换,只需在height 上使用Behavior。您可以更改链接到的示例中的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
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-25
    • 1970-01-01
    相关资源
    最近更新 更多