I suggest you extend the PlotItem class and then intercept the mouse clicks 
and drags.

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui

class EZPlotWidget(pg.PlotItem):
    def __init__(self, *args, **kwds):
        super().__init__(*args, **kwds)

    def mouseClickEvent(self, evt):
        if mode == 'Paint'
        if evt.button() == QtCore.Qt.RightButton:
            evt.accept()        # This will intercept the event and 

    def mouseDragEvent(self, evt):
        if evt.button() == QtCore.Qt.RightButton:
            evt.ignore()
        else:
            pass







On Thursday, January 11, 2018 at 4:45:00 AM UTC-7, Marco wrote:
>
> 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
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/3eb8c798-d03d-4493-863f-6343e52c9181%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to