Qt动画工具按钮



我尝试使用QPropertyAnimation对工具按钮进行动画处理。然而,它什么也没做。我做错了什么吗?谁能帮忙?

ToolBarPalettes.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);
}

你应该使用 minimumSizemaximumSizesize 属性而不是 geometry 属性。

animation = new QPropertyAnimation(animatedButton, "minimumSize"); 

然后设置值:

animation->setStartValue(animatedButton->minimumSize());
animation->setEndValue(QSize(100,100));

geometry 属性仅适用于布局中未包含的顶级窗口和小部件。

最新更新