May 2, 2012

rferrazz rferrazz
Lab Rat
22 posts

ListView rendering problem

 

Can someone tell me what’s wrong with the current implementation?

  1. import QtQuick 1.1
  2. import com.nokia.meego 1.0
  3.  
  4. Page {
  5.     tools: commonTools
  6.     property string path: "/"
  7.     function add_element(element){
  8.         console.log(element.name)
  9.         elements.append(element);
  10.     }
  11.  
  12.     ListModel{
  13.         id: elements
  14.         ListElement{
  15.             name: "prova"
  16.         }
  17.         ListElement{
  18.             name: "gino"
  19.         }
  20.     }
  21.  
  22.     Flickable{
  23.         anchors.fill: parent
  24.         width: parent.width
  25.         contentHeight: list.height
  26.         ListView{
  27.             id: list
  28.             width: parent.width
  29.             model: elements
  30.             delegate: Item {
  31.                 signal clicked(string name)
  32.                 width: parent.width
  33.                 height: 100
  34.                 Label{
  35.                     id: label
  36.                     anchors.centerIn: parent
  37.                     text: name
  38.                     font: UiConstants.TitleFont
  39.                 }
  40.                 MouseArea{
  41.                     anchors.fill: parent
  42.                     onClicked: {
  43.                         parent.clicked(name)
  44.                     }
  45.                 }
  46.                 Rectangle{
  47.                     width: parent.width
  48.                     height: 2
  49.                     color: "white"
  50.                     anchors.bottom: parent.bottom
  51.                 }
  52.             }
  53.         }
  54.     }
  55.  
  56.     Component.onCompleted: {
  57.         add_element({"name": "test"})
  58.     }
  59. }

When the list is displayed i can see only the first list item
Thank You

2 replies

May 2, 2012

favoritas37 favoritas37
Lab Rat
148 posts

Why did you put the ListView inside the Flickable?
Most probably it would result to unexpected behavior because the mouse events would be caught by the Flickable element not letting you select an element from the list. Also in the ListView you haven’t set the height so probably this is why you can see only the first element.

So, if you only want to use the ListView remove the Flickable and add the anchors.fill: parent to the ListView.

May 2, 2012

rferrazz rferrazz
Lab Rat
22 posts

You’re right
i did not know that the ListView is already scrollable. I thought it was like a Column.
Thank you again!

 
  ‹‹ Can’t build qml example in eclipse      How I can call function in ListView delegate item. ››

You must log in to post a reply. Not a member yet? Register here!