<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Collapsable menu with responsive height]]></title><description><![CDATA[<p dir="auto">I've got a simple collapsable menu, that contains a title for the menu ("Hair color"), and 2 items within it ("Blond" and "Brown"). I also have an animation that displays/hides the different items within it in a linear fade in/fade out of 500ms. That works fine as a visual, however I cannot figure out how to make the menu itself take the height during the animation: at any given time during the 500ms animation, i would like whatever is below the menu (a line in this example) to be located at the position of the lowest displayed item within the menu. What I get instead is that as soon as the animation starts for opening, the menu takes the whole space of the items (even the ones that aren't displayed yet). Same when hiding.</p>
<p dir="auto">Below is the code that I currently have:</p>
<pre><code>import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15

Item {
    property bool expanded: false
    property int filterWidth: 400

    id: root
    width: filterWidth
    height: columnFilter.implicitHeight

    ColumnLayout {
        id: columnFilter
        width: parent.width

        RowLayout {
            id: row
            height: implicitHeight
            Layout.margins: 10
            width: parent.width - Layout.leftMargin - Layout.rightMargin
            spacing: 10

            Text {
                id: text1
                text: qsTr("Hair color")
                font.pixelSize: 16
            }

            Item {
                Layout.fillWidth: true
            }

            Image {
                id: expandIcon
                width: 20
                height: 20
                sourceSize: Qt.size(width, height)
                source: "./Up-black.svg"
                fillMode: Image.PreserveAspectFit
                rotation: 180
            }
        }

        Column {
            id: filterValues
            spacing: 10
            height: 0
            clip: true
            Layout.leftMargin: 12
            visible: height &gt; 0

            onHeightChanged:  {
                console.log("bottom col " + (y + height))
            }

            Text {
                id: blond
                text: qsTr("Blond")
                font.pixelSize: 16
                clip: true
            }

            Text {
                id: brown
                Layout.margins: 12
                text: qsTr("Brown")
                font.pixelSize: 16
                clip: true
            }
        }

        Rectangle {
            id: line1
            width: row.width
            height: 2
            color: "black"
        }

        MouseArea {
            id: filterTitleMouseArea
            anchors.fill: row
            enabled: true
            onClicked: expanded = !expanded
        }
    }

    states: [
        State {
            name: "Expanded"
            when: root.expanded

            PropertyChanges {
                target: expandIcon
                rotation: 0
            }
            PropertyChanges {
                target: filterValues
                height: implicitHeight
            }
        }
    ]

    transitions: [
        Transition {
            id: transition1
            ParallelAnimation {
                PropertyAnimation {
                    target: expandIcon
                    property: "rotation"
                    duration: 200
                }
                PropertyAnimation {
                    target: filterValues
                    property: "height"
                    duration: 500
                }
            }
            to: "*"
            from: "*"
        }
    ]

}
</code></pre>
<p dir="auto">What I would like is something that looks like this:</p>
<pre><code>Rectangle {
           id: line1
           width: row.width
           height: 2
           color: "black"
           top: filterValues.y + filterValues.height
       }
</code></pre>
<p dir="auto">Which kinda works, but doesn't take into account the margins/padding of the filterValues column, and seems like a hack honestly. Is there a way to do that natively with the QML framework?<br />
For reference, I'm using Qt 5.15.13.</p>
]]></description><link>https://forum.qt.io/topic/149586/collapsable-menu-with-responsive-height</link><generator>RSS for Node</generator><lastBuildDate>Wed, 21 Oct 2026 15:17:13 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/149586.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 15 Sep 2023 15:08:56 GMT</pubDate><ttl>60</ttl></channel></rss>