Animating a Delegate
-
Is there a standard way to animate a delegate?
I want to create a delegate that shows an item in a loading state. There are three possibilities for the state of the item:
Unloaded,Loading, orLoaded. While the item is in theLoadingstate, I want the delegate to show an animated spinning wheel. (Note that I don't have actual progress for how far loaded the item is. I just know that it is in aLoadingstate.)Is it possible for a delegate to be animated like that? Do I need to constantly emit
dataChanged()from the model to force the delegate to be repainted? Or is there a way for the delegate to force itself to be repainted every frame (or on a repeating timer), without relying on the model emitting adataChanged()signal? -
Hi,
How many items are you expecting to show at a given time ?
-
@SGaist In a usual case, I wouldn't expect to show more than fifty at once. There may be some edge cases where I show a few hundred.
-
Then I wouldn't recommend showing fifty to several hundreds spinning wheels at the same time. Not that it's not doable but this sounds like a waste of resources.
In any case, one possible way to implement that is to do the painting yourself and have a timer at the model level that triggers every so often incrementing a number that would correspond to the number of points you want to show.
Another possible way to do that, that is also less complicated, is to simply have your model returnLoading .,Loading..,Loading...and loop on that (or more dots).
It's also a sort of animation but you don't need a special delegate. -
Adding to @SGaist: Maybe a progress bar delegate is a better alternative. While showing both the loading state and the progress, you don’t need permanent signal emissions. If it’s minuscule, it needs no more than 10-15 updates between 0 and 100%.
Theoretically, if you get hold of its pointer, you could even update it from outside the model, e.g. from a worker thread with a signal/slot connection. The model would just notify the view that loading has been triggered. The view creates the progress bar delegate and informes the worker about the pointer, who keeps it in a QPointer to know whether it is still around.