[英]Qt Animate Tool Button
我嘗試使用QPropertyAnimation為工具按鈕設置動畫。 但是,它什么也沒做。 我做錯了什么嗎? 誰能幫忙嗎?
ToolBarPalettes.h:
class ToolBarPalettes : public QToolBar
{
public:
ToolBarPalettes(void);
~ToolBarPalettes(void);
public slots:
void startAnimation();
private:
createButtons();
QToolButton *animatedButton;
}
ToolBarPalettes.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);
}
您應該使用minimumSize
, maximumSize
或size
屬性而不是geometry
屬性。
animation = new QPropertyAnimation(animatedButton, "minimumSize");
然后設置值:
animation->setStartValue(animatedButton->minimumSize());
animation->setEndValue(QSize(100,100));
geometry
屬性僅適用於布局中未包含的頂級窗口和窗口小部件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.