Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved compatible types for listModel delegates

    QML and Qt Quick
    2
    3
    529
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      scrub last edited by

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

      1 Reply Last reply Reply Quote 0
      • ?
        A Former User last edited by

        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
            }
        
        }
        
        1 Reply Last reply Reply Quote 0
        • S
          scrub last edited by

          thanks that answers my question.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post