首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QPropertyAnimation没有动画效果

QPropertyAnimation没有动画效果
EN

Stack Overflow用户
提问于 2012-05-26 01:50:22
回答 1查看 387关注 0票数 0

这是我的代码:

代码语言:javascript
复制
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++的新手,我该怎么做呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-26 04:04:16

我建议你读一本好的C++书,或者至少去看看http://www.cplusplus.com/doc/tutorial/

对于初学者来说,您可能打算在on_pushButton_clicked()中的a==1之后调用update()?还有一个问题是按钮在函数结束时超出了作用域,所以您需要这样做

代码语言:javascript
复制
QPushButton *button = new QPushButton("Animated Button", this); 

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10759128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档