Results 1 to 4 of 4

Thread: How to get a fixed stepSize of AxisScale even after zooming

  1. #1
    Join Date
    Jan 2014
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default How to get a fixed stepSize of AxisScale even after zooming

    Hello,

    I want to define a fixed step size for my x-scale (step=1). I can do this by using setAxisScale() method. But after zooming it's lost.
    Here is my example code:

    Qt Code:
    1. //create a plot
    2. QwtPlot plot;
    3.  
    4. //create a curve
    5. double x[] = {0,1,2,3,4,5,6,7,8,9,10};
    6. double y[] = {1,2,3,2,1,0,1,2,3,2,1};;
    7. curve.setRawSamples(x, y, 11);
    8. curve.attach(&plot);
    9.  
    10. //create zoom
    11. QwtPlotMagnifier zoom = QwtPlotMagnifier(plot.canvas());
    12. zoom.setAxisEnabled(QwtPlot::xBottom,true);
    13.  
    14. //set scale
    15. plot.setAxisScale(QwtPlot::xBottom,0,10,1);
    16.  
    17. //show plot
    18. plot.show();
    To copy to clipboard, switch view to plain text mode 

    What I want:
    - fixed major ticks with a step=1, independant if I zoomed in or zoomed out

    Is there an easy way to do that with just calling a method?
    If not, how can I get around this the best way? Reimplementing ScaleEngine?

    regards
    Johannes

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

    Default Re: How to get a fixed stepSize of AxisScale even after zooming

    Do this....

    connect(((QObject*)plot->axisWidget(QwtPlot::xBottom)) , SIGNAL(scaleDivChanged () ), this, SLOT(scaleDivChangedSlot () ));


    implement the slot...

    void scaleDivChangedSlot ()
    {
    //restore the scale to what ever you want
    }

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get a fixed stepSize of AxisScale even after zooming

    Quote Originally Posted by beckjoh View Post
    Reimplementing ScaleEngine?
    Yes - this is probably better, than calculating a scale you don't want first - fixing it later.

    Simply overload QwtLinearScaleEngine::divideScale() - should be a couple of lines only.

    Uwe

  4. #4
    Join Date
    Jan 2014
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get a fixed stepSize of AxisScale even after zooming

    Thank you both for your answers!

    First attempt i tried and it works, but I will try Uwe's solution too.

    Johannes

Similar Threads

  1. Replies: 7
    Last Post: 18th November 2016, 11:48
  2. Replies: 2
    Last Post: 20th February 2012, 07:30
  3. zooming only x
    By mastupristi in forum Qwt
    Replies: 1
    Last Post: 7th May 2009, 08:23
  4. Zooming..
    By chethana in forum Qt Programming
    Replies: 7
    Last Post: 10th October 2007, 08:17
  5. Zooming in but not out
    By nitriles in forum Qt Programming
    Replies: 1
    Last Post: 5th October 2007, 08:54

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.