fix: do mouse gallery navigation on btn release

This commit is contained in:
Gary Wang 2021-10-08 19:31:19 +08:00
parent 3a442b35f6
commit 7a1816cbac
2 changed files with 15 additions and 11 deletions

View File

@ -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);

View File

@ -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);
}