Question

i'm trying to let the user draw a curve on my plot canvas via mouse click-and-release, to emit a signal after releasing the mouse and send the array of points to another method for further processing.

Right now my code looks like this:

self.plotPicker = Qwt.QwtPlotPicker(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PolygonSelection, Qwt.QwtPlotPicker.PolygonRubberBand, Qwt.QwtPicker.AlwaysOn, plot.canvas())
self.plotPicker.setRubberBandPen(QPen(Qt.green))
self.plotPicker.setTrackerPen(QPen(Qt.cyan))
self.connect(self.plotPicker, SIGNAL('selected(const QwtPolygon&)'), self.onDrawing)

The problem is, the QwtPolygon send to the onDrawing method does only get 2 points. The beginning and end point of the straigt line between the point where the mouse was clicked first time and the the point where it was clicked the second time.

Is it possible to record arbitrary shapes and polygons via a method in Qwt (v.5 due to python usage) ?

Was it helpful?

Solution

Okay i solved it by overloading QwtPlotPicker, recording all the coordinates returned by trackerText and doing a little sampling afterwards. Looks like this:

def trackerText(self, point):

    if _record:
        self.recording = True
        pos = self.invTransform(point)  
        if(len(self.recorded_data)):
            if(eucliddist((pos.x(), pos.y()), self.recorded_data[-1]) > 0.0):
                self.recorded_data.append((pos.x(), pos.y()))
        else:
            self.recorded_data.append((pos.x(), pos.y()))            
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top