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. Editable TableViewColumn and Delegate
Forum Updated to NodeBB v4.3 + New Features

Editable TableViewColumn and Delegate

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
10 Posts 3 Posters 3.7k 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.
  • M Offline
    M Offline
    MTOLANI
    wrote on last edited by
    #1

    Hi,
    I am new to QML and trying to use TableViewColumn and Delegate
    I am using TextEdit inside delgate but when I edit the text the changes are not being reflected to the backend
    I tried using onTextChanged, onEditingChanged but nothing works
    Please help

    FocusScope {
        property alias model: tableView1.model
    
        Rectangle {
            anchors.fill: parent
            color: "#2e2e2e"
    
            TreeView {
                id: tableView1
                anchors.fill: parent
                anchors.margins: 20
    
                TableViewColumn {
                    role: "name"
                    title: qsTr("Name")
                    width: 150
                }
                TableViewColumn {
                    role: "default"
                    title: qsTr("Default Value")
                    width: 150
                    delegate:
                        TextEdit {
                        text: styleData.value
                       
                    }
                }
                TableViewColumn {
                    role: "map"
                    title: qsTr("Value Map")
                    width: 300
                    delegate: Row {
                        spacing: 10
                        Repeater {
                            model: styleData.value
                            delegate: Row {
                                TextEdit {
                                    text: name + "="
                                }
                                TextEdit {
                                    text: value
                                    font.bold: variable
                                }
                            }
                        }
                    }
    
                }
            }
        }
    }
    
    
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      maxwell31
      wrote on last edited by
      #2

      Have a look at this: https://forum.qt.io/topic/89143/help-with-qml-tableview

      GrecKoG 1 Reply Last reply
      0
      • M maxwell31

        Have a look at this: https://forum.qt.io/topic/89143/help-with-qml-tableview

        GrecKoG Offline
        GrecKoG Offline
        GrecKo
        Qt Champions 2018
        wrote on last edited by
        #3

        @maxwell31 I'm biased but the solution of modifying the model doesn't sound very clean to me when you can do it without modification to the model.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxwell31
          wrote on last edited by
          #4

          Not sure I understand what you mean. I think the model should be modified. Maybe have a look at http://doc.qt.io/qt-5/model-view-programming.html

          GrecKoG 1 Reply Last reply
          0
          • M maxwell31

            Not sure I understand what you mean. I think the model should be modified. Maybe have a look at http://doc.qt.io/qt-5/model-view-programming.html

            GrecKoG Offline
            GrecKoG Offline
            GrecKo
            Qt Champions 2018
            wrote on last edited by GrecKo
            #5

            @maxwell31 Sorry my remark wasn't very clear :)

            Modified as in add an updateValue method when the delegate can already call setData itself automatically when doing model.yourRole = newValue

            1 Reply Last reply
            1
            • M Offline
              M Offline
              maxwell31
              wrote on last edited by maxwell31
              #6

              True. You should be able to use setData, but the problem might be to get the right role number. The prototype is

              setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole)
              

              and I don't know how to use the role name for the integer. Please tell me when you solved that

              GrecKoG 1 Reply Last reply
              0
              • M maxwell31

                True. You should be able to use setData, but the problem might be to get the right role number. The prototype is

                setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole)
                

                and I don't know how to use the role name for the integer. Please tell me when you solved that

                GrecKoG Offline
                GrecKoG Offline
                GrecKo
                Qt Champions 2018
                wrote on last edited by
                #7

                @maxwell31
                Doing model.roleName = newValue in the QML delegate is the same as doing myModel.setData(myModel.index(row, 0), newValue, roleNumber) except that you don't have to figure out the role number.

                M 1 Reply Last reply
                1
                • GrecKoG GrecKo

                  @maxwell31
                  Doing model.roleName = newValue in the QML delegate is the same as doing myModel.setData(myModel.index(row, 0), newValue, roleNumber) except that you don't have to figure out the role number.

                  M Offline
                  M Offline
                  maxwell31
                  wrote on last edited by
                  #8

                  @GrecKo
                  Ah, good to know

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    MTOLANI
                    wrote on last edited by
                    #9

                    Hi,

                    I tried the above it works. Thank you !
                    I am able to edit existing values.
                    Is there a way to add values in new row?

                    GrecKoG 1 Reply Last reply
                    0
                    • M MTOLANI

                      Hi,

                      I tried the above it works. Thank you !
                      I am able to edit existing values.
                      Is there a way to add values in new row?

                      GrecKoG Offline
                      GrecKoG Offline
                      GrecKo
                      Qt Champions 2018
                      wrote on last edited by
                      #10

                      @MTOLANI That's specific to the model you are using.

                      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