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

QML Listview contentWidth always -1

    XMLWordPrintable

Details

    • macOS

    Description

      Item {
        id: rootitem
        width: list.contentWidth
        height: list.contentHeight
      
        ListView {
          id: list
          anchors.fill: parent
          model: 4
      
          delegate: Text { // Could be any Item. Even with hardcoded width/height it doesn't work.
            text: index
          }
      
          Component.onCompleted: console.log("ch: " + contentHeight + " cw: " + contentWidth)
        }
      }
      

      I'm trying to set up an item that wraps around my contents. Using the listview contentHeight works great, but contentWidth never gets set... I've burned countless hours trying to mess with implicitWidth to no avail. All examples I've seen online always use a hard-coded root width. Maybe there's an implementation strategy I'm missing here, but I cannot for the life of me get my root item to automatically wrap around the size of my contents, and the contentWidth never being set affects this (looks like it comes down to childrenRect never having a width).

      The closest related issue I can find to this is QTBUG-35063.

      I forgot to add my hack of a workaround, which I'd prefer not to use...

      delegate: Text {
        text: index
      
        Component.onCompleted: rootitem.width = (rootitem.width < width ? width : rootitem.width)
      }
      

      Attachments

        Issue Links

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

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              atemple03 Adam Temple
              Votes:
              1 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes