讓我們假設我有一張使用Rectangle
製作的卡片,並且我想在單擊時在其上顯示按鈕。我打電話showMenu()
功能來做到這一點,併爲我使用動態ListModel
ListView
按鈕。這樣的問題是,按鈕被添加到Rectangle
而不是頂部。將項目追加到模型後,錨點不會更新。這是我的代碼ListView動態錨定
Item {
width: 120
height: 120
Rectangle {
id: card
width: 50
height: 100
color: "pink"
anchors.bottom: parent.bottom
Item {
id: rec
width: 50
anchors.bottom: parent.top // This anchor is not updating after appending an item to the list.
ListModel {
id: menuListModel
}
Component {
id: delegate
Rectangle {
width: 120
height: 20
color: "blue"
Text {
anchors.fill: parent
anchors.centerIn: parent
text: commandText
}
}
}
ListView {
anchors.fill: parent
model:menuListModel
delegate: delegate
interactive: false
}
}
MouseArea {
anchors.fill: parent
onClicked: menuListModel.append({"commandText" : "Normal Summon"});
}
}
}
你可以發佈運行的代碼嗎? – Mitch
更新了示例。 –