Anchor Layout available in Qt 4.6 repository

This post is just to let you know that the Qt approach to Anchor Layouts, the QGraphicsAnchorLayout is available in the Qt 4.6 repository.

To browse the source or download a tarball, visit Qt Gitorious.

As the name implies, the current version is only available for the Graphics View Framework, ie. it is a QGraphicsLayout, not a QLayout. The current version is still under development and still have know issues, specially with impossible arrangements of items. You can expect improvements through the next month though.

Check the QGraphicsAnchorLayout header for its public API while documentation is not available. I’m going to post more about its usage soon as well.

Comments are always welcome!

Canola-like layout in Qt Kinetic

Hi all,

We’ve just uploaded a new video showing our latest animated layout example.

You can check it at:
OpenBossa’s Youtube Channel

Or here:

Rather than showing how to animate from one layout to another, this example shows how could a Qt user create his/her own custom layout that uses QGraphicsLayoutProxies internally to animate its items.

From the usage point of view, once the layout is ready, all one has to do is to add or remove widgets to the layout or resize it to see them animating to the right places.


Using QAnimation to create Animated Qt Layouts

In this post I’ll share a little bit about what we’ve been working with, Animated Layouts in Qt. To be more precise, how we have been animating QGraphicsLayouts.


If you are familiar with Qt, chances are you have already used layouts and widgets a couple times. If you haven’t, try to think of a layout as a set of geometry rules, or principles, that are applied to the children widgets when the layout is associated to a parent widget.

In other words, imagine you have a box drawn on the screen, and, inside it, three widgets, say, a button, a checkbox and a label. Now imagine you want these three components to be organized somehow inside the box, horizontally aligned for instance. In Qt all you have to do is to apply an horizontal layout to the box and its widgets (button, checkbox and label) will follow the rules enforced by that layout.

The Goal

While existing layouts work fine for forms  other static UIs but lack something when seek the development of rich, animated, interfaces, as the one in Canola 2. In these scenarios animating from different layouts and/or different layout states is a must, and that’s what we went after. As the starting point, we focused on the Graphics View Framework and therefore started with QGraphicsLayouts rather than QLayouts. After talking with the guys at Qt Software we found a solution that enables:

  • animated transitions from one QGraphicsLayout to a completely different one (grid to linear, for instance);
  • animated transitions from one QGraphicsLayout state to another (when an item is added for instance, or items are re-arranged);
  • works with all third-party QGraphicsLayout subclasses you may have coded to fit your personal needs; and
  • works with all third-party widgets.

The result

A video is worth more than a bunch of words. :-)In this demo we show:

  • Addition of new items to a visible layout;
  • Change between three different layouts (horizontal, vertical and grid); and
  • Changes in the parent widget size.

Can’t see the video? Watch it on YouTube:

The Usage

This post is focused on the internals but read MoRpHeUz recent post about this subject for the end-user point of view.

The Solution

We had a strong requirement of providing compatibility with 3rd party layouts and widgets, we also couldn’t break Qt’s API or ABI. To understand the next step it is necessary to know a little bit about how QGraphicsLayouts work in Qt, but, in a nutshell what happens when a layout is applied to a widget is the following:

  • When the parent widget (the outer box) undergoes a change (is resized for instance), its associated layout is informed about it.
  • The layout recalculates new geometries for each of the child widgets (the label, the button and the checkbox).
  • The layout sets the new children geometries.

What we did was to create an Animated Layout Proxy that sits between the Layout and each of the child widgets. Due to the way Qt is organized what is expected then is that our proxies pass along the geometry change information they received from the layout to the item below it. The trick here is that rather than sending the geometry change request immediatelly, the Proxy creates a QAnimation from the former state to the new one. The result after the animation is finished is the same, the child widgets were set to their new geometries, what is different however is that the widget moves in an animated, sleek way, rather than at once, which is the standard.

The high-level diagram below shows how the Animated Layout Proxy is inserted in the existing QGraphicsLayoutItem hierarchy. Other relationships were omitted to keep things simple.

Qt Animated Proxy Layout diagram