我想使我的電話號碼列表與左側的一個字段(「名稱」)和右側的另一個字段(「電話」)對齊。但是,當試圖綁定委託內部的錨定屬性時,它說委託對象不是ListView組件的父項。我如何從代表接觸其他組件?如何對齊委託中的QML組件
這是我的QML代碼:
import QtQuick 2.7
import QtQuick.Controls 2.0
Item {
id: enclosing_area
width: 500
height: 300
ListModel {
id: dataModel
ListElement {
name: "John Smith"
phone: "1111-1111"
}
ListElement {
name: "Peter Poter"
phone: "2222-2222"
}
ListElement {
name: "Anna Lasalle"
phone: "3333-3333"
}
}
ListView {
id: list
width: enclosing_area.width
height: enclosing_area.height
model: dataModel
delegate: Rectangle {
width: enclosing_area.width
border.color: "red"
Label {
text: name
anchors.left: list.left
}
Label {
text: phone
anchors.right: list.right
}
}
}
}
qmlscene產生以下錯誤:
file:///LViewTest.qml:36:13: QML Label: Cannot anchor to an item that isn't a parent or sibling.
file:///LViewTest.qml:32:13: QML Label: Cannot anchor to an item that isn't a parent or sibling.
file:///LViewTest.qml:36:13: QML Label: Cannot anchor to an item that isn't a parent or sibling.
file:///LViewTest.qml:32:13: QML Label: Cannot anchor to an item that isn't a parent or sibling.
file:///LViewTest.qml:36:13: QML Label: Cannot anchor to an item that isn't a parent or sibling.
file:///LViewTest.qml:32:13: QML Label: Cannot anchor to an item that isn't a parent or sibling.
線32和32是 「anchors.left」 和 「anchors.right」 語句。 如何在我的情況下綁定到來自委託的另一個對象中的屬性?