Quote Originally Posted by Halabund View Post
Based on the colliding mice example, I've gotten to the point where I have 100 animated (actually just rotating) triangles ("birds") on screen. The problem is that even without antialiasing, this is much slower than the processing version that has 150 antialiased and semi-transparent triangles of the same size in a bigger window. (I only get 50% CPU usage with Processing, 100% with Qt.)
Get rid of the timer from the bird class and its inheritance from QObject as well. Instead use QGraphicsScene::advance() and QGraphicsItem::advance(). Right now you are updating your view 100 times every frame instead of doing it just once. You should get significant speedup this way. If that not enough, come back here and we'll suggest more optimizations (like enabling cache).


1. In Processing, all drawing is done manually, so it very clear when things are being drawn. When is a QGraphicsView redrawn?
When the viewport is obscured and unobscured, when the scene changes or when the programmer schedules a redraw manually.

Does the re-draw happen every time an item is changed in some way (so every time I call rotate() on an item)?
Yes. The problem is you modify each item separately in a separate timeframe of the animation (as each item runs its own timer).

2. I don't understand how timerEvent() works completely ... Is it a good idea that each bird has its own timer, like in the colliding mice example? Would it be better to have a single timer that rotates all of the birds at once? (I actually tried this and it didn't make the program faster.)
I already answered that, I guess.

3. Is QGraphicsView at all suitable for what I'm trying to do, or is it bound to be slower than Processing? Should I try to use other means of drawing the birds (instead of QGraphicsView)?
I don't know "Processing" but Graphics View is a very fast canvas so there is a good chance it will be at least as fast as Processing once you get a grip on it.


Ok, I rewritten your code and.... it didn't give any improvement. I even reduced the number of items to 4 without any change. Then I started thinking. Qt uses degree based values, so rotating an item around needs currently 360 frames which is 12 seconds with the framerate you set. Try increasing the step of rotation to 10 and your items will magically start rotating 10 times faster. If you want to see what is "slow", increase the number of items to 10000. My optimizations would then start to matter. Setting NoViewportUpdate mode and updating manually and getting rid of separate timers should then help significantly.