From 7a1816cbacb3b98eaf5d32b64bcca65433c23698 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Fri, 8 Oct 2021 19:31:19 +0800 Subject: [PATCH] fix: do mouse gallery navigation on btn release --- app/graphicsview.cpp | 8 ++++++-- app/mainwindow.cpp | 18 +++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/graphicsview.cpp b/app/graphicsview.cpp index 1573014..577c907 100644 --- a/app/graphicsview.cpp +++ b/app/graphicsview.cpp @@ -263,9 +263,13 @@ void GraphicsView::mouseMoveEvent(QMouseEvent *event) void GraphicsView::mouseReleaseEvent(QMouseEvent *event) { - QGraphicsItem *item = itemAt(event->pos()); - if (!item) { + if (event->button() == Qt::ForwardButton || event->button() == Qt::BackButton) { event->ignore(); + } else { + QGraphicsItem *item = itemAt(event->pos()); + if (!item) { + event->ignore(); + } } return QGraphicsView::mouseReleaseEvent(event); diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index e5e87fb..3575679 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -272,15 +272,6 @@ void MainWindow::mousePressEvent(QMouseEvent *event) event->accept(); } - // It seems the forward/back mouse button won't generate a key event [1] so we can't use - // QShortcut or QKeySequence to indicate these shortcuts, so we do it here. - // Reference: - // [1]: https://codereview.qt-project.org/c/qt/qtbase/+/177475 - if (event->buttons() & Qt::ForwardButton || event->buttons() & Qt::BackButton) { - event->buttons() & Qt::BackButton ? galleryNext() : galleryPrev(); - event->accept(); - } - return FramelessWindow::mousePressEvent(event); } @@ -304,6 +295,15 @@ void MainWindow::mouseReleaseEvent(QMouseEvent *event) { m_clickedOnWindow = false; + // It seems the forward/back mouse button won't generate a key event [1] so we can't use + // QShortcut or QKeySequence to indicate these shortcuts, so we do it here. + // Reference: + // [1]: https://codereview.qt-project.org/c/qt/qtbase/+/177475 + if (event->button() == Qt::ForwardButton || event->button() == Qt::BackButton) { + event->button() == Qt::BackButton ? galleryNext() : galleryPrev(); + event->accept(); + } + return FramelessWindow::mouseReleaseEvent(event); }