Results 1 to 14 of 14

Thread: Updating and Zooming Plot, that is frequently filled with new Data

  1. #1
    Join Date
    Sep 2011
    Posts
    14
    Thanks
    5
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Updating and Zooming Plot, that is frequently filled with new Data

    Hello Qt and Qwt Folks!

    This is my 1st post. Sorry if this topic was already handled here in the forum, but i have found nothing.
    My English is not perfect, sorry for that.

    Let's get to my topic...
    My problem is, that i want to plot a curve, that is updated with data from the database every 500ms. In the past i did this by doing setSamples(x_vals, y_vals); and after that replot(); inside my class that inherits QwtPlot.
    That worked fine, but now I also want to zoom. Zooming in by rubberband and mousewheel, zooming out by right-clicking. So i implemented a QwtPlotZoomer and installed to my QwtPlot.
    And it works fine... as long as you don't update the Plot! It zooms in for a tiny piece of a second and then immediatley zooms out again, after replot() is called.

    So, my idea was to just add data to my plot and let it handle update and zooming functionality itself.
    But I'm just not getting it, how to do that... i tried setAutoReplot(true); ... same problem as before.

    I hope someone can help me. I'm stuck for days, trying out stuff from the qwt examples. trying out setting any scales or scaledraws or scaledivs. This cannot be that difficult, can it?


    Thanks in advance!

  2. The following user says thank you to entonjackson for this useful post:


  3. #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: Updating and Zooming Plot, that is frequently filled with new Data

    show the code where you add the data, please.

    you probably set the axes ranges there...

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


  5. #3
    Join Date
    Sep 2011
    Posts
    14
    Thanks
    5
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating and Zooming Plot, that is frequently filled with new Data

    //getting new data from database and store it on QVector<double> m_xVal and m_yVal

    m_curve->setSamples(m_xVal, m_yVal);

    setAxisScale(xBottom, m_xVal.first(), m_xVal.last());
    setAxisScale(yLeft, yMin, yMax);

    replot();
    Last edited by entonjackson; 7th September 2011 at 09:58.

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


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

    Default Re: Updating and Zooming Plot, that is frequently filled with new Data

    do you know what "setAxisScale()" does?

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


  9. #5
    Join Date
    Sep 2011
    Posts
    14
    Thanks
    5
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating and Zooming Plot, that is frequently filled with new Data

    No I don't. I try to understand what the great "Documentation" tries to tell me by saying the following about this method:

    "Disable autoscaling and specify a fixed scale for a selected axis."

    Maybe you can explain it to me in more than 1 sentence...
    I understand that I'm disabling autoscaling, but I know that I'm setting the scale from update to update, so this cannot be the problem.
    I'm specifying a fixed scale... ok... isn't that what i want?

    Thank you
    Last edited by entonjackson; 7th September 2011 at 11:10.

  10. The following user says thank you to entonjackson for this useful post:


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

    Default Re: Updating and Zooming Plot, that is frequently filled with new Data

    you set the range of the scales with that method. e.g. "setAxisScales(xBottom,0,10)" makes the x-axis have the range (0-10).

    When you zoomed in before, you have a different scale, e.g. (4-6). So, after "setAxisScale", "replot" makes your plot zooming out because you set the scales to a larger interval.

  12. The following 2 users say thank you to FelixB for this useful post:

    entonjackson (8th September 2011)

  13. #7
    Join Date
    Sep 2011
    Posts
    14
    Thanks
    5
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating and Zooming Plot, that is frequently filled with new Data

    Thanks! That helped a lot!

    But I have another Problem.
    I made an own QwtPlotZoomer Class that inherits it. i have overriden widgetWheelEvent() signal and check if delta is > or < 0. if so, i zoom(1) or zoom(-1);
    if i zoom in, it zooms to a y-scale from 0 to 1000 and won't ever zoom to another scale after that. What am I doing wrong?

  14. The following user says thank you to entonjackson for this useful post:


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

    Default Re: Updating and Zooming Plot, that is frequently filled with new Data

    you probably have a "setAxisScale(yLeft,0,1000)" somewhere in your code... or maybe you do the zooming wrong. show some code, please...

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


  17. #9
    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: Updating and Zooming Plot, that is frequently filled with new Data

    Quote Originally Posted by entonjackson View Post
    I made an own QwtPlotZoomer Class that inherits it. i have overriden widgetWheelEvent() signal ...
    You probably want to use QwtPlotMagnifier.

    Uwe

  18. The following 2 users say thank you to Uwe for this useful post:

    entonjackson (9th September 2011)

  19. #10
    Join Date
    Sep 2011
    Posts
    14
    Thanks
    5
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating and Zooming Plot, that is frequently filled with new Data

    That seems to solve my problem...
    now, inside my QwtPlot derived Class Constructur i do...


    QwtPlotMagnifier magnifier(canvas());
    magnifier.setAxisEnabled(xBottom, true);
    magnifier.setAxisEnabled(yLeft, true);


    Now it zooms automatically by scrolling... but!
    I have a QwtScaleDraw class called TimeAxis... that is formatting double values into Timestamps.
    And no matter if i zoom out or in, it zooms always to 01.01.1970 on the x axis. Why is that?

    Any suggestions?

    Edit: This must be a basic problem, because on right-clicks, i do zoom(0); after that it zooms also to 01.01.1970... so I probably must tell my zoomer and magnifier what the base rect is, or something. right?

    Edit: Sorry my fault. There was an active mousewheel listener, that zoomed into 01.01.1970, that i have commented out. now it works!

    Vielen Dank! Felix und Uwe
    Last edited by entonjackson; 9th September 2011 at 11:27.

  20. The following user says thank you to entonjackson for this useful post:


  21. #11
    Join Date
    Sep 2011
    Posts
    14
    Thanks
    5
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating and Zooming Plot, that is frequently filled with new Data

    There's an annoying autozoom functionality implemented in the QwtPlotZoomer, that enables autozooming after right-click and moving Mouse vertically up and down.
    I don't know how to disable that... can anybody please tell me?

  22. The following user says thank you to entonjackson for this useful post:


  23. #12
    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: Updating and Zooming Plot, that is frequently filled with new Data

    Subclass Qwt<Plot>Magnifier and overwrite
    Qt Code:
    1. virtual void QwtMagnifier::widgetMouseMoveEvent(QMouseEvent*)
    To copy to clipboard, switch view to plain text mode 
    That should do the trick.

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


  25. #13
    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: Updating and Zooming Plot, that is frequently filled with new Data

    Or:

    Qt Code:
    1. magnifier->setMouseButton( Qt::NoButton );
    To copy to clipboard, switch view to plain text mode 
    Uwe

  26. The following 2 users say thank you to Uwe for this useful post:

    entonjackson (20th September 2011)

  27. #14
    Join Date
    Sep 2011
    Posts
    14
    Thanks
    5
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating and Zooming Plot, that is frequently filled with new Data

    Thank you!

    That helped, but the problem is: I don't understand it.
    setMouseButton seems to be a method that sets functionality to some some mousebuttons. above you simply said setMouseButton(Qt::NoButton);
    Why is it setting the right-click autozooming thing to "NoButton".
    It could be any functionality of the magnifier, right?

    I hope you understand my question, although it's a little confusing...
    Thanks in advance

  28. The following user says thank you to entonjackson for this useful post:


Similar Threads

  1. Replies: 6
    Last Post: 7th January 2013, 17:30
  2. QwtPlotZoomer zooming off the plot canvas
    By BettaUseYoNikes in forum Qwt
    Replies: 1
    Last Post: 26th June 2011, 12:38
  3. Tree widget not updating the data
    By phillip_Qt in forum Qt Programming
    Replies: 2
    Last Post: 17th November 2009, 08:00
  4. Qtreewidget not updating data
    By phillip_Qt in forum Qt Programming
    Replies: 2
    Last Post: 12th November 2009, 05:10
  5. confusion with a STATEMENT used frequently
    By salmanmanekia in forum Newbie
    Replies: 3
    Last Post: 11th June 2008, 21: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.