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
ListViewdelegate.It's essentially a
TextInputthat I want to callselect()on, giving it arguments that are stored in myListModel.Assume I have
selstartandselendfields in my model. There isn't an option inTextInputto bind these to properties; there is just theselect()function. In other circumstances I would deal with this sort of thing with aConnectionto call a function in response to a property change but that doesn't seem appropriate for a model-delegate interaction. -
@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
Connectionswas 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() ... -
I feel as though I should know how to do this but I am struggling to know what to write in my
ListViewdelegate.It's essentially a
TextInputthat I want to callselect()on, giving it arguments that are stored in myListModel.Assume I have
selstartandselendfields in my model. There isn't an option inTextInputto bind these to properties; there is just theselect()function. In other circumstances I would deal with this sort of thing with aConnectionto call a function in response to a property change but that doesn't seem appropriate for a model-delegate interaction.@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 -
@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
Connectionswas 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() ...