Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

ListView Size problem



  • @dheerendra @J-Hilk @LeLev @Yunus

    When i click down-arrow of keyboard then focus get changed and it shows next listview element, but problem here is, initially it is showing 2 Listelement but as i go down so after 2 listelement it's height is getting increased and when i go at last element, it's height comes back to original.

    what is the problem here, why the height is changing as i am going from 1 element to last element ???

    import QtQuick 2.6
    import QtQuick.Window 2.2
    
    Rectangle
    {
        id:top
        visible: true
        width: 100
        height: 150
    
        ListModel
        {
            id:time
            ListElement{time_scale:"30 MIN"}
            ListElement{time_scale:"1 HOUR"}
            ListElement{time_scale:"2 HOUR"}
            ListElement{time_scale:"3 HOUR"}
            ListElement{time_scale:"4 HOUR"}
            ListElement{time_scale:"5 HOUR"}
            ListElement{time_scale:"6 HOUR"}
        }
    
        Component
        {
            id:comp
            Rectangle
            {
                width: parent.width
                height: 40
                color:"gray"
                border.width: 1
                Text
                {
                    text:time_scale
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.horizontalCenter: parent.horizontalCenter
                }
            }
        }
    
        Component
        {
            id:high
            Rectangle
            {
                width: parent.width
                height: 40
                color:Qt.rgba(0,0,255,0.1)
                z:5
                /*opacity: 0.5 this will also work */
            }
        }
    
        Rectangle
        {
            id:master
            width: parent.width
            height: parent.height/2
            anchors.centerIn: parent
            color: "red"
    
            ListView
            {
                id:ge
                spacing:0
                height: parent.height
                width: parent.width
                model:time
                delegate: comp
                highlight: high
                focus:true
            }
        }
    
    }
    
    


  • @Bhushan_Sure Hello. I don't know your final application, but if you change the height of master component (eliminate the "/2") the problem fix? I test this solution and the change of height was eliminated...



  • @oria66 if i eliminate master height(/2) , then it will take windows height then in that case it is working fine, But i don't have to give window's height, i want some specific height only. Only i case of parent height it is working fine.



  • Hi! setting clip property of listview to true would eliminate the visibility of unwanted delegate. But, I'm not sure whether this is the correct solution. Clip operation is a costly operation, would impact the performance.



  • @Yashpal It work's fine for me, Thank you Yashpal :)


Log in to reply