Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Retrieve changes made by user in ListView



  • Hi,
    I have a list view populated with data from a text file.
    The end user can make changes to these data in the ListView.
    I'm wondering how I can retrieve the changes made by the end user.
    Which signal is emitted when a value is changed and how can I retrieve it?
    Thank you


  • Moderators

    That depends entirely on how your delegate is written.

    If you are using LineEdit in your delegate, you can use onTextChanged slot, or editingFinished() signal to get the new value.



  • Thank you very munch.
    In fact I use a TextField in the delegate. So editingFinished works fine.

    Bys the way, maybe you have an idea on how I can select the text in a TextField with a double click on it?
    I couldn' find the double click signal in relation to the TextField.



  • @Bert59, Did You add

    TextField {
      selectByMouse: true
      // ...
    }
    

    ?



  • No I had not selectbyMouse: true.

    The issue I have now is because the text is a floating point number like 1.06, the double click is only selecting 1 or 06 depending on the position of the mouse.
    How can I set to select all?

    Thank you



  • Probably this is normal system behavior for selecting text.
    Try triple click to select the entire field.


  • Moderators

    If triple click does not do it, you can probably work around it by adding a MouseArea covering your text field - and handle the double click there.


  • Moderators

    @Bert59
    I'm using:

    onActiveFocusChanged: activeFocus ? selectAll() : deselect()
    

    works fine



  • onActiveFocusChanged: activeFocus ? selectAll() : deselect()
    is not working exactly as expected.
    The text is selected when the cell gets the focus, not on a double click.
    The following is working:
    onReleased: {
    selectAll()
    }
    But it looks weird so I was wondering is there is a cleaner way to achieve this.
    Thanks for your feedbacks.

    Comming back to the intial question "Retrieve changes made by user in ListView", editingFinished() works fine for getting the value changed by the user. But I also need to know the index of the item that has been changed in the ListView. How do I retrieve this?


  • Moderators

    @Bert59 said in Retrieve changes made by user in ListView:

    Comming back to the intial question "Retrieve changes made by user in ListView", editingFinished() works fine for getting the value changed by the user. But I also need to know the index of the item that has been changed in the ListView. How do I retrieve this?

    delegates do have an index property attached to them you can check that simply by (e.g.)

    Component.onCompleted: console.log(index)
    

    you can simply access it in your editing finished "slot"


Log in to reply