我正在尝试将TabButtons
垂直放置在TabBar
中。但是每个TabButton
的位置都在我不希望的位置。似乎它们是由根项锚定的。
Item {
id: element
width:800; height:800
Rectangle {
id: container
anchors.fill:parent
color:"red"
Rectangle {
id: subContainer
anchors.left:parent.left
anchors.leftMargin: 100
anchors.top:parent.top
anchors.topMargin: 100
width:200
height:450
TabBar {
id: tabBar
anchors.top:parent.top;
anchors.bottom:parent.bottom
anchors.left:parent.left;
anchors.leftMargin:100
width:120
Column {
id: column
anchors.fill:subContainer //
TabButton {
id:tab1
anchors.top:tabBar.top; anchors.left:tabBar.left
width: tabBar.width; height:tabBar.height/3;
}
TabButton {
id:tab2
anchors.top:tab1.bottom; anchors.left:tabBar.left
width: tabBar.width; height:tabBar.height/3;
}
TabButton {
id:tab3
anchors.top:tab2.bottom; anchors.left:tabBar.left
width: tabBar.width; height:tabBar.height/3;
}
} // End of Column
} // End of TabBar
}
StackLayout { // this stack seems to be working as I've intended
id: stack
anchors.top:parent.top;
anchors.bottom: parent.bottom;
anchors.left : bar.right;
anchors.right:parent.right
Rectangle {
id: homeTab
color:"yellow"
width: 300; height:300
}
Rectangle {
id: discoverTab
color:"skyblue"
width: 300; height:300
}
Rectangle {
id: activityTab
color:"lightgray"
width: 300; height:300
}
}
}
}
您的锚点设置不正确,您也不需要该列:
Item {
id: element
width:800; height:800
Rectangle {
id: container
anchors.fill:parent
color:"red"
Rectangle {
id: subContainer
anchors.left:parent.left
anchors.leftMargin: 100
anchors.top:parent.top
anchors.topMargin: 100
width:200
height:450
TabBar {
id: tabBar
anchors.top:parent.top;
anchors.bottom:parent.bottom
anchors.left:parent.left;
width:120
TabButton {
id:tab1
anchors.top:parent.top; anchors.left:parent.left
width: tabBar.width; height:tabBar.height/3;
}
TabButton {
id:tab2
anchors.top:tab1.bottom; anchors.left:parent.left
width: tabBar.width; height:tabBar.height/3;
}
TabButton {
id:tab3
anchors.top:tab2.bottom; anchors.left:parent.left
width: tabBar.width; height:tabBar.height/3;
}
} // End of TabBar
}
StackLayout {
id: stack
anchors.top:parent.top;
anchors.bottom: parent.bottom;
anchors.left : subContainer.right;
anchors.right:parent.right
Rectangle {
id: homeTab
color:"yellow"
width: 300; height:300
}
Rectangle {
id: discoverTab
color:"skyblue"
width: 300; height:300
}
Rectangle {
id: activityTab
color:"lightgray"
width: 300; height:300
}
}
}
}