Нежелательное поведение при использовании qPropertyAnimationC++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Нежелательное поведение при использовании qPropertyAnimation

Сообщение Anonymous »

Часть моего кода, которая отвечает за события: < /p>
QWidget* buttonWidget = qobject_cast(object);
if(buttonWidget && buttonWidget->property("nav") == "simple")
{
if (event->type() == QEvent::Enter)
{
// Get the current position and size of the button
QPoint currentPos = buttonWidget->pos();
QSize currentSize = buttonWidget->size();

//buttonWidget->setMinimumSize(currentSize);

// Create an animation to change the size
QPropertyAnimation* animation = new QPropertyAnimation(buttonWidget, "geometry");
animation->setDuration(150); // Duration of the animation in milliseconds
animation->setEasingCurve(QEasingCurve::InOutQuad); // Smooth easing curve

// Set the new geometry: expand equally in all directions from the center
QRect newGeometry(currentPos.x() - 10, currentPos.y() - 10, currentSize.width() + 20, currentSize.height() + 20);
animation->setStartValue(buttonWidget->geometry());
animation->setEndValue(newGeometry);
animation->start(QAbstractAnimation::DeleteWhenStopped); // Automatically delete the animation when done

}
else if (event->type() == QEvent::Leave)
{
// Get the current position and size of the button
QPoint currentPos = buttonWidget->pos();
QSize currentSize = buttonWidget->size();

//buttonWidget->setMaximumSize(currentSize);

// Create an animation to revert the size change
QPropertyAnimation* animation = new QPropertyAnimation(buttonWidget, "geometry");
animation->setDuration(150);
animation->setEasingCurve(QEasingCurve::InOutQuad);

// Set the new geometry: revert to original size
QRect newGeometry(currentPos.x() + 10, currentPos.y() + 10, currentSize.width() - 20, currentSize.height() - 20);
animation->setStartValue(buttonWidget->geometry());
animation->setEndValue(newGeometry);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}

return QWidget::eventFilter(object, event);
< /code>
Это находится внутри переопределения функции Eventfilter пользовательского Qwidget. Проблема в том, что когда я ввожу и ухожу, а затем вступаю в кнопку, вероятно, когда я делаю ее быстрее, чем заканчивая анимации, чем масштаб кнопок либо будет расти, либо уменьшаться больше, чем потребуется и ожидается. Я не знаю, нужно ли мне предоставить какие -либо другие части моего кода, но я думаю, проблема здесь, в этой части.

Подробнее здесь: https://stackoverflow.com/questions/795 ... yanimation
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»