这是我的代码:
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++的新手,我该怎么做呢?
发布于 2012-05-26 04:04:16
我建议你读一本好的C++书,或者至少去看看http://www.cplusplus.com/doc/tutorial/。
对于初学者来说,您可能打算在on_pushButton_clicked()中的a==1之后调用update()?还有一个问题是按钮在函数结束时超出了作用域,所以您需要这样做
QPushButton *button = new QPushButton("Animated Button", this); 最后,update()是QWidget中的一个虚函数(我假设它是Widget派生的?)。为什么要覆盖它?您可能希望将其称为类似startAnimatinon()的名称。
https://stackoverflow.com/questions/10759128
复制相似问题