Results 1 to 4 of 4

Thread: Restricting cursor movement (or appearance) to follow only the curve

  1. #1
    Join Date
    Oct 2011
    Location
    Zurich
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Restricting cursor movement (or appearance) to follow only the curve

    Hi everyone,

    It's my first week learning to use Qt and Qwt, so please bear with me. I'd like to make a plotting function with cursor similar to that of the BodePlot with:

    (1) a curve,
    (2) cursor display with the values being shown,
    (3) restrict the cursor's movements to slide along the values of the curve only when within the plot, i.e. given mouse position x, fixing mouse position y.

    I've taken apart the code in the Bode example and kept only a few elements which satisfy points (1) and (2) but would appreciate some suggestions, hints or pseudocode for doing (3)!

    Thanks very much!

  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: Restricting cursor movement (or appearance) to follow only the curve

    I'm not sure what you mean in 3).
    Are you talking about mouse cursor and restricting it's movement?
    I'm not sure if that's a good idea.
    In my opinion you should not play with the mouse cursor, instead you can add a marker which could follow the curve.

    As to 'how to'.
    You can install event filter on the canvas to get mouse move events only when mouse cursor is over the canvas.
    Having X screen coordinate you can translate it to X world coordinate using QwtPlot::transform().
    Now the difficult part: you can't use QwtPlot facilities to get curve Y value at cetain X (at least I don't know how).
    You have to do it yourself and it will depend on data model you have.

    In worst case, where your data takes forever to find Y for X you could use canvas cache to find the Y.
    Just interogate all pixels in X column (where X comes from mouse move event over the canvas) in the cache and look for first black pixel you find.
    This way you get Y position in the canvas which you can map to screen using QwtPlotCanvas::mapToGlobal().
    I haven't tested it but I think it should work

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,278
    Thanked 872 Times in 820 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Restricting cursor movement (or appearance) to follow only the curve

    Quote Originally Posted by Spitfire View Post
    I'm not sure what you mean in 3).
    Are you talking about mouse cursor and restricting it's movement?
    It should be about the rubber band of the picker.

    Quote Originally Posted by Spitfire View Post
    Now the difficult part: you can't use QwtPlot facilities to get curve Y value at cetain X (at least I don't know how).
    Read also: http://www.qtcentre.org/threads/4505...point-of-curve

    Uwe

  4. #4
    Join Date
    Oct 2011
    Location
    Zurich
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Restricting cursor movement (or appearance) to follow only the curve

    I guess it's not really about restricting the mouse movement, but that when I'm inside of the graph, I have a single point tracing over the curve. I settled with a QwtPickerTrackerMachine which tracks the movements of the cursor and then plots an extra point on my curve following the location of the cursor. If I can now only get rid of the "+" cursor from appearing... (related to my other post).

Similar Threads

  1. Replies: 4
    Last Post: 20th July 2011, 13:32
  2. Replies: 2
    Last Post: 25th November 2010, 09:53
  3. "Follow symbol under cursor" does not work...?
    By liormessinger in forum Qt Tools
    Replies: 0
    Last Post: 16th September 2009, 17:22
  4. Restricting a widget from being moved
    By ArmanS in forum Qt Programming
    Replies: 3
    Last Post: 14th April 2009, 15:48
  5. Replies: 3
    Last Post: 7th May 2008, 11:33

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.