At this year’s Akademy I’ve presented a talk that summarizes a new way of styling C++ widgets in Qt and KDE. Now checkout the companion paper with in deep explanations of the ideas proposed there.
Get it HERE
At this year’s Akademy I’ve presented a talk that summarizes a new way of styling C++ widgets in Qt and KDE. Now checkout the companion paper with in deep explanations of the ideas proposed there.
Get it HERE
Hi there! This post is to share with you something I hacked these days.
Image you are writing a widget or a piece of an application interface and you want to rotate something based on a mouse click. For instance, you may have a widget that looks like a rotating knob, or a round analogue gauge.
For this post, let’s use a car dashboard speedometer. What I want here is to click somewhere on the gauge and have the needle rotated towards the current mouse position. Check this video of how it should work.
In Qt, rotating a widget is easy in the context of QtQuick or QGraphicsView, just define the “rotation” property to the desired angle and you are all set. The problem here is to find out what the desired angle is.
Here I want to find out which is the angle formed between a given mouse position and centre of the gauge, or the origin of the needle rotation. Getting the mouse position is easy in QtQuick, simply watch the “mouseX” and “mouseY” properties of a MouseArea. But what about converting that to an “angle” ?
In mathematical terms what I want is to convert the mouse position from linear coordinates (X,Y pair) to circular coordinates (angle, radius pair) with the centre of the gauge being the origin of my plane. But designers using QtQuick really don’t want to deal with that.
I made a Qt class meant to be used as a “model” or “helper” for both C++ and QtQuick applications. This class hides the trigonometry required for that conversion by exporting a set of properties, namely:
So how would we use it in our example?
Then QtQuick data binding system will handle everything else. Every time the mouse moves, the properties “x” and “y” will be updated, the model will then recalculate the values of “angle” and “radius” causing the needle to update itself.
Below you can see a diagram of that behaviour. Note that the opposite also works, that is, once I explicitly set an “angle” and “radius” in the model, the values of “x” and “y” are automatically updated.

Relationship between AngleModel and different coordinates
To grab the code go to Qt Components Gitorious and check:
Hope you enjoy it. Comments are always welcome.
Está disponível desde hoje cedo a versão 4.6.0 do Qt com diversas novidades, como diz o post oficial dos nossos amigos do Qt.
A nova versão está disponível para download em qt.nokia.com, em versões pré compiladas para Windows, MacOS e Symbian, além do código fonte (para todas as plataformas). Usuários Linux podem baixar e compilar o fonte ou então instalar usando os procedimentos normais de cada distribuição, tão logo estejam disponíveis os pacotes desta versão.
Entre as novidades dessa versão estão:
A documentação atualizada com todas as novas classes está pronta também, ou pelo Qt Assistant ou online.
Outro fato marcante desta versão é o fato de ser a primeira após a abertura do repositório Git do Qt, e assim marca uma integração cada vez maior com a comunidade. Nesse sentido esperamos que todos usem, testem e mandem opiniões e reports de eventuais bugs, para que as próximas versões sejam cada vez melhores!
Para ilustrar um pouco, um vídeo feito pelo pessoal aqui do openBossa mostrando o 4.6.0 rodando em diversos aparelhos!
Para finalizar, algumas fotos do time do Qt.
Em Oslo
Em Berlin
Em Brisbane
Em Munich
Parabéns pessoal!