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. Trigger function call in ListView delegate

Trigger function call in ListView delegate

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 577 Views
  • 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.
  • B Offline
    B Offline
    Bob64
    wrote on last edited by
    #1

    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.HilkJ 1 Reply Last reply
    0
    • J.HilkJ J.Hilk

      @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

      B Offline
      B Offline
      Bob64
      wrote on last edited by
      #3

      @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()
           ...
      
      1 Reply Last reply
      1
      • B Bob64

        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.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #2

        @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


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        B 1 Reply Last reply
        1
        • J.HilkJ J.Hilk

          @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

          B Offline
          B Offline
          Bob64
          wrote on last edited by
          #3

          @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()
               ...
          
          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved