Jac*_*ieg 6 qt qml qt5 qtquick2 qtquickcontrols2
我想创建一个布局QML,我想添加一个spacer项(下图中的底部选项),就像使用小部件一样:
但我找不到任何适合这QtQuick方面的东西......是否可以QML使用锚定系统进行这种布局?我更喜欢布局方法......
Gre*_*cKo 19
你可以简单地使用Item具有Layout.fillHeight: true:
import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.3
ApplicationWindow {
visible: true
ColumnLayout {
anchors.fill: parent
Button {
Layout.fillWidth: true
text: "PushButton"
}
Button {
Layout.fillWidth: true
text: "PushButton"
}
Label {
Layout.fillWidth: true
text: "TextLabel"
}
Item {
// spacer item
Layout.fillWidth: true
Layout.fillHeight: true
Rectangle { anchors.fill: parent; color: "#ffaaaa" } // to visualize the spacer
}
}
}
Run Code Online (Sandbox Code Playgroud)

编辑:或者在这里,您可以使用Column没有间隔项,因为它Column只是将其子项从上到下定位,并且不会将它们展开以占用所有可用空间.