Advertisement
artemmarchenko

ListView sizing itself to the content height

Aug 24th, 2011
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import QtQuick 1.0
  2.  
  3. Rectangle {
  4.     width: 400
  5.     height: 300
  6.     color: "lightyellow"
  7.  
  8.     property int lineHeight: 30
  9.  
  10.     Component {
  11.         id: demoDelegate
  12.  
  13.         Rectangle {
  14.             color: "lightblue"
  15.             width: 120
  16.             height: lineHeight
  17.             Text {
  18.                 text: model.index
  19.             }
  20.         }
  21.     }
  22.  
  23.     ListView {
  24.         id: view
  25.         model: 6
  26.         anchors.left: parent.left
  27.         anchors.bottom: parent.bottom
  28.         width: childrenRect.width
  29.         height: model * lineHeight
  30.  
  31.         delegate: demoDelegate
  32.     }
  33.  
  34.     Component.onCompleted: {
  35.         console.log("contentHeight: " + view.childrenRect.height)
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement