Results 1 to 1 of 1

Thread: A problem when using QwtPlotPanner and QwtPlotDirectpaint

  1. #1
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    2

    Default A problem when using QwtPlotPanner and QwtPlotDirectpaint

    Hi,

    I encounter a problem when using QwtPlotPannerand QwtPlotDirectPainter. It is described as following.

    I make a plot widget by QwtPlot, and implement panner, picker and magnifier by inheriting QwtPlotPanner, QwtPlotPickand QwtPlotMagnifier.

    The symbol selection is implemented by connect signal http://doc.qt.io/qt-4.8/QwtPlotPick::selected(QPointF) with a select(QPointF) function. I also write a highlight function for selected symbol, using QwtPlotDirectPainter, similar to the example of event_filter with qwt package. The code show as follow

    The plot:
    Qt Code:
    1. class QwtFoilPlot: public QwtPlot
    2. {
    3. Q_OBJECT
    4. public:
    5. QwtFoilPlot(QWidget *parent = NULL);
    6. ....
    7. }
    8.  
    9. QwtFoilPlot::QwtFoilPlot( QWidget *parent /*= NULL*/ ):
    10. curve_np(200)
    11. {
    12. ......
    13. // panner
    14. p_panner = new CanvasPanner(this);
    15. // picker
    16. p_picker = new CanvasPicker(canvas());
    17. p_picker->setStateMachine(new QwtPickerClickPointMachine);
    18. p_picker->setRubberBand(QwtPicker::NoRubberBand);
    19. ......
    20. }
    To copy to clipboard, switch view to plain text mode 


    The plot picker:
    Qt Code:
    1. class CanvasPicker: public QObject
    2. {
    3. QOBJECT
    4. public:
    5. CanvasPicker(QwtPlotCanvas* p);
    6. private:
    7. void select(const QPoint &);
    8. .......
    9. void showCursor(bool enable);
    10. .......
    11. QwtPlotCurve *d_selectedCurve;
    12. int d_selectedPoint;
    13. };
    To copy to clipboard, switch view to plain text mode 

    The method definition for this picker
    Qt Code:
    1. void CanvasPicker::select( const QPointF& p )
    2. {
    3. QPoint pos = transform(p);
    4. QwtPlotCurve *curve = NULL;
    5. double dist = 10e10;
    6. int index = -1;
    7.  
    8. const QwtPlotItemList& itmList = plot()->itemList();
    9. for ( QwtPlotItemIterator it = itmList.begin();
    10. it != itmList.end(); ++it )
    11. {
    12. if ( (*it)->rtti() == QwtPlotItem::Rtti_PlotCurve )
    13. {
    14. QwtPlotCurve *c = (QwtPlotCurve*)(*it);
    15. double d;
    16. int idx = c->closestPoint(pos, &d);
    17. if ( d < dist )
    18. {
    19. curve = c;
    20. index = idx;
    21. dist = d;
    22. }
    23. }
    24. }
    25.  
    26. showCursor(false);
    27. p_selectedCurve = NULL;
    28. p_selectedPoint = -1;
    29.  
    30. if ( curve && dist < 10 ) // 10 pixels tolerance
    31. {
    32. p_selectedCurve = curve;
    33. p_selectedPoint = index;
    34. showCursor(true);
    35. }
    36. }
    37.  
    38. void CanvasPicker::showCursor(bool showIt)
    39. {
    40. if ( !p_selectedCurve )
    41. return;
    42.  
    43. QwtSymbol *symbol = const_cast<QwtSymbol *>( p_selectedCurve->symbol() );
    44.  
    45. const QBrush brush = symbol->brush();
    46. if ( showIt )
    47. symbol->setBrush(symbol->brush().color().dark(180));
    48.  
    49. QwtPlotDirectPainter directPainter;
    50. directPainter.drawSeries(p_selectedCurve, p_selectedPoint, p_selectedPoint);
    51.  
    52. if ( showIt )
    53. symbol->setBrush(brush); // reset brush
    54. }
    To copy to clipboard, switch view to plain text mode 

    The panner
    Qt Code:
    1. class CanvasPanner: public QwtPlotPanner
    2. {
    3. Q_OBJECT
    4. public:
    5. CanvasPanner(QwtFoilPlot *plot);
    6.  
    7. private:
    8.  
    9.  
    10. };
    11.  
    12. CanvasPanner::CanvasPanner( QwtFoilPlot *plot ):
    13. QwtPlotPanner(plot->canvas())
    14. {
    15. setMouseButton(Qt::MidButton);
    16. }
    To copy to clipboard, switch view to plain text mode 

    The problem appear when I pan the canvas after a selection. When I pick a symbol on a curve by click, the symbol will be highlighted normally(1.png). Then I start to pan the canvas without releasing the mid button, the highlighted symbol will offset a little to upper left(2.png and 3.png). Then I release the button, the offset disappeared.

    Did anyone see this problem before? Is there any simple way to solve this problem?
    Thank you
    1.png2.png3.png
    Last edited by apango; 8th June 2012 at 16:46.

Similar Threads

  1. Graphic effects of QwtPlotPanner
    By mastupristi in forum Qwt
    Replies: 2
    Last Post: 2nd July 2019, 21:14
  2. Replies: 0
    Last Post: 6th March 2012, 10:56
  3. Replies: 1
    Last Post: 24th February 2012, 15:01
  4. Replies: 4
    Last Post: 10th June 2010, 13:31
  5. Replies: 1
    Last Post: 3rd November 2008, 10:13

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.