I recently wrote a Qt-based application in C++ that relies heavily on the QGraphicsView framework that made its first public appearance in Qt 4.2. QGraphicsView has been the target of some criticism for poor performance. I am a long-time user of Qt3’s QCanvas class which served me very well, in performance terms, but that lacked several features that made it both difficult to use and less pretty. Namely, it had poor support for mouse handling and item selection, and it had no support for anti-aliasing or alpha-level transparency. The one thing it did have, however, was speed, blazing fast speed. I could throw hundreds of QCanvasItems on the screen with no apparent slow down. Blazing speed.
Then along came QGraphicsView, which promised to be every bit as fast as QCanvas, but with a much more intuitive mouse handling, item selection, and animation API. It’s true, the QGraphicsView is miles ahead of QCanvas in that regard. You basically get all that stuff for free. It even sports multi-select using both meta keys and a rubber band, all built in. It’s fantastic. What QGraphicsView doesn’t provide, however, is speed. Over the past few months I’ve found a couple tricks that speed things up a bit. Read on for three tips that have helped me improve QGraphicsView performance.
(more…)