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. Error using rowDelegate
Qt 6.11 is out! See what's new in the release blog

Error using rowDelegate

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 392 Views
  • 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.
  • B Offline
    B Offline
    blackrue
    wrote on last edited by blackrue
    #1

    Trying to use area, actualTempF,setTempF from my ListModel in the rowDelegate below ( see the three Text)
    I tried modelData, model, just using area .... please tell me the syntax ... I am using 5.15

    import QtQuick 2.15
    import QtQuick.Controls 2.15
    import QtQuick.Window 2.0
    import QtQuick.Controls 1.4

    Dialog {
    title: "Temperature Settings"
    width: 400
    height: 300
    ListModel {
    id: tempModel
    ListElement { area: "Living Room"; actualTempF: "70"; setTempF: "72" }
    ListElement { area: "Bedroom"; actualTempF: "68"; setTempF: "70" }
    ListElement { area: "Kitchen"; actualTempF: "72"; setTempF: "68" }
    ListElement { area: "Bathroom"; actualTempF: "75"; setTempF: "74" }
    }
    TableView {
    id: tableView
    anchors.fill: parent
    model:tempModel
    rowDelegate: Rectangle {
    height: 30
    color: styleData.alternate ? "#f5f5f5" : "white"
    Text {
    anchors.left: parent.left
    anchors.leftMargin: 10
    text: area
    }
    Text {
    anchors.left: parent.children[0].right
    anchors.leftMargin: 10
    text: styleData.value.actualTempF
    }
    Text {
    anchors.left: parent.children[1].right
    anchors.leftMargin: 10
    text: modelData.setTempF
    }
    }

        TableViewColumn {
            role: "area"
            title: "Area"
            width: tableView.width / 3
        }
    
        TableViewColumn {
            role: "actualTempF"
            title: "Actual Temperature (F)"
            width: tableView.width / 3
        }
    
        TableViewColumn {
            role: "setTempF"
            title: "Set Temperature (F)"
            width: tableView.width / 3
        }
    
    
    }
    

    }

    1 Reply Last reply
    0
    • SGaistS SGaist moved this topic from Brainstorm on
    • B Offline
      B Offline
      blackrue
      wrote on last edited by
      #2

      In case anyone else wanted to know how to do this properly. I found the answer.
      You should use itemDelegate and styledata.value .. see below

      import QtQuick 2.15
      import QtQuick.Controls 2.15
      import QtQuick.Window 2.0
      import QtQuick.Controls 1.4

      Dialog {
      title: "Temperature Settings"
      width: 500
      height: 300
      ListModel {
      id: tempModel
      ListElement { area: "Living Room"; actualTempF: "70"; setTempF: "72" }
      ListElement { area: "Bedroom"; actualTempF: "68"; setTempF: "70" }
      ListElement { area: "Kitchen"; actualTempF: "72"; setTempF: "68" }
      ListElement { area: "Bathroom"; actualTempF: "75"; setTempF: "74" }
      }
      TableView {
      id: tableView
      anchors.fill: parent
      model:tempModel
      itemDelegate: Rectangle {
      height: 30
      color: styleData.alternate ? "#f5f5f5" : "white"
      Text {
      anchors.left: parent.left
      anchors.leftMargin: 10
      //text: tableView.model.get(styleData.row).area
      text: styleData.value

              }
      

      // Text {
      // anchors.left: parent.children[0].right
      // anchors.leftMargin: 10
      // text: tableView.model.get(styleData.row).actualTempF
      // }
      // Text {
      // anchors.left: parent.children[1].right
      // anchors.leftMargin: 10
      // // text: modelData.setTempF
      // text: tableView.model.get(styleData.row).setTempF
      // }
      }

          TableViewColumn {
              role: "area"
              title: "Area"
              width: tableView.width / 3
          }
      
          TableViewColumn {
              role: "actualTempF"
              title: "Actual Temperature (F)"
              width: tableView.width / 3
          }
      
          TableViewColumn {
              role: "setTempF"
              title: "Set Temperature (F)"
              width: tableView.width / 3
          }
      
      
      }
      

      }

      1 Reply Last reply
      0
      • B blackrue has marked this topic as solved on

      • Login

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