diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/animatedheightwidget.cpp | 16 | ||||
| -rw-r--r-- | src/animatedheightwidget.h | 7 |
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. |
