Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. compatible types for listModel delegates

compatible types for listModel delegates

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 798 Views 1 Watching
  • 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 Offline
    S Offline
    scrub
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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
      0
      • S Offline
        S Offline
        scrub
        wrote on last edited by
        #3

        thanks that answers my question.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved