How to make StackLayout collapse when currentIndex === -1?
-
The following code just do a simple thing: change the
currentIndexofStackLayoutto-1when clicked. But I want to let the height ofStackLayoutto be0whencurrentIndexis-1.Window { id: window width: 400 height: 400 visible: true color: "#181818" MouseArea { id: ma anchors.fill: parent hoverEnabled: true onClicked: lay.currentIndex = -1 } StackLayout { id: lay anchors.top: parent.top Rectangle { width: 300 height: 100 color: "white" } } Rectangle { anchors.top: lay.bottom width: 200 height: 100 color: "red" } }I've tried
BindinglikeBinding { when: lay.currentIndex === -1 lay.height: 0 }But this won't work.
-
Hi,
Shouldn't you rather make it invisible ?
-
Do you mean you want to animate its size going down to 0 ?
-
@Kamichanw I don't get what you want to achieve, but I assume you can simply bind the height?
StackLayout { id: lay anchors.top: parent.top height: currentIndex >= 0 ? childrenRect.height : 0 Rectangle { width: 300 height: 100 color: "white" } }