May 2, 2012

dFrontia dFrontia
Lab Rat
14 posts

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?

  1. ListView {
  2.     model : .....some
  3.     delegate : Item{
  4.         function fncItem(){
  5.            ......
  6.         }
  7.     }
  8.     Component.onCompiled {
  9.  
  10.        -----> I wont call to fncItem of all child Item in ListView
  11.  
  12.     }
  13. }

6 replies

May 3, 2012

task_struct task_struct
Ant Farmer
355 posts

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.

 Signature 

“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.”
- Linus Torvalds

May 3, 2012

MichK MichK
Lab Rat
70 posts

Hi,
You can not access all delegates in Component.onCompleted . Delegates [qt-project.org] 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 [qt-project.org] function

May 3, 2012

chriadam chriadam
Lab Rat
181 posts

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

May 3, 2012

dFrontia dFrontia
Lab Rat
14 posts

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

May 4, 2012

chriadam chriadam
Lab Rat
181 posts

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.

May 4, 2012

dFrontia dFrontia
Lab Rat
14 posts

HI, Respons.

I found a solution!

CurrentIndex property given Delegate Item’s function.

  1. ListView {
  2.     id:_lvTarget
  3.     ......
  4.  
  5.     delegate:Item{
  6.         function fncItem(){
  7.             .......
  8.         }
  9.     }
  10. }
  11.  
  12. function fncItemCall(){
  13.         for( var lpCnt= 0; lpCnt < _lvTarget.count; lpCnt++ )
  14.         {
  15.             _lvTarget.currentIndex=lpCnt
  16.             _lvTarget.currentItem.fncItem()   <- Can do it!
  17.         }
  18.  
  19. }

thanks lot.

 
  ‹‹ ListView rendering problem      Adding QQuickView(QWindow) to a QStackedWidget->addWidget(QWidget) ››

You must log in to post a reply. Not a member yet? Register here!