Adding custom mouse functionality to pyGraph plotWidget
-
Hello,
I'm tryin to hijack mouse move functionality of py plot widget without overwriting it to add my own functionality based mouse cursor and mouse move event to retrieve it's position in the viewbox(just the graph position without the axisess pixels,
So I was wondering, how would one approach it?
I tryed connection self.sigSceneMoved.connect() to a function of mine but the function doesn't seem to respond to mouse move like that though self.lastMousePose Variable does seem to change with every mouse move but it's 0 it in relation to the Widget rather than the origin point of the PlotWidget,
Any Idea wether the PlotWidget also outputs the mouse cursor coordinated relative to the ViewBox excluding the axissItems and Title? -
Hi,
Do you mean PyQtGraph ? Because PyGraph is a pure Python library and makes no use of PySide nor PyQt.
-
Hi,
Do you mean PyQtGraph ? Because PyGraph is a pure Python library and makes no use of PySide nor PyQt.
-
Then you should subclass that widget and re-implement the mouse event handler(s) to do what you want.
-
Then you should subclass that widget and re-implement the mouse event handler(s) to do what you want.
@SGaist Yeah I did that, copying the contect of the original mouseMoveEvent() to my source file and adding on top of it doesn't look the cleanesr and most ideal for programming but if it work's we'll go with it.
Now the other problem is,
How do you get a cursor position of mouse in relation to the ViewBox in pygraph rather than the whole add globaly?The thing is that the PlotWidget has axiss and title info that can shift the relative mouse position as well as the actually window size which can change the scale,
I was looking and GraphicsView.py of the pyqtgraph source files and saw the function: self.mapToScene(lpos) which doesn't work for me running QtPy6.1 for somereason which hints it could help but I can't know since it outputs the following error when executing it:Traceback (most recent call last): File "C:\Users\User\AppData\Roaming\Python\Python39\site-packages\pyqtgraph\widgets\GraphicsView.py", line 367, in mouseMoveEvent self.sigSceneMouseMoved.emit(self.mapToScene(lpos)) TypeError: arguments did not match any overloaded call: mapToScene(self, QPoint): argument 1 has unexpected type 'QPointF' mapToScene(self, QRect): argument 1 has unexpected type 'QPointF' mapToScene(self, QPolygon): argument 1 has unexpected type 'QPointF' mapToScene(self, QPainterPath): argument 1 has unexpected type 'QPointF' mapToScene(self, int, int): argument 1 has unexpected type 'QPointF' mapToScene(self, int, int, int, int): argument 1 has unexpected type 'QPointF'
Anyidea how to fix it?
-
As I wrote before: there's no need to copy anything, just call the base class implementation.
As for the error you get, transform the QPointF into a QPoint.