Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Is it possible to change value of widget when animation loop is incremented?



  • Hello!
    I wonder if there is possibility to change position of widget after loop. For example, we have widget that is being animated and if animation ends we change its position and animate it again (something like reset, but in other place/position).

    I was thinking about creating individual class derived from QAbstractAnimation just to override LoopCount or function responsible for looping, but i am lost right know and i don't know if there isn't maybe easier and faster way to go. It should look
    like this:

    Endless Loop {

    1. animate
    2. if animation ends, change position of widget
    3. animate it again

    }

    Do you know any hints? I will be grateful :)
    Cheers!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You can use the currentLoopChanged to get that information.

    Hope it helps



  • Thanks for reply, however i still can't do it. I am struggling with connecting animation with any widget.

    animation = new QPropertyAnimation(ui->label_2, "geometry");
    //code handling animation...
    QObject::connect(animation, SIGNAL(currentLoopChanged()), ui->pushButton, SLOT(changeText()));
    

    This is doing nothing. Like signal is not being send.

    ChangeText function:

    void MainWindow::changeText(int) {
        int randomValue = random<int>(this->height() - this->height(), this->height());
        ui->pushButton->setText(QString::number(randomValue));
    }
    

    Do you see something suspicious in this connect?
    Awww this problem is devouring so much time haha! For sure it is, because my Qt5 knowledge is so tiny :)
    Cheers!



  • Alright nevermind, finally i understood how connections work and i implemented one properly this time. Thanks for help.


Log in to reply