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. How I can call function in ListView delegate item.
Forum Updated to NodeBB v4.3 + New Features

How I can call function in ListView delegate item.

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 4 Posters 9.8k 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.
  • D Offline
    D Offline
    dFrontia
    wrote on 2 May 2012, 16:32 last edited by
    #1

    Hi.

    ListView delegate item has function.
    I wont call to the function from ListView element.

    Do you know how to do it?

    @
    ListView {
    model : .....some
    delegate : Item{
    function fncItem(){
    ......
    }
    }
    Component.onCompiled {

       -----> I wont call to fncItem of all child Item in ListView
    
    }
    

    }
    @

    1 Reply Last reply
    0
    • T Offline
      T Offline
      task_struct
      wrote on 3 May 2012, 06:11 last edited by
      #2

      Hi,

      I'm not sure that you can do that. Even if you manage to get access to delegates, ListView contains delegates only for visible and cached items. So you can't call fncItem function for all items in list.

      "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

      • Linu...
      1 Reply Last reply
      0
      • M Offline
        M Offline
        MichK
        wrote on 3 May 2012, 07:23 last edited by
        #3

        Hi,
        You can not access all delegates in Component.onCompleted . "Delegates":http://qt-project.org/doc/qt-4.8/qml-listview.html#delegate-prop are created as needed so you can access only some of them.

        However you can access delegates as children of contentItem of your ListView element. If I have to access delegate I use "childAt":http://qt-project.org/doc/qt-4.8/qml-item.html#childAt-method function

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chriadam
          wrote on 3 May 2012, 07:31 last edited by
          #4

          Can't you define the function outside the delegate, and simply pass a reference to the delegate, to the function as a parameter?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dFrontia
            wrote on 3 May 2012, 18:28 last edited by
            #5

            Hi,thinks for replay.

            Why i wont to call function in delegate.
            So, delegate component has properties,
            and you can change the properties how to do your operations (MouseArea,Flicable ...)

            And I want to implement Reset button. the reset button turn to properties in delegate.

            do you have any other idea that call function in delegate....

            1 Reply Last reply
            0
            • C Offline
              C Offline
              chriadam
              wrote on 4 May 2012, 01:13 last edited by
              #6

              So, each delegate in your list has a completely different set of properties? (Not just property values, which of course will be different; I mean, is each delegate of a different type, with a different set of dynamic properties?) If not, you can use a single function in the scope of the parent, and pass each delegate to it as a parameter.

              In general, you want each delegate to be as simple and quick to create as possible (since at full-speed-flick you'll probably be creating somewhere in the range of 600 to 1000 of these per second (60fps, 10 to 15 delegates displayed per frame)), and constructing identical js functions would be wasted effort.

              But I'm not sure that I fully understand your use case, so maybe this advice doesn't apply in your situation.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dFrontia
                wrote on 4 May 2012, 05:01 last edited by
                #7

                HI, Respons.

                I found a solution!

                CurrentIndex property given Delegate Item's function.

                @
                ListView {
                id:_lvTarget
                ......

                delegate:Item{
                    function fncItem(){
                        .......
                    }
                }
                

                }

                function fncItemCall(){
                for( var lpCnt= 0; lpCnt < _lvTarget.count; lpCnt++ )
                {
                _lvTarget.currentIndex=lpCnt
                _lvTarget.currentItem.fncItem() <- Can do it!
                }

                }
                @

                thanks lot.

                1 Reply Last reply
                0

                1/7

                2 May 2012, 16:32

                • Login

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