Answer the question
In order to leave comments, you need to log in
Right click image panning in PyQt5?
There is an application, it has an overridden QGraphicsView, and an image in it. It is necessary to click the left mouse button on the image and call the pixelSelect function, which determines the color of the clicked pixel and its location (In the example below, not all the code). When you hold down the right button, you must enable the QGraphicsView.ScrollHandDrag mode to pan. I understand that the algorithm should be something like this. At initialization - mode:
self.setDragMode(QGraphicsView.ScrollHandDrag)
self.mousePressEvent = self.pixelSelect
self.setDragMode(QGraphicsView.ScrollHandDrag)
def set_pixmap(self, msg, w_img, h_img):
self._zoom = 0
self.qImg = QImage(msg, w_img, h_img, w_img, QImage.Format_Grayscale8)
self._photo = QGraphicsPixmapItem(QPixmap(self.qImg))
self._photo.mousePressEvent = self.pixelSelect
self._scene.addItem(self._photo)
def pixelSelect(self, event):
if event.button() == 1:
self.setDragMode(QGraphicsView.NoDrag)
position = QPoint(event.pos().x(), event.pos().y())
print position
else:
self.setDragMode(QGraphicsView.ScrollHandDrag)
self._photo.mousePressEvent(event)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question