Results 1 to 4 of 4

Thread: qwtPlotPicker: simple problem to start understanding how it works

  1. #1
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default qwtPlotPicker: simple problem to start understanding how it works

    I have been reading several examples and threads about qwtPlotPicker, but most people have extreme problems for the standards of my understanding, so the solutions are more confusing than answering to my questions.

    Problem
    1. create a picker
    2. when you click
    3. you leave mark on the plot/canvas, a cross "+", an "x", whatever
    4. get the clicked coordinates in a variable


    So far, I have reached this point:

    Qt Code:
    1. mypicker = new QwtPlotPicker(m_amp->canvas());
    2. mypicker->setTrackerMode(QwtPicker::AlwaysOn);
    3. mypicker->setRubberBand(QwtPicker::VLineRubberBand);//not sure for this!
    4. mypicker->setSelectionFlags(QwtPicker::PointSelection | QwtPicker::ClickSelection);
    To copy to clipboard, switch view to plain text mode 

    any suggestions to move on?!

  2. #2
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qwtPlotPicker: simple problem to start understanding how it works

    well, I managed some steps.
    I have created a picker:

    Qt Code:
    1. d_picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
    2. QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,
    3. myPlot->canvas());
    4. d_picker->setStateMachine(new QwtPickerDragRectMachine());
    5. d_picker->setRubberBandPen(QColor(Qt::green));
    6. d_picker->setRubberBand(QwtPicker::CrossRubberBand);
    7. d_picker->setTrackerPen(QColor(Qt::blue));
    To copy to clipboard, switch view to plain text mode 

    but I am still missing the rest:


    Qt Code:
    1. when you click you leave mark on the plot/canvas, a cross "+", an "x", whatever
    2. get the clicked coordinates in a variable
    To copy to clipboard, switch view to plain text mode 

    the methods

    Qt Code:
    1. void selected (const QwtDoublePoint &pos)
    2. void selected (const QwtDoubleRect &rect)
    3. void selected (const QwtArray< QwtDoublePoint > &pa)
    To copy to clipboard, switch view to plain text mode 

    are signals. Should i try to make a connection between these signals and a custom slot where I will store the clicked values? Which setStateMachine is the proper one in order to get 4 separate points of the plot?


    Added after 22 minutes:


    Is the following combination possible to work?

    Qt Code:
    1. d_picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
    2. QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,
    3. myPlot->canvas());
    4. d_picker->setStateMachine(new QwtPickerClickPointMachine());
    5. d_picker->setRubberBandPen(QColor(Qt::green));
    6. d_picker->setRubberBand(QwtPicker::CrossRubberBand);
    7. d_picker->setTrackerPen(QColor(Qt::blue));
    8.  
    9.  
    10. connect(d_picker, SIGNAL (selected(const QwtDoublePoint &)), myPlot, SLOT (setPoint1(const QwtDoublePoint &)) );
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. void my2dPlot::setPoint1(const QwtDoublePoint & po1)
    2. {
    3. point1 = po1;
    4.  
    5. QString x1,y1;
    6. x1.setNum(point1.x());
    7. y1.setNum(point1.y());
    8. QString info("x >>> " + x1 + " y >>> " +y1);
    9.  
    10. showInfo(info);
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by fatecasino; 4th January 2011 at 22:52. Reason: updated contents

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: qwtPlotPicker: simple problem to start understanding how it works

    If you set the picker machine to QwtPickerClickPointMachine (ClickSelection | PointSelection) you will get only a single point. That is, the selected( const QwtDoublePoint & ) signal will be emitted. If you want more than one point, then you need to use PolygonSelection instead of PointSelection. In that case, the selected( const QwtArray< QwtDoublePoint > & ) signal will be emitted. RectSelection results in a QwtDoubleRect signal.

    The picker does not put "x" or other marks on the plot, as far as I know. So your #3 idea is not correct.

    The picker does not store the selected points. That's what the signals are there for. You connect a slot to the signal, and the save the points yourself if you need them.

  4. #4
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qwtPlotPicker: simple problem to start understanding how it works

    use this signal and connect it to a custom slot. This signal is emitted when the user clicks if you have set your picker to "PointSelection". For setting a mark, you have to use a QwtPlotMarker.

    example:
    Qt Code:
    1. myMarker = new QwtPlotMarker();
    2. myMarker ->setSymbol(QwtSymbol(QwtSymbol::Cross, QBrush(Qt::darkRed), QPen(Qt::red, 2, Qt::DashLine), QSize(100,100)));
    3. myMarker->attach(myPlot);
    4. myMarker->setVisible(false);
    5.  
    6. void clicked(const QwtDoublePoint &pos)
    7. {
    8. myMarker->setVisible(true);
    9. myMarker->setValues(pos);
    10. myPlot->replot(); // replot to show/refresh marker
    11. }
    To copy to clipboard, switch view to plain text mode 

    hope this helps!
    Felix

Similar Threads

  1. setVisible(bool) problem, only works one way
    By hojoff79 in forum Newbie
    Replies: 3
    Last Post: 29th December 2010, 19:01
  2. QSerialDevice problem to start in GUi
    By ssaku in forum Qt Quick
    Replies: 9
    Last Post: 6th December 2010, 09:51
  3. Replies: 3
    Last Post: 18th July 2010, 14:53
  4. QProcess problem to start executable
    By cydside in forum Qt Programming
    Replies: 3
    Last Post: 17th June 2010, 19:48
  5. Replies: 14
    Last Post: 20th April 2010, 12:40

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.