From b8af2a4eb5d04b5aadc1751bfc97ac8d268f46e5 Mon Sep 17 00:00:00 2001 From: glubsy Date: Thu, 3 Sep 2020 01:44:01 +0200 Subject: [PATCH] Don't show parent window's context menu on viewers * When right clicking on image viewers while they are docked, the context menu of the Results window showed up. * This also enables capture of right click and middle click buttons to drag around images, which solves a conflict with some theme engines that enable left mouse button click to drag a window's position regardless of where the event happens, hence blocking the panning. * Probably unnecessary to check which button is released. --- qt/pe/image_viewer.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/qt/pe/image_viewer.py b/qt/pe/image_viewer.py index 32719077..ef379361 100644 --- a/qt/pe/image_viewer.py +++ b/qt/pe/image_viewer.py @@ -758,11 +758,15 @@ class QWidgetImageViewer(QWidget): return self.disconnectMouseSignals() + def contextMenuEvent(self, event): + """Block parent's (main window) context menu on right click.""" + event.accept() + def mousePressEvent(self, event): if self.bestFit or not self.isEnabled(): event.ignore() return - if event.button() == Qt.LeftButton: + if event.button() & (Qt.LeftButton | Qt.MidButton | Qt.RightButton): self._drag = True else: self._drag = False @@ -790,8 +794,8 @@ class QWidgetImageViewer(QWidget): if self.bestFit or not self.isEnabled(): event.ignore() return - if event.button() == Qt.LeftButton: - self._drag = False + # if event.button() == Qt.LeftButton: + self._drag = False self._app.restoreOverrideCursor() self.setMouseTracking(False) @@ -956,11 +960,18 @@ class ScrollAreaImageViewer(QScrollArea): self._horizontalScrollBar.valueChanged.connect( self.controller.onHScrollBarChanged, Qt.UniqueConnection) + def contextMenuEvent(self, event): + """Block parent's (main window) context menu on right click.""" + # Even though we don't have a context menu right now, and the default + # contextMenuPolicy is DefaultContextMenu, we leverage that handler to + # avoid raising the Result window's Actions menu + event.accept() + def mousePressEvent(self, event): if self.bestFit: event.ignore() return - if event.button() == Qt.LeftButton: + if event.button() & (Qt.LeftButton | Qt.MidButton | Qt.RightButton): self._drag = True else: self._drag = False @@ -985,8 +996,7 @@ class ScrollAreaImageViewer(QScrollArea): if self.bestFit: event.ignore() return - if event.button() == Qt.LeftButton: - self._drag = False + self._drag = False self._app.restoreOverrideCursor() self.setMouseTracking(False) super().mouseReleaseEvent(event) @@ -1203,11 +1213,15 @@ class GraphicsViewViewer(QGraphicsView): self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) + def contextMenuEvent(self, event): + """Block parent's (main window) context menu on right click.""" + event.accept() + def mousePressEvent(self, event): if self.bestFit: event.ignore() return - if event.button() == Qt.LeftButton: + if event.button() & (Qt.LeftButton | Qt.MidButton | Qt.RightButton): self._drag = True else: self._drag = False @@ -1223,8 +1237,7 @@ class GraphicsViewViewer(QGraphicsView): if self.bestFit: event.ignore() return - if event.button() == Qt.LeftButton: - self._drag = False + self._drag = False self._app.restoreOverrideCursor() self.setMouseTracking(False) self.updateCenterPoint()