我想要使用列布局動態調整大小的窗口,以便無論剩餘空間由列中最後一項填充。我可以通過動態計算javascript中最後一項的高度來實現。我還可以將最後一項移出列,並將列的頂部綁定到列的底部和容器的底部,但是我還必須從其內容中計算列的新大小。如何讓QML容器中的最後一項填充剩餘空間?
import QtQuick 2.0
import QtQuick.Controls 1.1
Rectangle {
id: rect
anchors.fill: parent
Column {
id: myColumn
anchors.fill: parent
Rectangle {
id: container
signal clicked
width: label.width + 20; height: label.height + 6
anchors { right: parent.right }
border.width: 1
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: {
if (myColumn.state == 'hidden') { myColumn.state = '' }
else { myColumn.state = 'hidden'; }
}
}
Text {
id: label
text: { if (myColumn.state == '') {"Hide"} else {"Show"} }
anchors.centerIn: parent
}
}
Text {
id: textualBox
text: "A Big Box"
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
anchors { left: parent.left; right: parent.right }
height: 200
}
TableView {
id: table
width: parent.width
height: { myColumn.height - container.height - textualBox.height }
model: myData
TableViewColumn { role: "name"; title: "name"; width: 60 }
TableViewColumn { role: "stuff"; title: "stuff"; width: 60 }
}
states: State {
name: 'hidden'
PropertyChanges {
target: textualBox
height: 20
text: "a little box"
}
}
}
ListModel {
id: myData
ListElement{ name: "content" ; stuff: "4.5" }
ListElement{ name: "content" ; stuff: "4.5" }
ListElement{ name: "content" ; stuff: "4.5" }
}
}
有沒有更優雅的方式來做到這一點?