Results 1 to 4 of 4

Thread: QwtRescaler issue

  1. #1
    Join Date
    Apr 2013
    Posts
    63
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default QwtRescaler issue

    Hi,
    I posted this question as a replay to an old post. But there was no response. So posting new thread.
    I have inherited a class from QWTPlot and inside that I am calling
    Qt Code:
    1. QwtPlotRescaler rescaler(canvas());
    2. rescaler.setReferenceAxis(QwtPlot::xBottom);
    3. rescaler.setAspectRatio(QwtPlot::yLeft, 1.0);
    To copy to clipboard, switch view to plain text mode 
    My requirement is
    Initially my plot's X Y axes have same range, 0 to 1. But My data changes such that y axis range is -1 to 1 (this is only an example. The range change dynamically to -0.5 to 1.0, -0.2 to 1.5 etc ) keeping x axis range 0 to 1 and now my aspect ratio is changed which I don't want. I expected that the rescaler will make the plot rectangle of height=2*width to maintain aspect ratio. But it remains as a square and Y axis got shrunk. I need to dynamically change the Y axis range and need to maintain aspect ratio. What I need to do? I also need to maintain aspect ratio when user shrinks the parent window.

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

    Default Re: QwtRescaler issue

    The rescaler automatically adjusts the scales to resize events of the canvas. When changing the scale range of the reference axis you have to call QwtPlotRescaler::rescale() manually.

    Qt Code:
    1. Plot::Plot()
    2. {
    3. m_rescaler = new QwtPlotRescaler( canvas(), QwtPlot::xBottom, QwtPlotRescaler::Fixed );
    4. m_rescaler->setAspectRatio( QwtPlot::yLeft, 1.0 );
    5. }
    To copy to clipboard, switch view to plain text mode 

    and something like this:

    Qt Code:
    1. void Plot::expandReferenceAxis()
    2. {
    3. const QwtInterval interval = axisInterval( m_rescaler->referenceAxis() );
    4. plot->setAxisScale( m_rescaler->referenceAxis(), interval.minValue(), interval.minValue() + interval.width() + 1000 );
    5. plot->updateAxes(); // no relot to avoid flickering
    6.  
    7. m_rescaler->rescale(); // now sync the y axis + replot
    8. }
    To copy to clipboard, switch view to plain text mode 

    It might be possible to connect QwtPlotRescaler::rescale() to QwtScaleWidget::scaleDivChanged() signal of the reference axis - but I have not tried it.

    Uwe

  3. #3
    Join Date
    Apr 2013
    Posts
    63
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtRescaler issue

    Thanks Uwe,
    I will try this. One question: what is 1000 hard coded in expandReferenceAxis ?
    What I am trying is to achieve is a circle looks like a circle. I would like this happen even when user zoom with zoomer.

    I have one more requirement which I am not able to figure out
    When I change my data I don't want to change my current zoom reached by zoomer and/or magnifier. But I want to reset zoomer, so that I can Fit the view to new data (when a button clicked) with zoomer::zoom(0) call. How to achieve this?
    Last edited by mqt; 30th August 2013 at 11:20.

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

    Default Re: QwtRescaler issue

    Quote Originally Posted by mqt View Post
    One question: what is 1000 hard coded in expandReferenceAxis ?
    Just an example that modifies the scale somehow.

    What I am trying is to achieve is a circle looks like a circle. I would like this happen even when user zoom with zoomer.
    Then you should overload QwtPlotZoomer::rescale() ( have a look at the implementation ). Set the x axis like in the default implementation, but the y axis like in my code snippet above.

    When I change my data I don't want to change my current zoom reached by zoomer and/or magnifier. But I want to reset zoomer, so that I can Fit the view to new data (when a button clicked) with zoomer::zoom(0) call.
    Sounds like you want to modify the first entry of the zoom stack. See QwtPlotZoomer::setZoomStack() + QwtPlotZoomer::zoomStack().

    Uwe

  5. The following user says thank you to Uwe for this useful post:

    mqt (1st September 2013)

Similar Threads

  1. Qt 5.0.1 Issue
    By kiboi in forum Qt-based Software
    Replies: 0
    Last Post: 22nd March 2013, 05:22
  2. XML issue
    By jbpvr in forum Qt Programming
    Replies: 1
    Last Post: 25th August 2008, 13:01
  3. UI issue.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 13th August 2008, 11:41
  4. ui_....h issue
    By stevey in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 04:54
  5. qt3 to qt4 - uic issue
    By hvengel in forum Qt Programming
    Replies: 10
    Last Post: 4th March 2007, 02:59

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.