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 with inline edit
Forum Updated to NodeBB v4.3 + New Features

TableView with inline edit

Scheduled Pinned Locked Moved QML and Qt Quick
tableviewinline editqt5.4
8 Posts 3 Posters 7.7k 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.
  • P Offline
    P Offline
    PhTe
    wrote on last edited by
    #1

    Im trying to create a table where the user can edit the values in one column. The idea was that if the user double clicks ( or press and hold the mouse button) the value of one column turns into an edit field, where the value can be changed. If editing is finished (enter pressed or focus lost) the edit field should be hidden and the new value be shown. Also the new value should be sent to c++ by a signal.

    But i have problems how to realise this and where to start with it. I know how to handle the signals, doubleclick, pressAndHold events and all these stuff, but i have know idea how to combine it to get a table with the described behaviour :(

    Does anyone knows an example for this? Something that is near to my table.

    H 1 Reply Last reply
    0
    • P PhTe

      Im trying to create a table where the user can edit the values in one column. The idea was that if the user double clicks ( or press and hold the mouse button) the value of one column turns into an edit field, where the value can be changed. If editing is finished (enter pressed or focus lost) the edit field should be hidden and the new value be shown. Also the new value should be sent to c++ by a signal.

      But i have problems how to realise this and where to start with it. I know how to handle the signals, doubleclick, pressAndHold events and all these stuff, but i have know idea how to combine it to get a table with the described behaviour :(

      Does anyone knows an example for this? Something that is near to my table.

      H Offline
      H Offline
      hpollak
      wrote on last edited by
      #2

      @PhTe Have you tried to work with edit-Triggers?

      QAbstractItemView.setEditTriggers

      EditTriggers-Enum

      1 Reply Last reply
      0
      • P Offline
        P Offline
        PhTe
        wrote on last edited by
        #3

        Oh, i missed to mention that i use QML.
        It seems edittriggers can only be used for qtwidgets and not in QML.

        p3c0P 1 Reply Last reply
        0
        • P PhTe

          Oh, i missed to mention that i use QML.
          It seems edittriggers can only be used for qtwidgets and not in QML.

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

          Hi @PhTe,

          Im trying to create a table where the user can edit the values in one column. The idea was that if the user double clicks ( or press and hold the mouse button) the value of one column turns into an edit field, where the value can be changed. If editing is finished (enter pressed or focus lost) the edit field should be hidden and the new value be shown.

          Create a custom delegate comprising of TextInput or TextArea. For press and hold or mouse operations you will need to define MouseArea for it. Then assign this to the itemDelegate of TableView. Use onAccepted event handler for enter key press detection.

          Also the new value should be sent to c++ by a signal.

          Create a C++ class and set it as a setContextProperty so as to expose C++ class to QML. An example can be found here. Define some Q_INVOKABLE functions in C++ which can then be invoked from QML. You can invoke this function with required parameters in onAccepted event handler of delegate created earlier.

          Hope this helps. Try it out and come back for more questions.

          157

          1 Reply Last reply
          0
          • P Offline
            P Offline
            PhTe
            wrote on last edited by
            #5

            Ok, i created a table which worked nearly as expected yesterday.
            My problem is currently how to show the TextInput, lets say in column 4, even if the user double clicks on column 1 and hide it if the user clicks outside the TextInput field or on another row.

            p3c0P 1 Reply Last reply
            0
            • P PhTe

              Ok, i created a table which worked nearly as expected yesterday.
              My problem is currently how to show the TextInput, lets say in column 4, even if the user double clicks on column 1 and hide it if the user clicks outside the TextInput field or on another row.

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

              @PhTe I guess that wont work. itemDelegate will set delegate to all fields. May be try changing readOnly property to true when clicked to make it appear that it is in edit mode.

              157

              1 Reply Last reply
              0
              • P Offline
                P Offline
                PhTe
                wrote on last edited by
                #7

                I now use a MouseArea in my item delegate which triggers a Loader, if the item is in column 3, to overlay the text with an input field.
                This works so far. My next step is to hide the input field if the user clicks on an other cell, but if have not idea to get this.
                Does anyone have a solution for it?

                itemDelegate: Rectangle {
                
                    Text {
                        id: textItem
                        text: styleData.value
                    }
                
                    Loader {
                        id: editLoader
                    }
                
                    MouseArea {
                        anchors.fill: parent
                
                        onPressAndHold:  {
                            if(styleData.column === 3) 
                                 editLoader.sourceComponent = textInputComponent
                        }
                    }
                
                    Component {
                        id: textInputComponent
                
                        Component.onCompleted: {
                            textinput.forceActiveFocus();
                        }
                
                         TextField {
                               id: textinput
                              anchors.fill: textItem
                              text: styleData.value
                         }
                    }
                }
                p3c0P 1 Reply Last reply
                0
                • P PhTe

                  I now use a MouseArea in my item delegate which triggers a Loader, if the item is in column 3, to overlay the text with an input field.
                  This works so far. My next step is to hide the input field if the user clicks on an other cell, but if have not idea to get this.
                  Does anyone have a solution for it?

                  itemDelegate: Rectangle {
                  
                      Text {
                          id: textItem
                          text: styleData.value
                      }
                  
                      Loader {
                          id: editLoader
                      }
                  
                      MouseArea {
                          anchors.fill: parent
                  
                          onPressAndHold:  {
                              if(styleData.column === 3) 
                                   editLoader.sourceComponent = textInputComponent
                          }
                      }
                  
                      Component {
                          id: textInputComponent
                  
                          Component.onCompleted: {
                              textinput.forceActiveFocus();
                          }
                  
                           TextField {
                                 id: textinput
                                anchors.fill: textItem
                                text: styleData.value
                           }
                      }
                  }
                  p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #8

                  @PhTe Use activeFocus signal. Check it in onActiveFocusChanged handler.

                  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