Der Teil meines Codes, der für die Ereignisse verantwortlich ist: < /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>
Dies befindet sich in der Eventfilter -Funktion eines benutzerdefinierten Qwidgets. Das Problem ist, dass, wenn ich eingehe, wenn ich eingreife und gehe und in einen Knopf eingehe, wahrscheinlich, wenn ich es schneller mache als die Animationen, als die Skala der Tasten entweder wächst oder schrumpfen, als es nötig und erwartet würde. Ich weiß nicht, ob ich andere Teile meines Codes bereitstellen muss, aber ich denke, das Problem ist hier in diesem Teil.
Unerwünschtes Verhalten bei der Verwendung von Qpropertyanimation ⇐ C++
-
- Similar Topics
- Replies
- Views
- Last post