Results 1 to 13 of 13

Thread: Zoom on only one axis?

  1. #1
    Join Date
    Oct 2010
    Posts
    58
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26

    Default Zoom on only one axis?

    Hi,

    I have a plot that plots one curve on the yLeft and another on the yRight because they have different scale. I want to be able to zoom anywhere on the plot and have both y-axes be readjusted so I am looking at both the curves in the zoomer. For example, when I first load up the plot I want to be able to select a rectangle to zoom in on, and even if that rectangle has no curves passing through it, i want the new zoomed in view to show me the data of both my yLeft and yRight curves, over my x-axis scale.

    What I think I need to do is make the zoomer only zoom on the x-axis then somehow have both the y axes rescale. But I can't even figure out how to make the zoom only zoom in the x-axis.

    Any hints? Thanks.

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

    Default Re: Zoom on only one axis?

    maybe it works if you enable autoscaling for the y-axis after zooming?

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,348
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Zoom on only one axis?

    You should be able to make 2 zoomers, and assign one for xBottom/yLeft and the other for xBottom/yRight.

    I do not know if both zoomers can be active at the same time. If they can, then you will get zooming on both y axes simultaneously. I have not tried this, so it is something you will have to experiment with.

  4. #4
    Join Date
    Oct 2010
    Posts
    58
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26

    Default Re: Zoom on only one axis?

    You should be able to make 2 zoomers, and assign one for xBottom/yLeft and the other for xBottom/yRight.
    I have made two zoomers like this and it does allow me to zoom in on both y axes at the same time, but it is not quite what I want. When I zoom I want both y axes to be rescaled so that both the left and right curves will always be visible in my zoomed in area. As it is with the two zoomers made for xBottom/yLeft and xBottom/yRight the y axes do not rescale to the data


    maybe it works if you enable autoscaling for the y-axis after zooming?
    That seems like it might work, but I'm having a hard time actually understanding where the code goes when I use my zoomer. I'm sure this is something trivial but I can't figure it out. I've tried putting debug points at every instance of myZoomer but when I zoom on my plot it never gets to these debug points. Would I set the autoscaling in the zoomer class its self or what? I'll show some of my code so you can see how my program is working:

    What happens is that MyWidget calls MyPlot who calls CurveAttrib, CurveAttrib sets up the y-right and y-left then goes back to MyPlot who sets up the zoomer for the first view, then MyPlot goes back to MyWidget who replots the whole thing.


    Qt Code:
    1. #ifndef MYZOOMER_H
    2. #define MYZOOMER_H
    3. #include <qwt_plot_zoomer.h>
    4.  
    5. class MyZoomer : public QwtPlotZoomer
    6. {
    7. public:
    8. MyZoomer(int xAxis, int yAxis, QwtPlotCanvas *canvas):
    9. QwtPlotZoomer(xAxis, yAxis, canvas)
    10. {
    11. setTrackerMode(ActiveOnly);
    12. }
    13. };
    14. #endif
    15.  
    16. //MyWidget.cpp
    17.  
    18. void MyWidget::setAxis(){
    19. MyPlot * myPlot = new MyPlot();
    20. myPlot->changeAxis(curveNum, y); // calls MyPlot
    21.  
    22. myPlot->replot(); // after every thing has been called and the y axes have been set, I replot.
    23. }
    24.  
    25. //I declare myZoomer in myPlot
    26. #include "MyZoomer.h"
    27.  
    28. class MyPlot : public QwtPlot
    29. {
    30. CurveAttrib ** curves;
    31. public:
    32. MyPlot(){
    33. myZoomer[0] = new MyZoomer(QwtPlot::xBottom, QwtPlot::yLeft, this->canvas());
    34. myZoomer[1] = new MyZoomer(QwtPlot::xBottom, QwtPlot::yRight, this->canvas());
    35. enableAxis(QwtPlot::yRight);
    36. }
    37. MyZoomer *myZoomer[2];
    38.  
    39. ....
    40.  
    41. void changeAxis(int curvNum, int axis){
    42. curves[curvNum]->axis(axis); // the function 'axis' calls another function in
    43. // CurveAttrib which assigns the axis
    44. curves[curvNum]->curve->attach(this);
    45.  
    46.  
    47. // here I make it so that the zoomer fits to the new data points,
    48. // this happens before I replot so it looks right,
    49. // the problem is that when I zoom the axis don't rescale,
    50. // I don't know where to set auto scale for the y axes AFTER I zoom
    51. myZoomer[0]->setZoomBase();
    52. myZoomer[1]->setZoomBase();
    53. this->setAxisAutoScale(yLeft);
    54. this->setAxisAutoScale(yRight);
    55. this->setAxisAutoScale(xBottom);
    56. }
    57. };
    58. #endif
    59.  
    60. class CurveAttrib{
    61. ......
    62. void axis(int axis){ /// sets y-left or y-right
    63. curve->detach();
    64. if (axis == 1){
    65. curve->setYAxis(QwtPlot::yRight);
    66. }else{
    67. curve->setYAxis(QwtPlot::yLeft);
    68. }
    69. }
    To copy to clipboard, switch view to plain text mode 

    Hopefully this makes some sense. I think my problem is that I don't know where to put the setAutoScale so that it happens every time I zoom in or out. Any ideas?

    Thanks!

  5. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: Zoom on only one axis?

    Hard to understand your English - so I'm not completely sure what you want. Is it that you want to zoom the x scales only ?

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

    Default Re: Zoom on only one axis?

    Quote Originally Posted by kja View Post
    That seems like it might work, but I'm having a hard time actually understanding where the code goes when I use my zoomer.
    there is a signal emitted after a zoom has been performed: void QwtPlotZoomer::zoomed (const QwtDoubleRect & rect ). Connect this signal with a custom slot in your application. there you can set the y-axis of your zoomer to autoscale.

  7. The following user says thank you to FelixB for this useful post:

    kja (7th December 2010)

  8. #7
    Join Date
    Oct 2010
    Posts
    58
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26

    Default Re: Zoom on only one axis?

    so I set up the zoomed signal but I'm getting the error
    Qobject::connect: No such signal QwtPlotZoomer:: zoomed(const QwtDoubleRect &) in myplot.h
    I made the custom slot and added Q_OBJECT to the file. The Moc file is generated.

    Qt Code:
    1. class MyPlot : public QwtPlot
    2. {
    3. Q_OBJECT
    4. CurveAttrib ** curves;
    5. public:
    6. MyPlot(){
    7. myZoomer[0] = new MyZoomer(QwtPlot::xBottom, 0, this->canvas());
    8. myZoomer[1] = new MyZoomer(QwtPlot::xBottom, 0, this->canvas());
    9.  
    10. setAxisScaleDraw(QwtPlot::xBottom, new XaxisDates);
    11. enableAxis(QwtPlot::yRight);
    12.  
    13. connect(myZoomer[0], SIGNAL(zoomed(const QwtDoubleRect &)), this, SLOT(whenZoom(const QwtDoubleRect &)));
    14.  
    15. }
    16. public Q_SLOTS:
    17. void whenZoom(const QwtDoubleRect &);
    18. public:
    19. MyZoomer *myZoomer[2];
    20. }
    To copy to clipboard, switch view to plain text mode 

    Is my syntax incorrect?

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

    Default Re: Zoom on only one axis?

    maybe something has changed in Qwt 6.0... this is working for me:

    Qt Code:
    1. connect(m_zoomerBL, SIGNAL(zoomed(const QwtDoubleRect &)), this, SLOT(updatePlots()) );
    To copy to clipboard, switch view to plain text mode 

  10. #9
    Join Date
    Oct 2010
    Posts
    58
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26

    Default Re: Zoom on only one axis?

    hmmm that's strange. I have no idea why I can't set up the connection. All of my other slots and signals work as they should, but ever time I try to use the zoomed signal I get the error 'no such connection' any one know what might be happening?

    Qt Code:
    1. connect (newzoom, SIGNAL(zoomed(const QwtDoubleRect &)), this, SLOT(newzoomer()));
    To copy to clipboard, switch view to plain text mode 

  11. #10
    Join Date
    Oct 2010
    Posts
    58
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26

    Default Re: Zoom on only one axis?

    I mean the error is actually "no such signal QwtPlotZoomer:: zoomed(const QwtDoubleRect &) in myplot.h"

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

    Default Re: Zoom on only one axis?

    wait... your definition of MyZoomer is in myplot.cpp, right? Maybe it must be defined in myplot.h? then the signal should be available in myplot.h...

  13. #12
    Join Date
    Oct 2010
    Posts
    58
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26

    Default Re: Zoom on only one axis?

    Thanks for the help FelixB,

    I tried moving the MyZoomer definition into myplot.h but I still get the same problem. It is strange because, as I said before, I have different singles from push puttons and qActions that are implemented in the same way as myZoomer's connection and they all work fine.

  14. #13
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: Zoom on only one axis?

    What about reading the documentation of Qwt 6 concerning the signature of QwtPlotZoomer::zoomed.

    Uwe

    PS: These type of threads are really hard to accept

Similar Threads

  1. Replies: 0
    Last Post: 9th August 2010, 11:46
  2. QWTPlot Zoom: cannot zoom negative value
    By jwieland in forum Qwt
    Replies: 0
    Last Post: 8th January 2010, 17:16
  3. Replies: 1
    Last Post: 16th November 2009, 06:25
  4. How to zoom in negative X and Y axis ?
    By biplab777 in forum Qwt
    Replies: 0
    Last Post: 9th June 2009, 11:55
  5. QGLWidget with text - zoom in / zoom out
    By h123 in forum Qt Programming
    Replies: 1
    Last Post: 16th November 2008, 10:56

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.