Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-16037

ListView contentHeight not updated correctly if model is set after construction

    XMLWordPrintable

Details

    • 95ddfa13737164c93c58ce3694ce59ec68a016d9

    Description

      Run the code below. Click anywhere to toggle between the two models. Note that the size of
      the list (yellow) changes. Comment out the ListView's "model: listModel1" line and restart.
      Click on the screen again and note that contentHeight is not updated (it stays zero and the
      height of the listbox is not set correctly).

      import Qt 4.7
      
      Item {
          width: 800
          height: 480
      
          ListModel {
              id: listModel1
              ListElement { text: "Apple" }
              ListElement { text: "Banana" }
              ListElement { text: "Orange" }
              ListElement { text: "Coconut" }
          }
      
          ListModel {
              id: listModel2
              ListElement { text: "Bird" }
              ListElement { text: "Elephant" }
              ListElement { text: "Seal" }
          }
      
          Rectangle {
              width: 200
              height: listView.contentHeight
              color: "yellow"
              anchors.centerIn: parent
      
              ListView {
                  id: listView
                  anchors.fill: parent
      
                  model: listModel1   // Comment me out to show issue
                  delegate: Item {
                      width: 200
                      height: 20
                      Text { text: model.text; anchors.centerIn: parent }
                  }
              }
          }
      
          MouseArea {
              anchors.fill: parent
              onClicked: listView.model = (listView.model == listModel1 ? listModel2 : listModel1)
          }
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            martjone Martin Jones (closed Nokia identity) (Inactive)
            mathiasm Mathias Malmqvist
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes