From 6c5612b9667a4a5657a1bdc9e34572ce4f53c89f Mon Sep 17 00:00:00 2001 From: zhangjiarui Date: Mon, 28 Sep 2026 17:34:29 +0800 Subject: [PATCH] fix(reader): restore arrow key scrolling by removing QAction shortcut registration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Arrow keys (Left/Right/Up/Down) and Space were registered as QAction shortcuts in Central.cpp constructor, which intercepted key events and prevented Qt's default scrolling behavior in document reading mode. The page navigation logic in CentralDocPage.cpp for these keys was already commented out, so the QAction had no effect except blocking default scrolling. Fix by commenting out the QAction registrations for these keys in Central.cpp, removing the slide widget key forwarding in CentralDocPage.cpp, and adding a keyPressEvent override to SlideWidget with setFocus() in its constructor so slide show mode handles arrow keys and space independently. This restores the fix from commit a81e5e19 that was reverted by the v23 merge commit b20fcf92. Log: 方向键无法滚动文档页面 Bug: https://pms.uniontech.com/bug-view-374547.html --- reader/uiframe/Central.cpp | 15 +++++++-------- reader/uiframe/CentralDocPage.cpp | 1 - reader/widgets/SlideWidget.cpp | 10 ++++++++++ reader/widgets/SlideWidget.h | 16 +++++++++------- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/reader/uiframe/Central.cpp b/reader/uiframe/Central.cpp index 98984f159..5d3d10944 100644 --- a/reader/uiframe/Central.cpp +++ b/reader/uiframe/Central.cpp @@ -74,14 +74,13 @@ Central::Central(QWidget *parent) keyList.append(QKeySequence::Print); keyList.append(QKeySequence::Save); keyList.append(QKeySequence::Copy); - // 屏蔽右侧区域的切页快捷键,使用默认的滚动效果 - // when using slide mode, left & right keys are needed. modify by lz,at 2022.4.18 - keyList.append(QKeySequence(Qt::Key_Left)); - keyList.append(QKeySequence(Qt::Key_Right)); - - keyList.append(QKeySequence(Qt::Key_Up)); - keyList.append(QKeySequence(Qt::Key_Down)); - keyList.append(QKeySequence(Qt::Key_Space)); + //使用下面5个快捷键会屏蔽主界面对应的功能,故注释 + //keyList.append(QKeySequence(Qt::Key_Left)); + //keyList.append(QKeySequence(Qt::Key_Right)); + + //keyList.append(QKeySequence(Qt::Key_Up)); + //keyList.append(QKeySequence(Qt::Key_Down)); + //keyList.append(QKeySequence(Qt::Key_Space)); keyList.append(QKeySequence(Qt::Key_Escape)); keyList.append(QKeySequence(Qt::Key_F5)); keyList.append(QKeySequence(Qt::Key_F11)); diff --git a/reader/uiframe/CentralDocPage.cpp b/reader/uiframe/CentralDocPage.cpp index cf553f22a..3697d3083 100644 --- a/reader/uiframe/CentralDocPage.cpp +++ b/reader/uiframe/CentralDocPage.cpp @@ -731,7 +731,6 @@ void CentralDocPage::handleShortcut(const QString &s) } if (m_slideWidget) { - m_slideWidget->handleKeyPressEvent(s); return; } diff --git a/reader/widgets/SlideWidget.cpp b/reader/widgets/SlideWidget.cpp index 7bfee2e54..0603dffc6 100644 --- a/reader/widgets/SlideWidget.cpp +++ b/reader/widgets/SlideWidget.cpp @@ -9,6 +9,7 @@ #include "SlidePlayWidget.h" #include "Application.h" #include "ReaderImageThreadPoolManager.h" +#include "Utils.h" #include "ddlog.h" #include @@ -34,6 +35,7 @@ SlideWidget::SlideWidget(DocSheet *docsheet) initControl(); initImageControl(); show(); + QTimer::singleShot(0, this, [this](){this->setFocus();}); qCDebug(appLog) << "SlideWidget initialized"; } @@ -423,6 +425,14 @@ void SlideWidget::handleKeyPressEvent(const QString &sKey) // qCDebug(appLog) << "Handling key press event end"; } +void SlideWidget::keyPressEvent(QKeyEvent *event) +{ + QString key = Utils::getKeyshortcut(event); + handleKeyPressEvent(key); + + DWidget::keyPressEvent(event); +} + void SlideWidget::onFetchImage(int index) { qCDebug(appLog) << "Fetching image for page:" << index; diff --git a/reader/widgets/SlideWidget.h b/reader/widgets/SlideWidget.h index b3fc73ce8..cc283ff3e 100644 --- a/reader/widgets/SlideWidget.h +++ b/reader/widgets/SlideWidget.h @@ -36,13 +36,6 @@ public slots: */ void setWidgetState(bool full); - /** - * @brief handleKeyPressEvent - * 按键处理事件 - * @param sKey - */ - void handleKeyPressEvent(const QString &sKey); - /** * @brief onImageAniFinished * 单页幻灯片播放结束 @@ -56,6 +49,13 @@ public slots: */ void initControl(); + /** + * @brief handleKeyPressEvent + * 按键处理事件 + * @param sKey + */ + void handleKeyPressEvent(const QString &sKey); + /** * @brief initImageControl * 初始化图片数据 @@ -160,6 +160,8 @@ private slots: void wheelEvent(QWheelEvent *event) override; + void keyPressEvent(QKeyEvent *event) override; + private: int m_curPageIndex = 0; bool m_canRestart = false;