Results 1 to 8 of 8

Thread: spectrogram with fixed aspect ratio (1:1) and zooming/unzooming

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2014
    Posts
    9
    Thanks
    2

    Default Re: spectrogram with fixed aspect ratio (1:1) and zooming/unzooming

    Thread is really old, but here's my solution:

    Qt Code:
    1. class MyPlotZoomer : public QwtPlotZoomer {
    2.  
    3. // ...
    4.  
    5. private:
    6. int zx;
    7. int zy;
    8.  
    9. protected:
    10. virtual void widgetMousePressEvent(QMouseEvent *me);
    11. virtual void move(const QPoint &p);
    12. };
    13.  
    14. void MyPlotZoomer::widgetMousePressEvent(QMouseEvent *me)
    15. {
    16. if ( mouseMatch( MouseSelect1, me ) )
    17. {
    18. zx = me->pos().x();
    19. zy = me->pos().y();
    20. }
    21.  
    22. QwtPlotPicker::widgetMousePressEvent(me);
    23. }
    24.  
    25. void MyPlotZoomer::move(const QPoint &p)
    26. {
    27. QPoint square;
    28.  
    29. if( abs( p.x() - zx )
    30. >
    31. abs( p.y() - zy ) )
    32. {
    33. square.setX( p.x() );
    34.  
    35. if( p.y() > zy )
    36. square.setY( zy + abs( p.x() - zx ) );
    37. else
    38. square.setY( zy - abs( p.x() - zx ) );
    39. }
    40. else
    41. {
    42. square.setY( p.y() );
    43.  
    44. if( p.x() > zx )
    45. square.setX( zx + abs( p.y() - zy ) );
    46. else
    47. square.setX( zx - abs( p.y() - zy ) );
    48. }
    49.  
    50. QwtPlotZoomer::move( square );
    51. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2014
    Posts
    9
    Thanks
    2

    Default Re: spectrogram with fixed aspect ratio (1:1) and zooming/unzooming

    Ok, this is bad, I cannot edit my incorrect post. It looks like all you need to do in QWT 6.3 is to overload QwtPlotZoomer::zoom and make it call QwtPlotRescaller::rescale()

    Qt Code:
    1. class MyPlotZoomer : public QwtPlotZoomer
    2. {
    3. public:
    4. MyPlotZoomer(QwtPlotCanvas* widget, bool doReplot=true);
    5. QwtPlotRescaler * myPlotRescaler;
    6.  
    7. virtual void zoom(const QRectF& rect);
    8. }
    9.  
    10. MyPlotZoomer::MyPlotZoomer(QwtPlotCanvas* widget, bool doReplot) :
    11. QwtPlotZoomer(widget, doReplot)
    12. {
    13. myPlotRescaler = new QwtPlotRescaler( widget );
    14. //For example:
    15. myPlotRescaler->setRescalePolicy( QwtPlotRescaler::Expanding );
    16. myPlotRescaler->setExpandingDirection( QwtPlotRescaler::ExpandBoth );
    17. myPlotRescaler->setReferenceAxis(QwtPlot::xBottom);
    18. myPlotRescaler->setAspectRatio(QwtPlot::yLeft, 1.0);
    19. myPlotRescaler->setAspectRatio(QwtPlot::yRight, 0.0);
    20. myPlotRescaler->setAspectRatio(QwtPlot::xTop, 0.0);
    21. }
    22.  
    23. MyPlotZoomer::zoom(const QRectF& rect)
    24. {
    25. QwtPlotZoomer::zoom(rect);
    26.  
    27. //Most important
    28. myPlotRescaler->rescale();
    29. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by gavinmagnus; 18th November 2016 at 11:53.

Similar Threads

  1. Replies: 5
    Last Post: 11th June 2011, 15:29
  2. keeping aspect ratio while resizing
    By franco.amato in forum Qt Programming
    Replies: 2
    Last Post: 19th November 2009, 20:12
  3. Preserving aspect ratio of image
    By Banjo in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2009, 13:39
  4. QProcess+mPlayer+Aspect Ratio
    By IGHOR in forum Qt Programming
    Replies: 0
    Last Post: 22nd March 2008, 03:14
  5. aspect ratio of top-level widgets
    By urbangipsy in forum Qt Programming
    Replies: 3
    Last Post: 16th January 2007, 21:49

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
  •  
Qt is a trademark of The Qt Company.