1
我有一個groupbox,我想添加動畫。 我創建了我的自定義組框類並實施了穆斯特進入和離開事件。 在鼠標輸入時,我檢查高度並減少或增加動畫,但似乎不起作用。羣組的Qt動畫
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);
}
如果添加組框的佈局,因爲它是由佈局管理不能手動改變其幾何形狀。嘗試使用'maximumSize'屬性代替。佈局會尊重這個價值。 –
這就是對,我已經將它添加到佈局。如果我爲組合框設置maximumSze,它將起作用。 – user476566
現在動畫是否工作? –