我有一个要添加动画的组框。我创建了我的自定义组框类并实现了鼠标进入和离开事件。在鼠标输入时,我检查高度并通过动画减少或增加它,但似乎不起作用。
int height = groupBox->height();
if ( height >= 40 ) // if height is already increased set , decrease it.
{
int groupBoxHeight = 15;
QPropertyAnimation *animation = new QPropertyAnimation(groupBox, "geometry");
animation->setDuration(2000);
animation->setStartValue(QRect(this->x(), this->y(), this->width(), this->height()));
animation->setEndValue(QRect(this->x(), this->y(), this->width(), groupBoxHeight));
animation->setEasingCurve(QEasingCurve::OutBounce);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
else
{
int groupboxHeight = 50;
groupBox->setGeometry(groupBox->geometry().x(), groupBox->geometry().y(), groupBox->width(), groupboxHeight);
QPropertyAnimation *animation = new QPropertyAnimation(groupBox, "geometry");
animation->setDuration(2000);
animation->setStartValue(QRect(this->x(), this->y(), this->width(), this->height()));
animation->setEndValue(QRect(this->x(), this->y(), this->width(), groupboxHeight));
animation->setEasingCurve(QEasingCurve::OutBounce);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}