我尝试使用 QPropertyAnimation 为工具按钮设置动画。然而,它什么也没做。有什么我做错了吗?有人可以帮忙吗?
工具栏调色板.h:
class ToolBarPalettes : public QToolBar
{
public:
ToolBarPalettes(void);
~ToolBarPalettes(void);
public slots:
void startAnimation();
private:
createButtons();
QToolButton *animatedButton;
}
工具栏调色板.cpp:
ToolBarPalettes::ToolBarPalettes(void)
{
createButtons();
connect(animatedButton, SIGNAL(clicked()), this, SLOT(startAnimation()));
}
void ToolBarPalettes::createButtons()
{
animatedButton = new QToolButton;
animatedButton->setText("Animate!");
addWidget(animatedButton);
}
void ToolBarPalettes::startAnimation()
{
QPropertyAnimation *animation = new QPropertyAnimation(animatedButton, "geometry");
animation->setDuration(3000);
animation->setStartValue(QRect(this->x(), this->y(), this->width(), this->height()));
animation->setEndValue(QRect(this->x(), this->y(), 10, 10));
animation->setEasingCurve::OutBounce);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}