1 如果row和rowlayout都没有填充父窗口,则没啥区别代码及效果如下
Rectangle{
width: 400
height: 600
border.color: "black"
Row{
//anchors.fill: parent //此时没有填充父窗口
spacing: 10
Rectangle{
width: 50
height: 50
color: "red"
}
Rectangle{
width: 50
height: 50
color: "red"
}
}
}
Rectangle{
width: 400
height: 600
x:500
border.color: "black"
RowLayout{
//anchors.fill: parent//同上
spacing: 10
Rectangle{
width: 50
height: 50
color: "red"
}
Rectangle{
width: 50
height: 50
color: "red"
}
}
}
2 如果布局填充父窗口
Rectangle{
width: 400
height: 600
border.color: "black"
Row{
anchors.fill: parent //此时填充父窗口
spacing: 10
Rectangle{
width: 50
height: 50
color: "red"
}
Rectangle{
width: 50
height: 50
color: "red"
}
}
}
Rectangle{
width: 400
height: 600
x:500
border.color: "black"
RowLayout{
anchors.fill: parent//同上
spacing: 10
Rectangle{
width: 50
height: 50
color: "red"
}
Rectangle{
width: 50
height: 50
color: "red"
}
}
}
很明显,rowlayout会把里面的子项平均填充整个区域,而row则还是和没填充之前一样,不会改变子项位置