PDA

View Full Version : Looking for Suggestions for Implementing Flashing in a QGraphicsScene



Goug
5th May 2011, 00:11
I'm porting an application where any number of items may flash to an alternate color every half-second (i.e. from bright red to dark red, or from white on blue to blue on white). I'm using a graphics scene for my drawing, and I'm thinking ahead to implementing the flashing mechanism. The number of objects will typically be in the hundreds with extreme cases into a few tens of thousands. There will also be up to 16 windows, each with its own scene, although typically only one to four windows are used at a time.

The graphics items will be subclasses with enough information to recalculate their drawing colors when notified that it's time to switch colors. The only issue I'm concerned about is doing the notification in an efficient manner since this happens every half-second.

The idea that I have is to use a timer that fires every half-second and connect it to a slot in my subclass of the QGraphicsScene. The slot will use the "items" method to get a list of all of the items in the scene, and iterate over them, calling a method to tell them to switch colors. Doing it this way is very straightforward.

Is there a more efficient way to notify all of the items within a scene? I've looked somewhat at the event handling, but I'm not sure that would be any more efficient, and to be honest, I have some trouble understanding all of the nuances or even if there's a way to send an event to the scene and have it propagate to all items. However, if the experts say to go that route, I'll take another look at it.

Thanks,
Doug