Hi,
many thanks to Luke for the great work with Pyqtgraph.
I need to temporarily disable pan in ViewBox and remap mouse interaction.
The program must have two modes:
1. View/explore image mode.
ViewBox in normal mode (mouse click and drag for panning).
2. Paint with mouse mode (No pan with mouse click and drag).
Mouse click, move and release must run functions. I will use those functions for drawing on numpy array.
I must switch between modes with a button.
Here the code:
#####################################
#####################################
from pyqtgraph.Qt import QtGui
import numpy as np
import pyqtgraph as pg
import sys
pg.setConfigOptions(antialias=True)
app = QtGui.QApplication([])
win = pg.GraphicsWindow()
vb = win.addViewBox()
vb.setAspectLocked()
# Create an array of data
x = np.linspace(0, 10)
y = x[:]
xx, yy = np.meshgrid(x, y)
img = np.sin(xx) + np.cos(yy)
# Plot the array on ViewBox
imm = pg.ImageItem(img)
vb.addItem(imm)
###########
# Code to be activate in paint mode
def mouseMoved(pos):
position = imm.mapFromScene(pos)
row, col = int(position.y()), int(position.x())
print("Moved to ", row, col)
def mouseClicked(pos):
position = imm.mapFromScene(pos)
row, col = int(position.y()), int(position.x())
print("Clicked at ", row, col)
# Note: incorrect function
def mouseReleased(pos):
position = imm.mapFromScene(pos)
row, col = int(position.y()), int(position.x())
print("Released at ", row, col)
# Note: incorrect function
win.scene().sigMouseClicked.connect(mouseClicked)
win.scene().sigMouseMoved.connect(mouseMoved)
win.scene().sigMouseReleased.connect(mouseReleased) # Note: incorrect
# End paint mode
###########
win.show()
sys.exit(app.exec_())
#####################################
#####################################
My questions:
1. how to disable (and after re-enable) mouse pan?
2. how to get coordinates when I click and release mouse button?
Thanks for your help.
mm