เนื่องจากสิ่งนี้ ListView
ทำงานได้ดี:
ListView {
id: myListView
model: myListModel
anchors.fill: parent
delegate: Row {
id: row
spacing: 5
Text {
text: id
width: 25
horizontalAlignment: Text.AlignHCenter
}
Text {
text: description
}
}
}
เหตุใดการเพิ่ม MouseArea
ด้วย anchors.fill: parent
ทำให้แถวซ้อนกัน ฉันจะคืนระยะห่างแนวตั้งอัตโนมัติที่ฉันมีก่อนที่จะเพิ่ม MouseArea
ได้อย่างไร ฉันได้ลองใส่ Row
ใน Rectangle
และใน Component
แล้ว
ListView {
id: myListView
model: myListModel
anchors.fill: parent
delegate: Row {
MouseArea {
anchors.fill: parent
onClicked: myListView.currentIndex = index
}
id: row
spacing: 5
Text {
text: id
width: 25
horizontalAlignment: Text.AlignHCenter
}
Text {
text: description
}
}
}