Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Adding custom mouse functionality to pyGraph plotWidget
Forum Updated to NodeBB v4.3 + New Features

Adding custom mouse functionality to pyGraph plotWidget

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 2 Posters 1.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MikeLemon
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean PyQtGraph ? Because PyGraph is a pure Python library and makes no use of PySide nor PyQt.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Do you mean PyQtGraph ? Because PyGraph is a pure Python library and makes no use of PySide nor PyQt.

        M Offline
        M Offline
        MikeLemon
        wrote on last edited by
        #3

        @SGaist Yes I mean the pyqtgraph library which utilizes QT for that: https://www.pyqtgraph.org/

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then you should subclass that widget and re-implement the mouse event handler(s) to do what you want.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          M 1 Reply Last reply
          0
          • SGaistS SGaist

            Then you should subclass that widget and re-implement the mouse event handler(s) to do what you want.

            M Offline
            M Offline
            MikeLemon
            wrote on last edited by
            #5

            @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?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved