如何将元素居中ColumnLayout
?
这是我的qml代码:
ApplicationWindow {
id: root
visible: true
width: 640
height: 640
title: qsTr("Your Booking")
GridLayout{
anchors.fill: parent
columns: 2
flow: GridLayout.TopToBottom
Rectangle{
id: appBar
Layout.columnSpan: 2
width: root.width
height: root.height/10
color: "red"
}
ColumnLayout{
spacing:5
id: columnData
height: root.height - appBar.height
width: root.width/2
ComboBox{
anchors.horizontalCenter: parent.horizontalCenter
}
ComboBox{
}
ComboBox{
}
ComboBox{
}
ComboBox{
}
}
ColumnLayout{
}
}
}
我想将ComboBoxes放在ColumnLayout中。
您应该避免同时使用锚点和布局。以相同的级别混合它们会导致布局故障或某些意外结果(但是,可以在布局中的项目内部使用锚点)。
要在布局中对齐项目,可以使用附加的属性:Layout.alignment
,例如:
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
此语句将使您的项目完全位于布局的中心。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句