Results 1 to 10 of 10

Thread: Dragging a vertina line (x=const) on graph (QwtPlot) and return its x value

  1. #1
    Join Date
    Mar 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Dragging a vertina line (x=const) on graph (QwtPlot) and return its x value

    I have gone through the examples, but couldn't figure out how to implement it. Ideally I can use Qt Designer to set up the UI (since I need other inputs as well, and its easier to make in Designer than hardcoding it from scratch).

    I would like to have 2 lines on my plot that act as x limits to a 2D curve. The curve should be draggable along the x axis, and once the mouse is released, a function will run to update the graph.

    Many thanks

    Qt Creator 3.0.1, Qt 5.2.1, qwt 6.1.0, Mac OS 10.9

  2. #2
    Join Date
    Dec 2013
    Location
    Toronto, Canada
    Posts
    62
    Thanked 16 Times in 15 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Dragging a vertina line (x=const) on graph (QwtPlot) and return its x value

    I have a Ruler class that does exactly what you want

    The class is a subclass of QwtPlotMarker and "HAS A" subclass of QwtPlotPicker

    I will find a way to share the files with you.. Its a little to bulky for here..

    I will do this within the next 24hrs

  3. #3
    Join Date
    Mar 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Dragging a vertina line (x=const) on graph (QwtPlot) and return its x value

    thats absolutely wonderful
    thank you so much =D

  4. #4
    Join Date
    Dec 2013
    Location
    Toronto, Canada
    Posts
    62
    Thanked 16 Times in 15 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Dragging a vertina line (x=const) on graph (QwtPlot) and return its x value

    Here you go ...
    http://sourceforge.net/projects/caru...urce=directory

    I be happy to learn of any bugs, improvements, etc.

  5. #5
    Join Date
    Mar 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Dragging a vertina line (x=const) on graph (QwtPlot) and return its x value

    Its been great so far! Thank you so much for the code.

  6. #6
    Join Date
    Mar 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Dragging a vertina line (x=const) on graph (QwtPlot) and return its x value

    Is it possible to offset/manipulate the label of the ruler when you are dragging it? Say the ruler is for limiting something from a point that is not x=0, and I would like a label that reflects the offset.

    Many thanks

  7. #7
    Join Date
    Dec 2013
    Location
    Toronto, Canada
    Posts
    62
    Thanked 16 Times in 15 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Dragging a vertina line (x=const) on graph (QwtPlot) and return its x value

    Is it possible to offset/manipulate the label of the ruler when you are dragging it? Say the ruler is for limiting something from a point that is not x=0, and I would like a label that reflects the offset.
    It sounds like you want to be able to track relative positions. I do not know why... but, with a little work, it can be done.

    In the picker.h, augment the class by adding a variable _xReference and the accessor functions. Be sure to initialize _xReference in the picker constructor.

    Qt Code:
    1. class Picker: public QwtPlotPicker
    2. {
    3. Q_OBJECT
    4. public:
    5. ....
    6. void setReferenePosition(double pos);
    7. double referenePosition()const;
    8. protected:
    9. ....
    10.  
    11. double _xReference;
    12. };
    13. ...
    14. inline void setReferenePosition(double pos)
    15. {
    16. _xReference = pos;
    17. }
    18.  
    19. inline double referenePosition()const {return _xReference ;}
    20. ...
    To copy to clipboard, switch view to plain text mode 

    In picker.cpp, make a change to trackerTextF()

    replace... return xTitle.text() + "=" + QString::number(_rulerPos);
    with... return xTitle.text() + "=" + QString::number(_rulerPos - _xReference);

    and
    replace... return QString::number(_rulerPos);
    with... return QString::number(_rulerPos- _xReference);


    Client side
    ...
    Ruler* rv1 = new RulerV(_plot, "Vertical_1");
    rv1->picker()->setReferenePosition(2);
    ...

    Dragging rv1 to a absolute position 5.0 displays a tracking text (relative) of 3.0

    Let me know how this went.

  8. #8
    Join Date
    Mar 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Dragging a vertina line (x=const) on graph (QwtPlot) and return its x value

    Works perfectly.
    Thank you so much.

  9. #9
    Join Date
    Dec 2013
    Location
    Toronto, Canada
    Posts
    62
    Thanked 16 Times in 15 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Dragging a vertina line (x=const) on graph (QwtPlot) and return its x value

    Ok..
    But it is a intrusive way to add new functionality. Not the C++ way.

    A better solution may be to provide a member function in the Ruler class that allows clients to install a Picker of their choice.

    Thus,
    ...
    void setRulerPicker(Picker* picker)

    client do..

    class CustomPicker: public Picker
    {
    ....
    QwtText trackerTextF (const QPointF & pt) const; //reimplemented

    void setReferenePosition(double pos);
    private:
    double _xReference;
    ...
    };

    Ruler* rv1 = new RulerV(_plot, "Vertical_1");
    rv1->setRulerPicker(new CustomPicker(...));

    ...
    ((CustomPicke*)rv1->picker())->setReferenePosition(2);
    ...

    As you may suspect, the Ruler class is a stripped down version... I'll tidy up things and commit. You could expect to find a ruler editor in the form of a right click menu. I'll augmented Ruler class to provide setRulerPicker()

    I'll try to get this done within the next 24hrs or so

  10. #10
    Join Date
    Dec 2013
    Location
    Toronto, Canada
    Posts
    62
    Thanked 16 Times in 15 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Dragging a vertina line (x=const) on graph (QwtPlot) and return its x value

    Added right click menu and a little more
    see..http://sourceforge.net/projects/caru...urce=directory

Similar Threads

  1. Replies: 4
    Last Post: 9th May 2016, 13:30
  2. Get current line edit text and return to some class
    By Cyrebo in forum Qt Programming
    Replies: 3
    Last Post: 1st May 2013, 12:18
  3. Replies: 9
    Last Post: 28th March 2011, 23:51
  4. Replies: 1
    Last Post: 22nd July 2010, 18:12
  5. Line Graph
    By sabeesh in forum Qt Programming
    Replies: 2
    Last Post: 24th July 2007, 10:13

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.