A GraphicsView sneak-peek

Hi, everyone!

I'm back in Norway now, after having been all over (half) the world, talking about threads and graphics in Qt 4 for the Developer Road Show 2006. Only one stop left now: Hamburg, next week, which is rumored to be a fairly large event with over 70 people signed up. This has been a good experience all in all, the best part of course getting a great deal of face-to-face-with-customer time. And I have to say, more than anything else, our customers are waiting for QCanvas. So that's what this blog is about.

Have you seen this robot?

Have you ever used QCanvas? It's a set of classes for visualizing light-weight graphical shapes on a 2D canvas. With collision detection, view transformations (like zooming, rotation, etc.), and support for managing millions of items efficiently, this tool has been used to write everything from charting apps, CAD / vector drawing apps, games (typically board-, platform- or asteriods-like games), and image editors. The classic QCanvas app, however, is the flow chart / UML editor tool. Imagine an API for the editor widget, and you're pretty close to what QCanvas is. It's simply amazing to see what people are using QCanvas for. My most common responses to seeing a customer demo are:

"No way, that can't possibly be based on QCanvas!? QCanvas doesn't support that, does it!?"

QCanvas doesn't support what our customers are using it for. Hehe ;-). At the same time, isn't it amazing how much you can tweak Qt classes to do exactly what you want them to? I must salute Warwick Allison, who wrote the original canvas, for coming up with a design that provides for so many possibilities. :-D

QCanvas was phased out of Qt with Qt 4. The main reason for this was that we were sure to finish the successor, and provide that as a replacement in 4.0. Unfortunately, the impact of finishing the 4.0 release was so significant that we couldn't make it. So the replacement project, GraphicsView, was postponed, and QCanvas became part of Qt 4's Qt3Support library. Now, Qt 4.1 was released shortly after, addressing very many 4.0 issues, and adding the missing classes that we couldn't finish for 4.0. Unfortunately, GraphicsView wasn't ready yet.

With 4.2 (hopefully available in Q3/Q4 this year), GraphicsView is finally here. GraphicsView is QCanvas' official successor. This project has taken into account all the applications that we have seen QCanvas being used for, removing most of the things that people had to hack in earlier, and making proper features instead. The heart of the new project is in its new features.

In this example, QGraphicsView is used to visualize thousands of shapes that all have arbitrary transformations, colors and transparency. Click the image to see a 1:1 screenshot.

Let's do a little rundown of some new features for GraphicsView. Keep in mind that this is a snapshot of the current set of features, and it may change between now and the final release. Scroll to the end of this article to see how you can influence the final touches of GraphicsView before it's released.

  • Full double-precision coordinate system. Including negative world coordinates.
  • Item interaction support through event propagation.
    • All items can receive key, mouse, focus, and accessibility events.
    • Mouse events use real coordinates.
    • Some features, like selection and moving, are provided by default.
  • Items can now be rotated, scaled, etc., individually.
  • Items can now have a parent, and a list of children. Item positions and transformations are propagated from parent to child.
  • Support for OpenGL.
    • You can render onto a QGLWidget by inserting a new QGLWidget into the view.
    • The items can either draw using QPainter, or using raw GL, with untransformed coordinates.
  • View transformations now keep the center aligned.
  • The chunks in QCanvas are no longer explicit. The scene is automatically indexed, using an axis aligned BSP tree.
  • Animation support. Out with static item velocity, here comes proper animation path support.
  • The text item has as powerful editing capabilities as QTextEdit. Seriously. ;-)
  • Collision detection has been greatly improved.
"What? Who wouldn't want to edit text rotated 170 degrees and with a 40% skew?" Four views visualizing a scene with 4 million chips. You can navigate the scene in real-time, zoom in to read the text on each chip, or zoom out and see the big picture: a bunch of happy trolls chilling.

In general, one major message is that the API is now so pleasant to work with that everyone will want to use it!

Now if this features list changes, and it probably will, then please don't sue anyone for it. ;-) No, seriously, Qt 4.2 is still many months away, and we will adapt to the feedback from when the first snapshots are available. QGraphicsView will be available as soon as we start generating snapshots for 4.2. Around that time, we may also release a beta package. When that happens, everyone must run and grab a snapshot, and start writing GraphicsView applications ;-). And let us know what you think. Where? There are several channels available.

  • Post to qt-interest ( - include GraphicsView in the subject.
  • Customers, you can post suggestions through your regular support channels.

Now stay put, and wait for the first snapshots of 4.2 to appear. There's a lot of excellent stuff coming up in this release.

Blog Topics: