1

I have a ListView with a SwipeDelegate as delegate. It's contentItem consists of a ColumnLayout with two RowLayouts inside. Now I want the second RowLayout to unfold, if I click the delegate. This works like it should, but I want the "expand" to be animated, so that it smoothly unfolds. I tired it with Behaviour on height { NumberAnimation {} } but it did not work. How can I achive this?

ListView {
    id: myView
    visible: count > 0

    clip: true
    boundsBehavior: Flickable.StopAtBounds
    model: mymodel

    Component.onCompleted: {
        Layout.preferredHeight = Qt.binding(function() {
            return myView.contentHeight
        })
    }

    spacing: 3

    delegate: SwipeDelegate {
        id: delegate
        width: myView.width
        hoverEnabled: false

        property bool expanded: false

        onClicked: {
            expanded = !expanded
        }


        contentItem: ColumnLayout {

            Behavior on height { NumberAnimation {} }

            RowLayout {
                Layout.fillWidth: true

                CheckBox {
                    id: chkSel
                    Layout.fillHeight: true
                    checked: model.sel
                    padding: 0
                    rightPadding: 5
                    spacing: 0
                }

                Label {
                    Layout.fillWidth: true
                    font.pointSize: 14
                    font.bold: true
                    text: model.nr
                }

                Image {
                    id: swipeTipArrow
                    sourceSize.height: parent.height * 0.9
                    fillMode: Image.PreserveAspectFit
                    opacity: 0
                    source: "left.svg"
                }
            }

            RowLayout {
                Layout.fillWidth: true
                visible: delegate.expanded

                Label {
                    Layout.fillWidth: true
                    font.pointSize: 12
                    text: model.nr2
                }
            }
        }
}

1 Answer 1

0

Move the animation to the SwipeDelegate and change the size of the delegate according the expanded state:

...

delegate: SwipeDelegate {
            id: delegate
            width: myView.width
            hoverEnabled: false

            property bool expanded: false
            onClicked: {
                expanded = !expanded
            }
            height: expanded ? 100 : 40 // TODO change to correct sizes
            Behavior on height { NumberAnimation {}}

            ...
            
        }

...
Sign up to request clarification or add additional context in comments.

6 Comments

I cannot set the height directly, because it is calculated dynamically by the ColumnLayout of the contentItem.
Then relate to the implicitHeight of the ColumnLayout: height: layout1.implicitHeight
Now the animation works, but the height is not high enough and text is cut off
Hm, tested it and works for me. Both texts are displayed correctly.
Can you try it without the Image?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.