I followed the Qt 5.2 documentation on ListView (http://qt-project.org/doc/qt-5/qml-qtquick-listview.html#details). My code is almost identical to the doc except for the contactDelegate's width which I want to bind to the width of the Rectangle listArea.
When I run the code below it looks as expected. However, when I resize the window the delegate is not resized with the rectangle's changing width.
import QtQuick 2.0
Rectangle {
id: listArea
width: 200; height: 50
color: "#fffcca"
Component {
id: contactDelegate
Item {
width: listArea.width; height: 40
Column {
Text { text: '<b>Name:</b> ' + name }
Text { text: '<b>Number:</b> ' + number }
}
}
}
ListModel {
id: contactModel
ListElement {
name: "John Doe"
number: "5555 1234"
}
ListElement {
name: "Don Johnson"
number: "5555 5432"
}
}
ListView {
id: contactView
anchors.fill: parent
model: contactModel
delegate: contactDelegate
highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
focus: true
}
}
How can I make the delegate's width adapt to changing width of the outer rectangle?