分组框的 Qt 动画

  • 本文关键字:Qt 动画 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);
    }
如果您将

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

最新更新