1

我有一个要添加动画的组框。我创建了我的自定义组框类并实现了鼠标进入和离开事件。在鼠标输入时,我检查高度并通过动画减少或增加它,但似乎不起作用。

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);

    }
4

1 回答 1

0

如果您将QSpacerItems 添加到包含布局中,或者更好地将 s 的大小设置为 ,groupbox它可能会起作用FixedSize。当您动态添加和删除项目时,固定大小可能会导致问题,但它可能会有所帮助

于 2013-10-31T08:26:18.047 回答