繁体   English   中英

QPropertyAnimation不动画

[英]QPropertyAnimation doesn't animate

这是我的代码:

void Widget::update()
{
    if (a==1)
    {
        QPushButton button("Animated Button");
        button.show();

        QPropertyAnimation *animation =
                    new QPropertyAnimation(&button, "geometry");
        animation->setDuration(10000);
        animation->setStartValue(QRect(0, 0, 100, 30));
        animation->setEndValue(QRect(250, 250, 100, 30));

        animation->start();
        a++;
    }
}

void Widget::on_pushButton_clicked()
{
    a=1;
}

我是C ++的新手,如何进行这项工作?

我建议您读一本不错的C ++书,或者至少阅读http://www.cplusplus.com/doc/tutorial/

对于初学者,您可能打算在on_pushButton_clicked()中a == 1之后调用update()? 函数结尾处的按钮超出范围也存在问题,因此您需要执行

QPushButton *button = new QPushButton("Animated Button", this); 

最后,update()是QWidget中的虚函数(我假设是Widget派生的?)。 为什么要覆盖它? 您可能想将其命名为类似startAnimatinon()的名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM