MCPcopy
hub / github.com/PyQt5/PyQt / MyWindow

Class MyWindow

PyQtGraph/mouseFlow.py:28–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26
27
28class MyWindow(QMainWindow, Ui_Form):
29 def __init__(self, parent=None):
30 super(MyWindow, self).__init__(parent)
31 self.setupUi(self)
32 x = np.linspace(-100, 100, 1000)
33 data = np.sin(x) / x
34 self.graphicsView.plot(data, pen=(255, 255, 255, 200))
35 self.label = pg.TextItem(text="横坐标:{}".format(0))
36 self.graphicsView.addItem(self.label)
37 self.setMouseTracking(True)
38 self.graphicsView.scene().sigMouseMoved.connect(self.onMouseMoved)
39
40 def onMouseMoved(self, evt):
41 if self.graphicsView.plotItem.vb.mapSceneToView(evt):
42 point = self.graphicsView.plotItem.vb.mapSceneToView(evt)
43 self.label.setHtml("<p style='color:white'>横坐标:{0}</p>".format(point.x()))
44
45
46if __name__ == '__main__':

Callers 1

mouseFlow.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected