python 3.x - Display coordinates in pyqtgraph? -


i'm attempting develop gui allows tracking mouse coordinates in plotwidget, , displaying in label elsewhere in main window. have attempted several times emulate crosshair example in pyqtgraph documentation, have not been able agree this. part of difficulty unable understand how access mouse tracking can enable in qtdesigner.

i attempted use the:

proxy = pg.signalproxy(plotted.scene().sigmousemoved, ratelimit=60, slot=mousemoved) plotted.scene().sigmousemoved.connect(mousemoved) 

however, not quite understand allows "update" in real time, nor @ level should have statement. should

def mousemoved(evt):     pos = evt[0]     if plotted.sceneboundingrect().contains(pos):        mousepoint = vb.mapscenetoview(pos)        index = int(mousepoint.x())        if index > 0 , index < len(x):           mousecoordinatesdisplay.settext("<span style='font-size: 12pt'>x=%0.1f, <span style='color: red'>y1=%0.1f</span>" % (mousepoint.x(), y[index], data2[index]))           vline.setpos(mousepoint.x())           hline.setpos(mousepoint.y())  

part of code in ui_mainwindow class, or outside of it?

i able updates work doing following:

in setupui function:

plotted = self.plot vline = pg.infiniteline(angle=90, movable=false) hline = pg.infiniteline(angle=0, movable=false) plotted.additem(vline, ignorebounds=true) plotted.additem(hline, ignorebounds=true) plotted.setmousetracking(true) plotted.scene().sigmousemoved.connect(self.mousemoved)  def mousemoved(self,evt):         pos = evt         if self.plot.sceneboundingrect().contains(pos):             mousepoint = self.plot.plotitem.vb.mapscenetoview(pos)             self.mousecoordinatesdisplay.settext("<span style='font-size: 15pt'>x=%0.1f, <span style='color: black'>y=%0.1f</span>" % (mousepoint.x(),mousepoint.y()))         self.plot.plotitem.vline.setpos(mousepoint.x())         self.plot.plotitem.hline.setpos(mousepoint.y() 

where .mousecoordinatedisplay label. took me forever figure out how use in gui designer. seems between pyqt4 , pyqt5 there change qpointf, new qpointf doesn't allow indexing. passing evt variable, possible map without calling evt[0].


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -