View Full Version : selecting text in Qwt plots

25th April 2008, 23:09
Hi all,
I have a Qwt plot created with a curve in it and I have some text items scattered on the plot. Is there any way so that I can select any of these text items on the plot and get the (x,y) coordinates of the selected text in the plot?....There is the function to select closest point on the curve, but nothing I can find to select closest text/symbol on the plot. In Matlab, you can select text items on the plot by mouse-over on the text, but I cannot seem to figure out how to do the same in Qwt. Any help in this regard will be great.


26th April 2008, 18:40
By scattered texts I guess you mean markers. Are you interested in the position of the marker or the bounding rect of its label ?


27th April 2008, 08:13
Well, I will be putting these text/markers at a defined (x,y) coordinates. When the user has the mouse over this marker, he should be able to select it . E.g. to the user the marker should be selectable e.g. the text marker turns red from black when the mouse is over the marker, and if i can get the reference to this marker when the user clicks, then I can do further stuff!!!!

I will try to add a screen-shot of my problem tomorrow, if that can help.
Thanks a lot for replying...


12th May 2008, 08:11
Finally I have found a solution....:D

I finally managed this in python...

class SimplePlot(QwtPlot):

def __init__(self, *args):

#put the picker in my __init__ function
self.picker = QwtPlotPicker(QwtPlot.xBottom,QwtPlot.yLeft,

#connect the signal from the picker to my slot "pickerSlot"
self.connect(self.picker,SIGNAL("selected(const QwtDoublePoint&)"),self.pickerSlot)

#pickerSlot() to process picking signals in the plot
def pickerSlot(self,qDoublePoint):
#transform the (x,y) coordinates of the point of clicking to plot coordinates
pickX = self.transform(QwtPlot.xBottom,qDoublePoint.x())
pickY = self.transform(QwtPlot.yleft,qDoublePoint.y())

#get the closest marker to point of clicking on the plot
#closestmarker() returns the tuple containing the marker_Key and distance
#the distance can be used to filter out the selection if desired
markerSelected = self.closestMarker(pickX,pickY)

#get the key to the closest marker
markerKey = markerSelected[0]
#i set the font of the selected text to bold to show that it has been selected
fn = self.fontInfo().family()


Using this, whatever text has been put in the plot using inserMarker() function, can be selected by clicking next to the plot. The equivalent C++ code should be straight-forward I believe.

Any suggestions or queries or optimizations to the above way is very much welcome. Please leave your comments.