How I can call function in ListView delegate item.



  • 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
    
    }
    

    }
    @



  • 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.



  • 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



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



  • 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....



  • 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.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.