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.

Enjoy!

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.

Layouts

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:

http://www.youtube.com/watch?v=M3HbmrNvQl4

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

Cheers,
Fleury

Ensol 2.0

Acontece nestes dias 2, 3 e 4 de Maio a segunda edição do Encontro de Software Livre da Paraíba, ou simplesmente, Ensol.

Eu, Eduardo Fleury, e Rodrigo Vivi, teremos o prazer de apresentar duas palestras na manhã do Domingo, dia 04 e agradecemos antecipadamente a presença de todos.

As palestras são independentes porém relacionadas, a primeira, Embarcando no Linux para sistemas embarcados (Rodrigo Vivi) ocorrerá as 09.00h de Domingo e cobrirá os conceitos fundamentais das plataformas móveis embarcadas baseadas em Linux, mais especificamente o Mamona e o Maemo.

Na seqüência, às 10.15h apresentarei a palestra Velejando com o Linux para sistemas embarcados na qual discutirei aspectos focados no desenvolvimento de aplicações para estas plataformas, incluindo questões como o ciclo de desenvolvimento e uma comparação entre linguagens de programação, partindo então para uma introdução à linguagem Python e suas principais características.

Links: