Results 1 to 5 of 5

Thread: Zoom in real time

  1. #1
    Join Date
    Jan 2012
    Posts
    23
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Zoom in real time

    Hello. I have a plot, which is updated on a timer. New points are taken from the database.
    New points are added to the chart every 3 seconds and the plot is redrawn.
    Qt Code:
    1. curv1 = new QwtPlotCurve();
    2. curv1->setPen(QPen(Qt::red));
    3. curv1->setAxes(xb,yl);
    4. myPlot->enableAxis(yl);
    5. curv1->attach(myPlot);
    6.  
    7. timerUpdPlot = new QTimer;
    8. connect (timerUpdPlot, SIGNAL(timeout()), SLOT(realTimePoints()));
    9. timerUpdPlot->start(3000);
    10. realTimePoints();
    To copy to clipboard, switch view to plain text mode 

    Curve is connected to zoomer
    Qt Code:
    1. d_zoomer[0] = new Zoomer( xb, yl, myPlot->canvas());
    2. d_zoomer[0]->setRubberBand(QwtPicker::RectRubberBand);
    3. d_zoomer[0]->setRubberBandPen(QColor(Qt::white));
    4. d_zoomer[0]->setTrackerPen(QColor(Qt::white));
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void TrendTop::realTimePoints()
    2. {
    3. if (!db.open()) {
    4. CreateConnection();
    5. }
    6.  
    7. if (db.isOpen())
    8. {
    9. QSqlQuery query(db);
    10. query.exec("SELECT tm, val FROM currstamp where id = 1136");
    11.  
    12. if (query.next())
    13. {
    14. osX = query.value(0).toUInt();
    15. osY = query.value(1).toDouble();
    16. }
    17.  
    18. X++;
    19. vectX.append(X);
    20. vectY.append(osY);
    21.  
    22. curv1->setSamples(vectX,vectY);
    23. myPlot->replot();
    24.  
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

    1.JPG

    But when I click zoom, plot itself is scaled to the very first point on the graph.
    2.jpg

    Although, I must first select the area that I want to scale.

    Slot is invoked by pressing the zoom:
    Qt Code:
    1. void TrendTop::enableZoomMode(bool on)
    2. {
    3. d_panner->setEnabled(on);
    4.  
    5. d_zoomer[0]->setEnabled(on);
    6. d_zoomer[0]->zoom(0);
    7.  
    8. d_zoomer1[0]->setEnabled(on);
    9. d_zoomer1[0]->zoom(0);
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    What am I doing wrong?
    Last edited by oddytz1989; 6th February 2012 at 11:50.

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

    Default Re: Zoom in real time

    you have to call "setZoomBase" after adding new points

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

    oddytz1989 (6th February 2012)

  4. #3
    Join Date
    Jan 2012
    Posts
    23
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Zoom in real time

    Thanks. I added:
    Qt Code:
    1. void TrendTop::enableZoomMode(bool on)
    2. {
    3. d_panner->setEnabled(on);
    4.  
    5. d_zoomer[0]->setEnabled(on);
    6. d_zoomer[0]->setZoomBase(on);
    7. d_zoomer[0]->zoom(0);
    8.  
    9. d_zoomer1[0]->setEnabled(on);
    10. d_zoomer1[0]->zoom(0);
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 
    The zoom works fine.

    But there is another question.
    On the plot continues to add new points.
    But when I turn off the zoom, plot is redrawn back. But while the plot has been zoomed, to plot new points added. A zoomer returns to the state when the points did not exist. And I have to manually scroll right to the new points.
    How to make the graph is redrawn with the newly added points?

  5. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Zoom in real time

    Qt Code:
    1. plot->setAxisAutoScale( QwtPlot::xBottom );
    2. plot->setAxisAutoScale( QwtPlot::yLeft );
    3. plot->updateAxes();
    4.  
    5. zoomer->setZoomBase( true );
    To copy to clipboard, switch view to plain text mode 
    this will update axes to include new points and update zoomer base (zoom out).

  6. The following user says thank you to Spitfire for this useful post:

    oddytz1989 (7th February 2012)

  7. #5
    Join Date
    Jan 2012
    Posts
    23
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Zoom in real time

    Big Thanks!

Similar Threads

  1. Real time QT application?
    By marc2050 in forum Newbie
    Replies: 1
    Last Post: 8th June 2011, 06:08
  2. Real time rendering
    By kaszewczyk in forum Newbie
    Replies: 1
    Last Post: 7th July 2010, 17:26
  3. real time plotting
    By agostain in forum Qwt
    Replies: 0
    Last Post: 10th August 2009, 10:47
  4. real time plotting
    By gyre in forum Qwt
    Replies: 4
    Last Post: 11th December 2007, 16:13
  5. Rendering real time video using SDL and QT
    By venk2ksubbu in forum Newbie
    Replies: 4
    Last Post: 13th September 2007, 15:20

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.