Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPropertyAnimation code not workable

QPropertyAnimation code not workable

Scheduled Pinned Locked Moved General and Desktop
qpropertyanimatqparallelanimat
2 Posts 2 Posters 5.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    houmingc
    wrote on last edited by Chris Kawa
    #1

    Newbie in QPropertyAnimation, trying to make code workable.
    Please kindly assist.

    code below shows nothing in mainwindow

    ui->setupUi(this);
    QPushButton button("Animated Button");
    button.show();
    QPropertyAnimation animation(&button,"geometry");
    animation.setDuration(5000);
    animation.setKeyValueAt(0,QRect(0,0,100,30));
    animation.setKeyValueAt(0.8,QRect(250,250,100,30));
    animation.setKeyValueAt(1,QRect(0,0,100,300));
    animation.start();
    

    code below error is:
    QPropertyAnimation::updateState (windowOpacity): Changing state of an animation without target

     QPropertyAnimation* animation = new   QPropertyAnimation(this->parent(),"windowOpacity");
     animation->setDuration(5000);
     animation->setStartValue(0.0);
     animation->setEndValue(1.0);
     animation->setEasingCurve(QEasingCurve::OutCubic);
     animation->start();
    

    code below error is:
    QPropertyAnimation::updateState (geometry, QPushButton, ): starting an animation without end value

     ui->setupUi(this);
     QPushButton* bonnie = new QPushButton("Bonnie");
     bonnie->show();
     QPushButton* clyde = new QPushButton("clyde");
     clyde->show();
    
     QPropertyAnimation* anim1 = new QPropertyAnimation(bonnie, "geometry");
     QPropertyAnimation* anim2 = new QPropertyAnimation(clyde,"geometry");
    
     QParallelAnimationGroup* group = new QParallelAnimationGroup;
     group->addAnimation(anim1);
     group->addAnimation(anim2);
     group->start();
    
    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      The first one: both button and animation are local stack variables and get destroyed at the end of the function, before anything starts to animate. Don't do that.

      The second one: if this points to a top level widget then its parent is most probably null. You can't animate a property of non-existing object. Make sure the first parameter points to a valid object. Also make sure you either delete the animation object somewhere or give it a parent (3rd parameter) or else you're leaking memory.

      Third one: you created two animations without any values i.e. it doesn't know how to animate the "geometry" property. Before you start the group add to your animations some duration, start and end values like in your previous examples. Also, again, make sure you delete the animations and the group or give them a parent or you're leaking memory.

      p.s. This forum no longer uses @ for code blocks. To properly format code just indent it either 4 spaces or a tab. I edited your post to fix this.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved