vfernandez
2nd January 2010, 10:49
I'm taking a look at the new animation framework as well as QStateMachine and I'm trying to make a QGraphicsView zoom in when I select an item and zoom out when no item is selected. I want to animate the zoom effect.
The animation is working fine when zooming in but it's not working when zooming out. It just zooms out suddenly. It's strange because the setZoom() slot I've added to my QGraphicsView subclass gets called but the zoom factor just jumps from 2 to 1 without intermediate values.
QStateMachine machine;
QState *globalOverview = new QState(&machine);
globalOverview->assignProperty(&view, "zoom", qreal(1.0));
machine.setInitialState(globalOverview);
QPropertyAnimation *animation = new QPropertyAnimation(&view, "zoom");
animation->setDuration(250);
animation->setEasingCurve(QEasingCurve::InOutQuad);
machine.addDefaultAnimation(animation);
for(int i = 0; i < 100; i++) {
ExtensionItem *item = new ExtensionItem(i);
layout.addItem(item);
scene.addItem(item);
QState *state = new QState(&machine);
state->assignProperty(&view, "zoom", qreal(2.0));
globalOverview->addTransition(item, SIGNAL(selected()), state);
state->addTransition(item, SIGNAL(selected()), globalOverview);
state->addTransition(&scene, SIGNAL(selectionCleared()), globalOverview);
}
machine.start();
Any idea why it isn't working?
The animation is working fine when zooming in but it's not working when zooming out. It just zooms out suddenly. It's strange because the setZoom() slot I've added to my QGraphicsView subclass gets called but the zoom factor just jumps from 2 to 1 without intermediate values.
QStateMachine machine;
QState *globalOverview = new QState(&machine);
globalOverview->assignProperty(&view, "zoom", qreal(1.0));
machine.setInitialState(globalOverview);
QPropertyAnimation *animation = new QPropertyAnimation(&view, "zoom");
animation->setDuration(250);
animation->setEasingCurve(QEasingCurve::InOutQuad);
machine.addDefaultAnimation(animation);
for(int i = 0; i < 100; i++) {
ExtensionItem *item = new ExtensionItem(i);
layout.addItem(item);
scene.addItem(item);
QState *state = new QState(&machine);
state->assignProperty(&view, "zoom", qreal(2.0));
globalOverview->addTransition(item, SIGNAL(selected()), state);
state->addTransition(item, SIGNAL(selected()), globalOverview);
state->addTransition(&scene, SIGNAL(selectionCleared()), globalOverview);
}
machine.start();
Any idea why it isn't working?