Results 1 to 6 of 6

Thread: QwtPlot how to save/restore zoom settings

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2017
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default QwtPlot how to save/restore zoom settings

    Hello, I use QwtPlot with one QwtPlotCurve, xBotton, yRight axes; I would like to save and restore the plot's zoom settings (when user exist/when user restarts the program). The idea is to get the user back to the same looking plot. Can anyone point me in the right direction?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QwtPlot how to save/restore zoom settings

    Store the x and y extents in member variables of whatever widget holds your plot, and use QSettings as a way to store them persistently on disk. Override the widget's showEvent() and closeEvent() methods. In showEvent(), read the settings in and set the zoom extents. In closeEvent(), save the settings.

    If the current zoom extents are accessible from QwtPlot, then you may not need the member variables. Just read or write them directly from the plot on load and save.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Nov 2017
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QwtPlot how to save/restore zoom settings

    Thanks for the response.
    I looked through all relevant classes APIs starting with QwtPlot, I just can't find the API to get/set zoom extents.. (starting point/ending value for each x/y axis or equivalent data)

  4. #4
    Join Date
    Nov 2017
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QwtPlot how to save/restore zoom settings

    A solution that worked for me was saving "zoomRect" and then restoring using "setZoomRect"
    Qt Code:
    1. QRectF zoomRect()
    2. {
    3. const QwtScaleDiv &xs = this->axisScaleDiv( QwtPlot::xBottom);
    4. const QwtScaleDiv &ys = this->axisScaleDiv( QwtPlot::yLeft );
    5. QRectF rect = QRectF( xs.lowerBound(), ys.lowerBound(), xs.range(), ys.range() );
    6. return rect;
    7. }
    8.  
    9. void setZoomRect(const QRectF& r)
    10. {
    11. d->zoomer->zoom(r);
    12. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QwtPlot how to save/restore zoom settings

    You don't need a zoomer to set the scale intervals - simply use setAxisScale or setAxisScaleDiv.

    Uwe

  6. #6
    Join Date
    Nov 2017
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QwtPlot how to save/restore zoom settings

    Thanks Uwe.
    now using:
    Qt Code:
    1. QRectF CGraph::zoomRect()
    2. {
    3. const QwtScaleDiv &xs = this->axisScaleDiv( QwtPlot::xBottom);
    4. const QwtScaleDiv &ys = this->axisScaleDiv( QwtPlot::yLeft );
    5. return QRectF( xs.lowerBound(), ys.lowerBound(), xs.range(), ys.range() );
    6. }
    7.  
    8. void CGraph::setZoomRect(const QRectF& r)
    9. {
    10. this->setAxisScale(QwtPlot::xBottom, r.left(), r.right());
    11. this->setAxisScale(QwtPlot::yLeft, r.top(), r.bottom());
    12. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Darent; 4th January 2021 at 19:05.

Similar Threads

  1. QScriptEngineDebugger save/restore breakpoints
    By Muts in forum Qt Programming
    Replies: 0
    Last Post: 26th February 2016, 15:37
  2. save and restore TreeWidgetItem
    By raj_iv in forum Newbie
    Replies: 3
    Last Post: 26th August 2011, 09:12
  3. QWTPlot Zoom: cannot zoom negative value
    By jwieland in forum Qwt
    Replies: 0
    Last Post: 8th January 2010, 17:16
  4. Save & Restore a selection in QTreeWidget
    By youkai in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2008, 20:54
  5. QPainter save() and restore()
    By babu198649 in forum Newbie
    Replies: 4
    Last Post: 28th July 2008, 10:22

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.