compatible types for listModel delegates



  • What qml types are compatible as delegates with listModel->deleagte?


  • Moderators

    Hi! What do you mean by "compatible type as delegate"? You create a Component and put into it whatever you like, e.g. Rectangle, Text, Row, etc.

    import QtQuick 2.5
    import QtQuick.Window 2.2
    
    Window {
        visible: true
        width: 200; height: 200
    
        ListModel {
            id: fruitModel
    
            ListElement {
                name: "Apple"
                cost: 2.45
            }
            ListElement {
                name: "Orange"
                cost: 3.25
            }
            ListElement {
                name: "Banana"
                cost: 1.95
            }
        }
    
        Component {
            id: fruitDelegate
            Row {
                spacing: 10
                Rectangle {
                    height: parent.height/2
                    anchors.verticalCenter: parent.verticalCenter
                    width: height
                    color: "red"
                }
                Text { text: name }
                Text { text: cost.toString().replace(".", ",") + " €" }
            }
        }
    
        ListView {
            anchors.fill: parent
            model: fruitModel
            delegate: fruitDelegate
        }
    
    }
    


  • thanks that answers my question.


Log in to reply
 

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