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

Trigger function call in ListView delegate



  • I feel as though I should know how to do this but I am struggling to know what to write in my ListView delegate.

    It's essentially a TextInput that I want to call select() on, giving it arguments that are stored in my ListModel.

    Assume I have selstart and selend fields in my model. There isn't an option in TextInput to bind these to properties; there is just the select() function. In other circumstances I would deal with this sort of thing with a Connection to call a function in response to a property change but that doesn't seem appropriate for a model-delegate interaction.



  • @J-Hilk Thanks. My problem (late last night!) with Connections was that I couldn't see how to make a connection to a model role. I resolved it by introducing an intermediate property in the component and binding the model role to that. I don't know if there is a better or more direct way but that seems to work.

         ...
         property var start: selstart  // selstart is a model role
    
         onStartChanged: doSomething()
         ...
    

  • Moderators

    @Bob64
    If I understand you correctly, than I would personally go with either a Connection inside the delegate - like you suggested - or via a Binding
    https://doc.qt.io/qt-5/qml-qtqml-binding.html



  • @J-Hilk Thanks. My problem (late last night!) with Connections was that I couldn't see how to make a connection to a model role. I resolved it by introducing an intermediate property in the component and binding the model role to that. I don't know if there is a better or more direct way but that seems to work.

         ...
         property var start: selstart  // selstart is a model role
    
         onStartChanged: doSomething()
         ...
    

Log in to reply