How to make StackLayout collapse when currentIndex === -1?
Unsolved
QML and Qt Quick
-
The following code just do a simple thing: change the
currentIndex
ofStackLayout
to-1
when clicked. But I want to let the height ofStackLayout
to be0
whencurrentIndex
is-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
Binding
likeBinding { when: lay.currentIndex === -1 lay.height: 0 }
But this won't work.
-
Hi,
Shouldn't you rather make it invisible ?
-
@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" } }