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. TableView rowDelegate - Getting values of column prior to commiting to table
Forum Updated to NodeBB v4.3 + New Features

TableView rowDelegate - Getting values of column prior to commiting to table

Scheduled Pinned Locked Moved QML and Qt Quick
qtableview
2 Posts 2 Posters 931 Views 2 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.
  • D Offline
    D Offline
    DBoosalis
    wrote on last edited by p3c0
    #1

    How to get a handle to values of TableView before they are commited to table. Below is a clip of my code, in the row delegate I have a Save button and when clicked I would like to get a handle to all the fields of the row delegate. (there are 4) . If anyone has a clue please scroll down to the save button below and look at the onClicked Method.

    Thank you very much for any info you can provide.

     TableView {
            id:serverTable
            anchors.margins:15
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.top: titleArea.bottom
            anchors.topMargin: fm.height*2
            anchors.bottom: serverButtonArea.top
            anchors.bottomMargin: 15
            alternatingRowColors: true
            selectionMode: SelectionMode.SingleSelection
            model: serverListModel;
            onCurrentRowChanged : {
                console.log("CURRENT ROW CHANGED");
            }
            rowDelegate: Rectangle {
                height: styleData.selected ? fm.height*1.8 : fm.height*1.3
                Behavior on height{ NumberAnimation{} }
                color:   styleData.selected ? "lightsteelblue" :  (styleData.alternate? "white" : "#DDE8FF")
                RowLayout {
                    id: buttons
                    x: nameCol.width + ipCol.width + portCol.width + maxRetriesCol.width + 20
                    anchors.verticalCenter: parent.verticalCenter
                    visible:  styleData.selected ? true : false
                    spacing: 10
                    Button {
                        id: saveB
                        text: "Save"
                        style : ButtonStyle {
                            background: Rectangle {
                                implicitWidth: 60
                                implicitHeight: fm.height*1.2
                                border.width: control.activeFocus ? 2 : 1
                                border.color: "#888"
                                radius: 5
                                gradient: Gradient {
                                    GradientStop { position: 0 ; color: control.pressed ? "#ccc" : "#eee" }
                                    GradientStop { position: 1 ; color: control.pressed ? "#aaa" : "#ccc" }
                                }
                            }
                        }
                        onClicked: {
                            console.log("Row = " + styleData.row);
                            //console.log("What goes here to get contents of cell  = " + nameCol.);      // TRYING TO GET CONTENTS OF COL 0
                        }
                    }
                    Button {
                        id: canceB
                        text: "Cancel"
                        style : ButtonStyle {
                            background: Rectangle {
                                implicitWidth: 60
                                implicitHeight: 22
                                border.width: control.activeFocus ? 2 : 1
                                border.color: "#888"
                                radius: 4
                                gradient: Gradient {
                                    GradientStop { position: 0 ; color: control.pressed ? "#ccc" : "#eee" }
                                    GradientStop { position: 1 ; color: control.pressed ? "#aaa" : "#ccc" }
                                }
                            }
                        }
                    }
    
                }
            }
            TableViewColumn {
                id: nameCol
                role: "name"
                title: "Name"
                width: 100
            }
            TableViewColumn {
                id: ipCol
                role: "ip"
                title: "IP Address"
                width: 200
            }
            TableViewColumn {
                id : portCol
                role: "port"
                title: "Port"
                width: 80
            }
            TableViewColumn {
                id: maxRetriesCol
                role: "maxRetries"
                title: "Max Retries"
                width: 100
            }
            itemDelegate: {
                return editableDelegate;
            }
    

    Edited: Please use ``` for posting code blocks - p3c0

    p3c0P 1 Reply Last reply
    0
    • D DBoosalis

      How to get a handle to values of TableView before they are commited to table. Below is a clip of my code, in the row delegate I have a Save button and when clicked I would like to get a handle to all the fields of the row delegate. (there are 4) . If anyone has a clue please scroll down to the save button below and look at the onClicked Method.

      Thank you very much for any info you can provide.

       TableView {
              id:serverTable
              anchors.margins:15
              anchors.left: parent.left
              anchors.right: parent.right
              anchors.top: titleArea.bottom
              anchors.topMargin: fm.height*2
              anchors.bottom: serverButtonArea.top
              anchors.bottomMargin: 15
              alternatingRowColors: true
              selectionMode: SelectionMode.SingleSelection
              model: serverListModel;
              onCurrentRowChanged : {
                  console.log("CURRENT ROW CHANGED");
              }
              rowDelegate: Rectangle {
                  height: styleData.selected ? fm.height*1.8 : fm.height*1.3
                  Behavior on height{ NumberAnimation{} }
                  color:   styleData.selected ? "lightsteelblue" :  (styleData.alternate? "white" : "#DDE8FF")
                  RowLayout {
                      id: buttons
                      x: nameCol.width + ipCol.width + portCol.width + maxRetriesCol.width + 20
                      anchors.verticalCenter: parent.verticalCenter
                      visible:  styleData.selected ? true : false
                      spacing: 10
                      Button {
                          id: saveB
                          text: "Save"
                          style : ButtonStyle {
                              background: Rectangle {
                                  implicitWidth: 60
                                  implicitHeight: fm.height*1.2
                                  border.width: control.activeFocus ? 2 : 1
                                  border.color: "#888"
                                  radius: 5
                                  gradient: Gradient {
                                      GradientStop { position: 0 ; color: control.pressed ? "#ccc" : "#eee" }
                                      GradientStop { position: 1 ; color: control.pressed ? "#aaa" : "#ccc" }
                                  }
                              }
                          }
                          onClicked: {
                              console.log("Row = " + styleData.row);
                              //console.log("What goes here to get contents of cell  = " + nameCol.);      // TRYING TO GET CONTENTS OF COL 0
                          }
                      }
                      Button {
                          id: canceB
                          text: "Cancel"
                          style : ButtonStyle {
                              background: Rectangle {
                                  implicitWidth: 60
                                  implicitHeight: 22
                                  border.width: control.activeFocus ? 2 : 1
                                  border.color: "#888"
                                  radius: 4
                                  gradient: Gradient {
                                      GradientStop { position: 0 ; color: control.pressed ? "#ccc" : "#eee" }
                                      GradientStop { position: 1 ; color: control.pressed ? "#aaa" : "#ccc" }
                                  }
                              }
                          }
                      }
      
                  }
              }
              TableViewColumn {
                  id: nameCol
                  role: "name"
                  title: "Name"
                  width: 100
              }
              TableViewColumn {
                  id: ipCol
                  role: "ip"
                  title: "IP Address"
                  width: 200
              }
              TableViewColumn {
                  id : portCol
                  role: "port"
                  title: "Port"
                  width: 80
              }
              TableViewColumn {
                  id: maxRetriesCol
                  role: "maxRetries"
                  title: "Max Retries"
                  width: 100
              }
              itemDelegate: {
                  return editableDelegate;
              }
      

      Edited: Please use ``` for posting code blocks - p3c0

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi @DBoosalis
      If serverListModel is a C++ model better to do it on model side. You can write a Q_INVOKABLE function in model to grab the data and call it from QML. If it is a ListModel you can iterate the model and use get to fetch data. Eg:

      tableView.model.get(0).title
      

      157

      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