Hi,
This isn't very flexible (you'll need to update the list of handles if any
are added/removed) but should be a start:
#!/usr/bin/env python3
from PyQt5 import QtWidgets
import pyqtgraph as pg
class TestPlot(pg.GraphicsLayoutWidget):
def __init__(self):
super().__init__()
self.plot = self.addPlot()
self.roi = pg.LineSegmentROI(positions=[(0.25, 0.25), (0.75, 0.75)])
self.plot.addItem(self.roi, ignoreBounds=True)
self.plot.disableAutoRange()
self.roi.sigRegionChanged.connect(self._roi_changed)
self.roi_labels = [ pg.TextItem(text='label', anchor=(0.5, 1.0)) for
_ in self.roi.getHandles() ]
for label in self.roi_labels:
self.plot.addItem(label)
self._roi_changed()
def _roi_changed(self):
for h_i, handle in enumerate(self.roi.getHandles()):
handle_pos = self.roi.pos() + handle.pos()
self.roi_labels[h_i].setPos(handle_pos)
self.roi_labels[h_i].setText("{}, {}".format(round(handle_pos[0
], 2), round(handle_pos[1], 2)))
def main():
import sys
app = QtWidgets.QApplication(sys.argv)
mainwindow = TestPlot()
mainwindow.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Patrick
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/1de5fa32-5ca2-40d0-83d8-bada85a87d8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.