┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPan Zhang <[email protected]>2025-09-17 00:39:35 +0800
committerAkseli Lahtinen <[email protected]>2025-09-16 19:39:35 +0300
commit407ce0706a18b9e1245f7c52246a76b0e54939dc (patch)
tree90284f0ad33784cfcb3d2893e3c7e46b2dd08d96
parent3b802845381d353dcbbeb06a12bd21b4b038874f (diff)
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
-rw-r--r--src/animatedheightwidget.cpp16
-rw-r--r--src/animatedheightwidget.h7
2 files changed, 23 insertions, 0 deletions
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 <QEvent>
#include <QGridLayout>
+#include <QKeyEvent>
#include <QPropertyAnimation>
#include <QScrollArea>
#include <QScrollBar>
@@ -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<QKeyEvent *>(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
diff --git a/src/animatedheightwidget.h b/src/animatedheightwidget.h
index 8f040d571..3933df93f 100644
--- a/src/animatedheightwidget.h
+++ b/src/animatedheightwidget.h
@@ -55,6 +55,13 @@ protected:
/** @returns whether this object is currently animating a visibility change. */
bool isAnimationRunning() const;
+protected:
+ /**
+ * Ignore PageUp/PageDown key events to prevent the internal QScrollArea
+ * (with an invisible scrollbar) from scrolling while editing inside child widgets.
+ */
+ bool eventFilter(QObject *obj, QEvent *event) override;
+
private:
using QWidget::hide; // Use QAbstractAnimation::setVisible() instead.
using QWidget::setVisible; // Makes sure that the setVisible() declaration above doesn't fully hide the one from QWidget so we can still use it privately.