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. Accessing Delegates from Outside the Delegate
Forum Updated to NodeBB v4.3 + New Features

Accessing Delegates from Outside the Delegate

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 3.0k Views 1 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.
  • A Offline
    A Offline
    archerabi
    wrote on last edited by
    #1

    Hello,

    Can we access delegates(ListView) from outside a Delegate Declaration.Say i want to change a property like state of a Delegate.
    For eg. in this sample code can i access a particular row delegate of list_view1 ?

    @
    Component{
    id:listDelegate

        Item{
    
         }
    

    }

    ListView {
    id: list_view1
    width:parent.width
    height: parent.height

            model: myModel
            delegate:listDelegate
    
        }
    

    @

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thorbjorn
      wrote on last edited by
      #2

      This is not possible in general since delegates are created on-demand (and thrown away at will when no longer necessary). So the delegate you are requesting may in fact not exist.

      So you have to either expose the necessary properties to allow the delegate to react to that, or the delegate can call a method and pass itself as a parameter, then you know you can access the delegate through this parameter.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        archerabi
        wrote on last edited by
        #3

        Yes,Delegates are actually deleted but we can store pointers to them in javascript(I know its not advisable , but it helps achieve some fancy UI effects).

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gustavo
          wrote on last edited by
          #4

          I have a question about this solution:

          Suppose the delegate calls a method that put it on a variable (say myDelegate). This variable can be someone else's property or just a javascript variable.

          Now, suppose I remove, from the model, the item associated with this delegate instance. Will the instance itself be deleted? Or will it be retained, since there's still a reference to it in myDelegate variable? In other words, the value in myDelegate will then be undefined?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            archerabi
            wrote on last edited by
            #5

            yes the value in myDelegate will be undefined.A solution to this problem is to reset the variable in myDelegate to NULL whenever the list starts moving( onMovementStarted: ) just to make sure it doesn't point to an invalid object/delegate

            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