Results 1 to 3 of 3

Thread: Animation not working on transition between states

  1. #1
    Join Date
    Jan 2006
    Location
    Innsbruck, Austria
    Posts
    62
    Thanks
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Animation not working on transition between states

    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.

    Qt Code:
    1. QStateMachine machine;
    2. QState *globalOverview = new QState(&machine);
    3. globalOverview->assignProperty(&view, "zoom", qreal(1.0));
    4. machine.setInitialState(globalOverview);
    5.  
    6. QPropertyAnimation *animation = new QPropertyAnimation(&view, "zoom");
    7. animation->setDuration(250);
    8. animation->setEasingCurve(QEasingCurve::InOutQuad);
    9. machine.addDefaultAnimation(animation);
    10.  
    11. for(int i = 0; i < 100; i++) {
    12. ExtensionItem *item = new ExtensionItem(i);
    13. layout.addItem(item);
    14. scene.addItem(item);
    15.  
    16. QState *state = new QState(&machine);
    17. state->assignProperty(&view, "zoom", qreal(2.0));
    18.  
    19. globalOverview->addTransition(item, SIGNAL(selected()), state);
    20. state->addTransition(item, SIGNAL(selected()), globalOverview);
    21. state->addTransition(&scene, SIGNAL(selectionCleared()), globalOverview);
    22. }
    23.  
    24. machine.start();
    To copy to clipboard, switch view to plain text mode 

    Any idea why it isn't working?
    Attached Files Attached Files

  2. #2
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Animation not working on transition between states

    As far as I know, QPropertyAnimation uses the read value of the property as the start value (this is reasonable since the old state may not have an assigned value for the property). Since your code never updates m_zoom and always return 1, the animation is from 1 to 1.
    Qt Code:
    1. void ExtensionView::setZoom(qreal zoom)
    2. {
    3. QTransform oldT = transform();
    4. QTransform newT(zoom, oldT.m12(), oldT.m13(),
    5. oldT.m21(), zoom, oldT.m23(),
    6. oldT.m31(), oldT.m32(), oldT.m33());
    7. setTransform(newT);
    8.  
    9. m_zoom = zoom; // Need to put this in!!!
    10.  
    11. qDebug() << __FUNCTION__ << zoom;
    12. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to numbat for this useful post:

    vfernandez (2nd January 2010)

  4. #3
    Join Date
    Jan 2006
    Location
    Innsbruck, Austria
    Posts
    62
    Thanks
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Animation not working on transition between states

    D'oh! What a newbie mistake. Thanks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.