How to set Flickable.contentHeight with dynamic height of Column?



  • how can i reduce my scroll-area to the size of the Column
    in my real example the 3 rectangles are a model and Loaders with items of different height, that sometimes change based on the model

    but i can't even get it work in this simple example

    and ideas?

    import QtQuick 2.5
    
    Item {
        width: 500
        height: 500
    
        Flickable {
            id: myList
    
            width: 200
            height: 100
            contentWidth: width
            // how to set this property based on Column.height
            contentHeight: 50+2+70+2+20+2 // list.height is NaN
            clip: true
    
            Column {
                id: list
                spacing: 2
    
                Rectangle { color: "red"; width: 50; height: 50 }
                Rectangle { color: "green"; width: 20; height: 70 }
                Rectangle { color: "blue"; width: 50; height: 20 }
            }
        }
    
        Rectangle {
            anchors.fill: myList
            color: "transparent"
            border { width: 2; color: "green" }
        }
    }
    

    Screenshot:

    0_1563542994391_Screenshot from 2019-07-19 15-29-36.png


  • Moderators

    @LowLevelM

    this should work:

    Flickable {
            id: myList
    
            anchors.fill:parent
            contentWidth: width
            contentHeight: lastItem.y + lastItem.height
            clip: true
    
            Column {
                id: list
                spacing: 2
    
                Rectangle { color: "red"; width: 50; height: 50 }
                Rectangle { color: "green"; width: 20; height: 70 }
                Rectangle { id:lastItem; color: "blue"; width: 50; height: 20 }
            }
        }
    


  • The real height for such items as Column is stored at implicitHeight property. Just set contentHeight: list.implicitHeight for your flickable.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.