refreshing Gridview components on button click
-
wrote on 8 Oct 2018, 12:16 last edited by
Hi,
I have a gridview which has 30-40 components. And i have a button on the screen, which when pressed changes the image source of the components. But the components which are visible on the gridview do not alter but as i scroll down, i find that the components which were not visible previously have altered image. And on scrolling back to previous position, the components which were not refreshed are now altered. In short the gridview components do not alter spontaneously. Any Help??
-
Hi,
I have a gridview which has 30-40 components. And i have a button on the screen, which when pressed changes the image source of the components. But the components which are visible on the gridview do not alter but as i scroll down, i find that the components which were not visible previously have altered image. And on scrolling back to previous position, the components which were not refreshed are now altered. In short the gridview components do not alter spontaneously. Any Help??
How do you actually change the image source of the components ?
-
wrote on 8 Oct 2018, 12:43 last edited by
Component { Image { id:folderImg width:140 height:175 source: selectAllFlag?"Assets/RecBtn2.png":"Assets/RecBtn1.png"; anchors.horizontalCenter: parent.horizontalCenter } }
where selectAllFlag is the status of the button.
-
Component { Image { id:folderImg width:140 height:175 source: selectAllFlag?"Assets/RecBtn2.png":"Assets/RecBtn1.png"; anchors.horizontalCenter: parent.horizontalCenter } }
where selectAllFlag is the status of the button.
wrote on 8 Oct 2018, 14:34 last edited by Yaswanth 10 Aug 2018, 14:52@Sam_George just to understand, you can add mousearea to image and print the value of selectAllFlag on click. If selectAllFlag value fine add a handler for selectAllFlag in delegate and set the source of the image on it. Like onSelectAllFlagChanged:
selectAllFlag ? source = second : source= first -
@Sam_George just to understand, you can add mousearea to image and print the value of selectAllFlag on click. If selectAllFlag value fine add a handler for selectAllFlag in delegate and set the source of the image on it. Like onSelectAllFlagChanged:
selectAllFlag ? source = second : source= firstwrote on 8 Oct 2018, 14:51 last edited by ODБOï 10 Aug 2018, 14:51hi
@Yaswanth said in refreshing Gridview components on button click:
Like onSelectAllFlagChanged:
selectAllFlag ? source : second : firstconditionnal operator will not work like this (use "=" for assign, not ":" ), correct verion is
onSelectAllFlagChanged: selectAllFlag ? source= second : source = first
-
hi
@Yaswanth said in refreshing Gridview components on button click:
Like onSelectAllFlagChanged:
selectAllFlag ? source : second : firstconditionnal operator will not work like this (use "=" for assign, not ":" ), correct verion is
onSelectAllFlagChanged: selectAllFlag ? source= second : source = first
wrote on 8 Oct 2018, 14:53 last edited by@LeLev it was typo :-(
-
Qt Champions 2022wrote on 10 Oct 2018, 15:01 last edited by dheerendra 10 Oct 2018, 15:14
Why are you changing the delegate directly ? You can change model. It should update the view. It is auto taken care.
If you still would like to do what you wanted -
Changing directly in component will not help. Delegate are individual objects and source is already set with your image. If you change in component, it will not change source of already created objects. So when you scroll down, new delegate objects are getting created. Hence you will see the new image. When you scroll back, old delegate objects would have been destroyed. So it is creating new objects. Hence you will see new images. If you want to change the existing delegate object, get the reference of all the child objects. All the delegate objects are parented to contentItem. So get all the children of contentItem and update them. -
wrote on 11 Oct 2018, 06:37 last edited by
Thank you all,
It worked. I made one extra property in Component Item which gets updated whenever the selectAllFlag status changes. So I added a handler for this new variable inside the Component Item which on change changes the source of the image. Thank you all once again..
1/8