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

ListView draws each item on top of each other. What am I doing wrong?



  • Below code produces list view as shown in the screenshot. Probably I'm missing something very trivial but I can't figure out what?

    alt text

    import QtQuick 2.0
    
    ListModel {
        ListElement {
            flag: "us"
            name: "USA"
            strength: "5"
        }
        ListElement {
            flag: "fr"
            name: "France"
            strength: "4"
        }
        ListElement {
            flag: "nl"
            name: "Netherlands"
            strength: "2"
        }
    }
    
    import QtQuick 2.9
    import QtQuick.Window 2.2
    
    Window {
        visible: true
        width: 640
        height: 480
    
        Component {
            id: countryItem
    
            Item {
                Text {
                    text: name + " " + flag + " " + strength
                }
            }
        }
    
        ListView {
            anchors {
                fill: parent
            }
            model: TestModel{}
            delegate: countryItem
        }
    }
    

  • Moderators

    hi @tapirath
    give your countryItem -component a height, and preferably a width as well and you should be fine



  • Works perfectly thanks


Log in to reply