组合框的Qt动画

时间:2013-10-30 20:13:03

标签: qt qt4

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

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

    }

1 个答案:

答案 0 :(得分:0)

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