How can I use a MouseArea to change the item in a StackLayout?
MouseArea {
id: mouseAreaServerSetup
anchors.fill: parent
onClicked:{
// change Iten serverSetupPage
}
}
MouseArea {
id: mouseAreaClientSetup
anchors.fill: parent
onClicked: {
// change Iten clientSetupPage
}
}
StackLayout {
anchors.fill: parent
currentIndex: menuConfig.currentIndex
Item {
id: serverSetupPage
Rectangle {
color: "red"
}
}
Item {
id: clientSetupPage
Rectangle {
color: "yellow"}
}
}
}
The idea is that when you click on a mouseArea you change Tab Item
Thanks
You will have to assign the
currentIndexfrom you stackLayout, so I gave it anid. Then each mouse click I increment thecurrentIndexuntill it reaches the number of items (count).Btw, I made the Rectangles fill their parent (which is the
StackLayout) so you will be able to see them actually, they default to a size of (0,0).I'm not sure why you have put two
MouseArea, since the first will be overlapped by the second completely and you will never be able to go toserverSetupPage. This also touches another problem you might get, if you ever grow away from only displaying a red of yellowRectangle(most probably today ;-) ) and implement anotherMouseArea, that new one will overlap the one to switch tabs.So page switching is better done by adding a
TabBarwithTabButtonwhich will tell what page will be opened. Something like this: