Results 1 to 4 of 4

Thread: selecting text in Qwt plots

  1. #1
    Join Date
    Apr 2008
    Location
    Bangalore, India
    Posts
    7
    Qt products
    Qt3
    Platforms
    Unix/X11

    Post selecting text in Qwt plots

    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.

    Kaustav.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,258
    Thanked 862 Times in 811 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: selecting text in Qwt plots

    By scattered texts I guess you mean markers. Are you interested in the position of the marker or the bounding rect of its label ?

    Uwe

  3. #3
    Join Date
    Apr 2008
    Location
    Bangalore, India
    Posts
    7
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: selecting text in Qwt plots

    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...

    Regards,
    Kaustav.

  4. #4
    Join Date
    Apr 2008
    Location
    Bangalore, India
    Posts
    7
    Qt products
    Qt3
    Platforms
    Unix/X11

    Talking Re: selecting text in Qwt plots - success@last

    Finally I have found a solution....

    I finally managed this in python...

    class SimplePlot(QwtPlot):
    Qt Code:
    1. def __init__(self, *args):
    2. apply(QwtPlot.__init__,(self,)+args)
    3.  
    4. #put the picker in my __init__ function
    5. self.picker = QwtPlotPicker(QwtPlot.xBottom,QwtPlot.yLeft,
    6. QwtPicker.PointSelection,QwtPicker.NoRubberBand,
    7. QwtPicker.AlwaysOn,self.canvas())
    8.  
    9. #connect the signal from the picker to my slot "pickerSlot"
    10. self.connect(self.picker,SIGNAL("selected(const QwtDoublePoint&)"),self.pickerSlot)
    11.  
    12. #pickerSlot() to process picking signals in the plot
    13. def pickerSlot(self,qDoublePoint):
    14. #transform the (x,y) coordinates of the point of clicking to plot coordinates
    15. pickX = self.transform(QwtPlot.xBottom,qDoublePoint.x())
    16. pickY = self.transform(QwtPlot.yleft,qDoublePoint.y())
    17.  
    18. #get the closest marker to point of clicking on the plot
    19. #closestmarker() returns the tuple containing the marker_Key and distance
    20. #the distance can be used to filter out the selection if desired
    21. markerSelected = self.closestMarker(pickX,pickY)
    22.  
    23. #get the key to the closest marker
    24. markerKey = markerSelected[0]
    25. #i set the font of the selected text to bold to show that it has been selected
    26. fn = self.fontInfo().family()
    27. self.setMarkerLabel(markerKey,"s",QFont(fn,12,QFont.Bold,False),Qt.blue)
    28.  
    29. self.replot()
    To copy to clipboard, switch view to plain text mode 

    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.

    Thanks
    Kaustav.
    Last edited by jpn; 12th May 2008 at 09:25. Reason: changed [color] to [code] tags

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. Replies: 4
    Last Post: 25th October 2007, 13:23
  3. Qwt 5 - render TeX text
    By ak in forum Qwt
    Replies: 2
    Last Post: 1st May 2007, 10:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.