How do you animate a widget in Qt 4? Let’s start with a bit of history….
- Qt 4.0 : QTimer provides a low level timer.
- Qt 4.2 : QTimeLine provides a duration, looping, easing and basic states
- Qt 4.2 : QGraphicsItemAnimation which is built on top of QTimeLine.
We realized that these classes were not convenient enough for doing highly animated user interfaces, so we decided to write yet another world dominating framework for animating widgets
. After a lot of research, prototyping, API discussions and rewrites we have finally something that will dominate the world.
Initially it was our intention to release the animation framework for 4.5. Unfortunately we felt it was not ready for 4.5, so we decided to postpone it in order to give it some more love. We feel that we are getting closer now, but as a service to people that have been waiting for this we have decided to release it as a Qt Solution. We also have a secret, scrupulous plan B with this: we want you guys to give feedback (qt-solutions@trolltech.com) on it so we can improve it even more
. It is available under the normal Qt Solution conditions, either commercial or GPL.
For you gaming enthusiasts we have made a full blown world dominating game:
No related posts.
21 comments
zOMG!!!1!!! I’ve been waiting for this 4ev4r!!!! It looks good, real good.
But immediately, I see missing functionality.
You need an animation function to take a point about which to perform a rotation, and the axis. This then is combined with all other axis (watching out for gimble lock) to produce the final QTransform.
for instance:
objTimeline.setEase(Bounce);
// about point , degrees, axis, timeline extent
objTimeline.setRotation(QPointF(width()/2, height()/2), 0, QTransform::ZAxis, 0) ;
objTimeline.setRotation(QPointF(width()/2, height()/2), 0, QTransform::YAxis, 0) ;
objTimeline.setRotation(QPointF(width()/2, height()/2), 360, QTransform::ZAxis, 1) ;
objTimeline.setRotation(QPointF(width()/2, height()/2), 360, QTransform::YAxis, 1) ;
Perhaps, I missed this somewhere?
Speaking about animations… It would be realy nice to see Qt integrated somehow with CoreAnimation on Mac OS X
We get Obama, and then we get Qt Animations? Oh good times!
There needs to be rotation about a point (2-space, but 3-space would be better) for any of the 3 axis.
As a solutions subscriber I like this “solution” a lot.
It really is a good solution for things not making a “big” point upgrade and forcing users to wait. And one where we get it early and provided feedback, for instance in the animation above you need a shark.
You are better programmer than game player
I love seing this as a Qt solution. I think that this way the API can be hammered by crazy KDE programmers before entering Qt.
I’ll give it a try myself this weekend.
@naresh With the Cocoa port it already is easy to do this. It doesn’t work well with Qt layouts, but QWidgets work just fine with core animation. Assuming you don’t mind writing Objective-C.
w00t!
w00t!
Woot, indeed.
woha alexis, this is gorgeous, congrats to the whole team!
you make your plasma friends veeery happy
(Sorry for my English.)
That’s great, but…
I don’t like this QtAnimation::setPropertyName thing.
I want to animate more than properties.
You cheat with QGraphicsItem, and it works, but not enough flexible. (Subclasses?)
I want to create animation with a pointer, and a member function poiner.
(QtFunctionAnimater::setFunction(QGraphicsView* item,void (*func_ptr)(T) );)
Or create with a function object (Boost::bind).
Yes, I can create it myself (I did it for GraphicsView framework 2 years ago), but…
tr3w, you are right, it should be possible to animate more than properties, and the support for QGraphicsItem is a “hack” in that sense – it’s not flexible enough. Your function approach should be covered by creating a subclass of QAnimation. I’m not sure if a function pointer is the best idea though, how would you propose that this would work? Thanks for the feed-back!
I am waiting for this new animation framework for my projet, so I am happy for that news.
But, I don’t like this… I am wainting for a “DoEveryThing” framework that supersed all other method.
Now, we have QTimeLine for animation that demand interaction (path may change), QGraphicsItemAnimation for “fixed” animation… and now Qt Animation for “group fixed” animation….. from my own experiment. I think there are too many ways to do thing.
I know that QtAnimation is not only for qgraphicsitem, but in QtAnimation is missing something like in QGraphicsItemAnimation, a setTargetValueAt ( qreal step, const QVariant & value ), for complex path.
Something I am missing too, is to animate more than one property by item… like changing a color and the path/geometry is a simple fashion…
I don’t see basic interpolation form Q* object, like QGradient, QColor.. why not QDate.. it may be very useful.
I overuse QTransform/QTimeline to manipulate rotation in X/Y axis because it’s too difficult… I hope that this news framework help me on this..
A simple API in QGraphicsItem to rotate in X/Y and a “cumulative” QTransform may help.
By “cumulative” QTransform for rotate in X/Y I think to rotate(10°, X) and rotate(10°, X) get a rotate(10°, X)
And in the end I think that to “Fixed” path in api is not good… I want to interpolate from one animation/path to the same animation but with other path
Sorry if I am completely wrong or understandable
and for this too long post
I share Scorp1us’s feelings (re Obama and now QAnimation).
More seriously, it would be neat if Qt provided a few “standard” animations users expect on specific platforms instead of requiring developers to reimplement the wheel for each dialog or application they deploy. What are examples of “standard” animations?
-expanding/collapsing the tool bar when clicking the pill buttons on the Mac (Qt already does this, why not implement it using QAnimation? and make it default?)
-a standard disclosure triangle which animates not only the triangle but also expanding down and then fading in/out the expanded/collapsed widget
-rearranging the order of icons in a tool bar by drag-n-drop when View->Toolbar->Customize… link is used on Mac
-auto resizing the size of a preferences dialog when switching between tabs (this is another Mac type thing)
What’s I’m suggesting is built the animation framework so that the above can all be implemented in it, then ship these features built on top of QAnimation so that you can show off more concrete ways all qt apps can immediately take advantage of this new framework.
Sound reasonable?
QtAnimationGroup animations;
int widthNow=width();
animations.beginSequentialGroup();
foreach (QString html, htmlItems)
{
QGraphicsTextItem *ti = new QGraphicsTextItem(background);
ti->setHtml(html);
scene()->addItem(ti);
sideItems.append(ti);
ti->setPos(QPointF(widthNow+500, (itemHeight*i)+(itemHeight >> 1)));
QtAnimation *animation = new QtAnimation((QGraphicsItem *)ti, “pos”);
animation->setTargetValue(QPoint(396,(itemHeight*i)+(itemHeight >> 1)));
animation->setDuration(1000);
animation->setEasingCurve(QtEasingCurve::InOutBounce);
animations.add(animation);
i++;
}
animations.endGroup();
animations.start();
Crashes on last line (during the animation, it crashes at:
void QtAbstractAnimation::setCurrentTime(int msecs)
{
Q_D(QtAbstractAnimation);
if (msecs
Hrm, looks like my previous post didn’t work. I am having trouble with
QtAnimationGroup.
Any operation will crash the program:
QtAnimationGroup animations;
animations.start();
It seems duration() can’t be resolved?
Also, on windows, I can’t seem to animate opacity.
What Will Stokes says, makes much sense to me!
PyskoTux:
Yes, it can almost be too many ways to do a thing. However I feel that QTimeLine and this animation framework complements each other, QTimeLine is nice if you want to animate something from your paint event. (i.e. animated progressbar), while you use the animation framework to animate objects.
Thanks for your feedback!
tr3w, Andreas:
I’ve always been thinking that signals and slots are a very nice mechanism for implementing mixins, i.e. add-on interfaces without the class hierarchy stuff. What about calling a slot instead of changing a property? There will be a small performance hit but otherwise it looks like the perfect solution to me.
Maybe you want a second possibility that works with non-QObjects if that makes any sense.
Thanks for all the feedback, guys! We’re trying to systematically go through these suggestions and make improvements to the API. Hopefully we’ll have a repository available soon so you can make changes yourself, and post patches / “show the code”. Remember that you can also subscribe to qt-solutions@trolltech.com to discuss more interactively than in this blog comment forum.
QObject:
Slot? Yes! And Q_INVOKABLE functions.
(I need more Q_INVOKABLE function in Qt. I use QtScript, and property simply not enough…)
QGraphicsItem:
I think of it. It only need a new QtAnimation member function:
—
class QtAnimation…
{
…
template
void setMemberFunction(void (U::*func)(V v));
…
}
—
And we use it like this:
—
animation->setTargetItem(item);
animation->setMemberFunction(&QGraphicsItem::rotate);
—
Implementation:
It need a helper base class:
—
class HelperBase
{
void setDuration(int);
…
virtual void updateCurrentTime(int ms)=0;
}
—
And templated classes:
—
template
class Helper: public HelperBase
{
Helper(boost::function callIt);
virtual void updateCurrentTime(int ms);
private:
boost::function m_callIt;
}
template
Helper::updateCurrentTime(int ms)
…
template
Helper::updateCurrentTime(int ms)
…
template
Helper::updateCurrentTime(int ms)
…
—
I think it works. And maybe it quicker than call qstrcmp with property names…
Hopefuly, you guys are still reading this rather than just the qt-solutions list, but one thing missing from the API right now is the ability to define a custom ease curve, it wouldn’t take much to make this possible. Looking over the list of curves provided, i think you’ve covered all the ones i can think we’d need, but having a way out for the thing that didn’t occur to us is important too.
Comments on this entry are closed.