Hello,
I'm not a programmer by trade, but I'm hoping to be able to use Qt to display the output of physics simulations in real time (while the simulation is running).
I am trying to learn Qt and QGraphicsView by implementing a flocking simulation that I already did in Processing.
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.)
I believe that the bad performance is due to my using Qt incorrectly (and not Qt being slow). I'd appreciate it very much if you could give me some hints on how to do this properly, or what to do differently. Here's the program. (I tried to remove everything that was not essential.)
A few specific questions:
1. In Processing, all drawing is done manually, so it very clear when things are being drawn. When is a QGraphicsView redrawn? Does the re-draw happen every time an item is changed in some way (so every time I call rotate() on an item)?
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.)
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 am new to Qt, and my understanding of it is clearly lacking, so please be gentle
P.S. I'm on Windows.
Bookmarks