title: Pyqtgraph mouse crosshair
body: <p>I want a mouse crosshair for a pyqtgraph (GraphicsView()).
  I was able to create a crosshair in a separate window using the code at the following link: <a href="https://stackoverflow.com/questions/57359843/pyqtgraph-add-crosshair-on-mouse-x-graph-y">pyqtgraph: add crosshair on mouse_x graph_y</a>, but I can't re-create It in GraphicsView().
  This Is my current code, but It Isn't working:</p>
  <pre><code>import sys
  import pyqtgraph as pg
  from PyQt6 import QtCore
  from PyQt6.QtWidgets import *
  
  
  class CrosshairPlotWidget(QWidget):
      &quot;&quot;&quot;Scrolling plot with crosshair&quot;&quot;&quot;
  
      def __init__(self, parent=None):
          super(CrosshairPlotWidget, self).__init__(parent)
  
          self.LEFT_X = -10
          self.RIGHT_X = 0
  
          self.crosshair_plot_widget = pg.PlotWidget()
          # self.crosshair_plot_widget.setXRange(self.LEFT_X, self.RIGHT_X)
          self.crosshair_plot_widget.setLabel('left', 'Price')
          self.crosshair_plot_widget.setLabel('bottom', 'Time')
          self.crosshair_color = (196, 220, 255)
  
          self.crosshair_plot = self.crosshair_plot_widget.plot()
  
          self.layout = QGridLayout()
          self.layout.addWidget(self.crosshair_plot_widget)
  
          self.crosshair_plot_widget.plotItem.setAutoVisible(y=True)
          self.vertical_line = pg.InfiniteLine(angle=90)
          self.horizontal_line = pg.InfiniteLine(angle=0, movable=False)
          self.vertical_line.setPen(self.crosshair_color)
          self.horizontal_line.setPen(self.crosshair_color)
          self.crosshair_plot_widget.setAutoVisible(y=True)
          self.crosshair_plot_widget.addItem(self.vertical_line, ignoreBounds=True)
          self.crosshair_plot_widget.addItem(self.horizontal_line, ignoreBounds=True)
  
          self.crosshair_update = pg.SignalProxy(self.crosshair_plot_widget.scene().sigMouseMoved, rateLimit=60, slot=self.update_crosshair)
  
      def update_crosshair(self, event):
          &quot;&quot;&quot;Paint crosshair on mouse&quot;&quot;&quot;
  
          coordinates = event[0]
          if self.crosshair_plot_widget.sceneBoundingRect().contains(coordinates):
              mouse_point = self.crosshair_plot_widget.plotItem.vb.mapSceneToView(coordinates)
              index = mouse_point.x()
              if self.LEFT_X &lt; index &lt;= self.RIGHT_X:
                  self.crosshair_plot_widget.setTitle(&quot;&lt;span style='font-size: 12pt'&gt;x=%0.1f,   &lt;span style='color: red'&gt;y=%0.1f&lt;/span&gt;&quot; % (mouse_point.x(), mouse_point.y()))
              self.vertical_line.setPos(mouse_point.x())
              self.horizontal_line.setPos(mouse_point.y())
  
      def get_crosshair_plot_layout(self):
          return self.layout
  
  # Create crosshair plot
  crosshair_plot = CrosshairPlotWidget()
  
  app = QApplication(sys.argv)
  view = pg.GraphicsView()
  l = pg.GraphicsLayout()
  view.setCentralItem(l)
  view.show()
  
  # cw = QWidget()
  # ml = QGridLayout()
  # cw.setLayout(ml)
  # view.setCentralWidget(cw)
  
  l.addLayout(crosshair_plot.get_crosshair_plot_layout(), 0, 0)
  
  if __name__ == '__main__':
      if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
          QApplication.instance().exec()
  </code></pre>
  <p>Any ideas of how I can do that?</p>