Guest User

QML Flickable ContentHeight problem

a guest
Apr 27th, 2014
52
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import QtQuick 2.0
  2. import QtQuick.Controls 1.1
  3. import QtQuick.Layouts 1.1
  4.  
  5. Rectangle {
  6. id: rectangle1
  7. function random_text( itemno ) {
  8. var i;
  9. var str;
  10. str = "<b>item(" + itemno + ")</b><br/>" ;
  11. var n = Math.round(100.0 * Math.random()) ;
  12. for ( i=0 ; i < n ; i++ ) {
  13. str = str + ' xyz abc ' ;
  14. if (Math.random() < .2 ) {
  15. str += "EOL<br/>";
  16. }
  17. }
  18. return str;
  19. }
  20. width: 400
  21. height: 500
  22.  
  23. ListView {
  24. id: flickable
  25. anchors.fill: parent
  26. model: 10
  27. spacing: 20
  28.  
  29. delegate:
  30. Rectangle {
  31. radius: 5
  32. border.color: "brown"
  33. border.width: 2
  34. color: "yellow"
  35. width: parent.width
  36. height: mytext.contentHeight * 1.1
  37. Text {
  38. wrapMode : Text.WordWrap
  39. width: parent.width * 0.95
  40. font.pointSize: 12
  41. id: mytext
  42. text: random_text(modelData)
  43. }
  44. }
  45. onFlickEnded: {
  46. console.log("Flick has ended");
  47. console.log("flickable height is " + flickable.height )
  48. console.log("flickable contentheight is " + flickable.contentHeight )
  49. console.log("flickable flickable.visibleArea.heightRatio is " + flickable.visibleArea.heightRatio)
  50. }
  51.  
  52. }
  53. }
RAW Paste Data