Results 1 to 7 of 7

Thread: How to use QwtPlotPicker to track some selected points?

  1. #1
    Join Date
    Feb 2012
    Location
    Stuttgart / Germany
    Posts
    35
    Thanks
    6
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Question How to use QwtPlotPicker to track some selected points?

    Hello,
    I have posted a lot and I got a lot of help here. I need another one. I'm plotting graphs with dotted line and tracking using QwtPlotPicker, but it tracks the plot area and I would like to track only some selected points. My code to track the whole area is:

    Qt Code:
    1. picker = new QwtPlotPicker(QwtPlot::xBottom, channelSelection->currentIndex(),
    2. QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,
    3. plot->canvas());
    4. picker->setStateMachine(new QwtPickerDragPointMachine());
    5. picker->setRubberBandPen(QColor(Qt::darkMagenta));
    6. picker->setRubberBand(QwtPicker::CrossRubberBand);
    7. picker->setTrackerPen(QColor(Qt::green));
    To copy to clipboard, switch view to plain text mode 

    As I said, this code tracks the whole plotting area and I want to track just some points that I have saved in my QVector. For example, the draw below is showing the picker tracking some part of the plotting area and showing the x and y axis value:

    trackNow.jpg

    And I would like to show the value according by the points that I have, the tracking would show something just when the mouse is on the place that the point is equal to some point of my vector. I have the line and the dots, the dots are my values, when the user pass the mouse on a dot the picker would show the value:

    rightTrack.jpg

    Is it possible to enable the picker just for some points? If yes, someone can help me giving me a tipp, I have no idea how to set the picker to track just some selected points.
    Thanks in advance
    Best Regards

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to use QwtPlotPicker to track some selected points?

    Not out of a box.

    You could use closestPoint() but that's prone to errors.

    But you can easily implement something like that yourself.
    For example - install event filter on the canvas, on mouse move transform cursor screen position to the canvas coordinates, see if any point in your vector is at that position (or close enough) and if it is - display whatever you want.

  3. The following user says thank you to Spitfire for this useful post:

    cesroc (9th March 2012)

  4. #3
    Join Date
    Feb 2012
    Location
    Stuttgart / Germany
    Posts
    35
    Thanks
    6
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to use QwtPlotPicker to track some selected points?

    Thanks Spitfire, I implemmented as you said and it's working. But it's not enough for what I wanted.
    The problem is that I have a lot of points, and when I have this verification while I'm moving the mouse, the tracking gets slow.
    And there is another problem that I don't know how to solve, my values are sometimes like -0.0020001201 and when I use invTransform the values that I get from the x and y axis are not gonna be equal my values, and I need to check if they are equal and not just close, because the user has to know the exactly value of one point.

    Did you understand what I mean?

    If you have any idea, please tell me, I'm out of ideas right now.

    thanks

  5. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,277
    Thanked 871 Times in 819 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to use QwtPlotPicker to track some selected points?

    Quote Originally Posted by cesroc View Post
    Thanks Spitfire, I implemmented as you said and it's working. But it's not enough for what I wanted.
    The problem is that I have a lot of points, and when I have this verification while I'm moving the mouse, the tracking gets slow.
    closestPoint() is not "prone to errors" - but slow. It iterates over all curves an all points. So what you have to do is to implement a faster lookup using the characteristics of your data ( f.e if they are in increasing x order ) or by introducing some sort of spatial index - like f.e. a quadtree.
    Quote Originally Posted by cesroc View Post
    And there is another problem that I don't know how to solve, my values are sometimes like -0.0020001201 and when I use invTransform the values that I get from the x and y axis are not gonna be equal my values, and I need to check if they are equal and not just close, because the user has to know the exactly value of one point.
    Your screen is a matrix of pixels ( f.e 1280x1024 ) and a mouse click is a position in integer coordinates !

    Uwe

  6. #5
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to use QwtPlotPicker to track some selected points?

    I appologize for 'prone to errrors'.
    I ment that if you're looking for point along Y axis closes to the mouse cursor then closestPoint() won't work, which is what the OP has asked for.

    Mea culpa.

    cesroc
    And how it is slow? How many points we're talking about?

  7. #6
    Join Date
    Feb 2012
    Location
    Stuttgart / Germany
    Posts
    35
    Thanks
    6
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to use QwtPlotPicker to track some selected points?

    Hello Spitfire,

    In the best case around 70.000, but when I add all curves it's more than 1.000.000.
    I had another idea, but I'm not sure yet if it's gonna work and help me.
    I was thinking about scan only the x-axis and based on the x-axis I get the index to get the closest y-axis and then jump the marker to the closest point to make easier for the user.

    What do you think? Possible? Would it be faster?

    Thanks for helping me

  8. #7
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to use QwtPlotPicker to track some selected points?

    Because in my approach every point (and there's up to 20M on the plot at a time) after some calculations can be converted to an index in the data set finding actual values is fast an easy but I don't know if it would work for you.

    Any chance you could get me a file with example of your data (70k+)?

    I wonder how my approach would work with it, and if it would I could share some code with you.

Similar Threads

  1. Replies: 1
    Last Post: 23rd December 2011, 08:30
  2. Track QSqlDatabase changes
    By aurelius in forum Qt Programming
    Replies: 0
    Last Post: 12th October 2011, 22:39
  3. Replies: 4
    Last Post: 5th February 2011, 08:33
  4. Frequency of Audio Track
    By vijay_kansal in forum Qt Programming
    Replies: 5
    Last Post: 28th July 2010, 10:15
  5. How to track scrolling
    By Slewman in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2010, 23:45

Tags for this Thread

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.