From 407ce0706a18b9e1245f7c52246a76b0e54939dc Mon Sep 17 00:00:00 2001 From: Pan Zhang <571863604zp@gmail.com> Date: Wed, 17 Sep 2025 00:39:35 +0800 Subject: animatedheightwidget: ignore PageUp/PageDown to avoid invisible scroll When typing in the search bar (or other widgets using AnimatedHeightWidget), pressing PageUp or PageDown would cause the internal QScrollArea (with hidden scrollbars) to react and scroll. This made the entered text appear to disappear even though focus stayed in the input field. PageUp and PageDown are now intercepted in AnimatedHeightWidget to prevent the underlying QScrollArea from handling them, ensuring input remains visible across all users of AnimatedHeightWidget. BUG: 508835 --- src/animatedheightwidget.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/animatedheightwidget.cpp') diff --git a/src/animatedheightwidget.cpp b/src/animatedheightwidget.cpp index cd62f3971..c89863b25 100644 --- a/src/animatedheightwidget.cpp +++ b/src/animatedheightwidget.cpp @@ -7,7 +7,9 @@ #include "animatedheightwidget.h" +#include #include +#include #include #include #include @@ -86,6 +88,7 @@ QWidget *AnimatedHeightWidget::prepareContentsContainer(QWidget *contentsContain contentsContainer->setParent(m_contentsContainerParent); m_contentsContainerParent->setWidget(contentsContainer); m_contentsContainerParent->setFocusProxy(contentsContainer); + contentsContainer->installEventFilter(this); return contentsContainer; } @@ -93,3 +96,16 @@ bool AnimatedHeightWidget::isAnimationRunning() const { return m_heightAnimation && m_heightAnimation->state() == QAbstractAnimation::Running; } + +bool AnimatedHeightWidget::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::KeyPress) { + auto *keyEvent = static_cast(event); + // Ignore PageUp/PageDown to prevent QScrollArea (invisible scrollbar) from scrolling + if (keyEvent->key() == Qt::Key_PageUp || keyEvent->key() == Qt::Key_PageDown) { + keyEvent->accept(); + return true; + } + } + return QWidget::eventFilter(obj, event); +} \ No newline at end of file -- cgit v1.3