Results 1 to 5 of 5

Thread: Using a zoomer to generate horizontal scrolling without zoom

  1. #1
    Join Date
    Dec 2010
    Location
    Israel
    Posts
    90
    Thanks
    59
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Using a zoomer to generate horizontal scrolling without zoom

    I'm using QWT 6.0.0.0 RC5, QT 4.7.1.

    I'm trying to generate the effect of horizontal scrolling for my plot - the X scale will be Time so it should be growing horizontally.

    I saw a discussion in which it was advised to use the QwtPlotZoomer class, so right now I have a combination of the Oscilloscope and the Realtime examples.

    What I want to achieve is to update the scale to a new size, and then emulate a zoom that is set to the pre-defined original scale, and to the right part of the plot.

    Meaning, if my X scale is 10 seconds, and I'm rescaling it to 11, I want the displayed plot to start from 1 and the scrollbar to enable scrolling back to 0.

    How do I go about this? Also, if there's a better way of doing it, I'd be happy for some pointers.

    Optimally I would want to get rid of the UI functionality of the zoomer (the ability to select a zoom rectangle using the mouse) and just use the mechanism for the behind-the-scenes action.

    Thanks,
    Frankie

  2. #2
    Join Date
    Dec 2010
    Location
    Israel
    Posts
    90
    Thanks
    59
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using a zoomer to generate horizontal scrolling without zoom

    To clarify: I have the plot copied from the Oscilloscope sample, and the Zoomer classes copied from the Realtime sample.

    The changes:
    I've removed the Zoomer::rescale implementation calling QwtScaleDraw::setMinimumExtent with the calculated extent (since I wasn't sure how to calculate it with my plot).

    Here's MyPlot constructor:
    Qt Code:
    1. MyPlot::MyPlot(QWidget *parent):
    2. QwtPlot(parent),
    3. d_interval(0, 30),
    4. d_paintedPoints(0),
    5. d_timerId(-1)
    6. {
    7. d_directPainter = new QwtPlotDirectPainter();
    8.  
    9. setAutoReplot(false);
    10.  
    11. // We don't need the cache here
    12. canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
    13. //canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);
    14.  
    15.  
    16. #if defined(Q_WS_X11)
    17. // Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent
    18. // works on X11. This has a nice effect on the performance.
    19.  
    20. canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
    21. canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
    22. #endif
    23.  
    24. plotLayout()->setAlignCanvasToScales(true);
    25.  
    26. setAxisTitle(QwtPlot::xBottom, "Time [s]");
    27. setAxisTitle(QwtPlot::yLeft, "Temperature");
    28. setAxisScale(QwtPlot::xBottom, d_interval.minValue(), d_interval.maxValue());
    29. setAxisScale(QwtPlot::yLeft, -20, 20);
    30. QwtPlotGrid *grid = new QwtPlotGrid();
    31. grid->setPen(QPen(Qt::gray, 0.0, Qt::DotLine));
    32. grid->enableX(true);
    33. grid->enableXMin(true);
    34. grid->enableY(true);
    35. grid->enableYMin(false);
    36. grid->attach(this);
    37.  
    38. /*
    39. // Mark middle
    40.   d_origin = new QwtPlotMarker();
    41.   d_origin->setLineStyle(QwtPlotMarker::Cross);
    42.   // In future calculate middle
    43. d_origin->setValue(5, 0.0);
    44. d_origin->setLinePen(QPen(Qt::gray, 0.0, Qt::DashLine));
    45.   d_origin->attach(this);
    46. */
    47. d_curve = new QwtPlotCurve();
    48. d_curve->setStyle(QwtPlotCurve::Lines);
    49. d_curve->setPen(QPen(Qt::green));
    50. #if 1
    51. d_curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
    52. #endif
    53. #if 1
    54. d_curve->setPaintAttribute(QwtPlotCurve::ClipPolygons, false);
    55. #endif
    56. d_curve->setData(new CurveData());
    57. d_curve->attach(this);
    58.  
    59. d_zoomer = new Zoomer(canvas());
    60. d_zoomer->setRubberBandPen(QPen(Qt::red, 2, Qt::DotLine));
    61. d_zoomer->setTrackerPen(QPen(Qt::red));
    62. }
    To copy to clipboard, switch view to plain text mode 

    So assuming my X axis goes from 0 to 30 seconds - what I want to do is Zoom on the area of 1-31 seconds:
    1. The scale should grow to 0-31
    2. The scrollbar should become visible
    3. The plot should be "scrolled" to the rightmost part (meaning I could scroll back to the previous range of 0-30).

    I've added a PushButton to "advance" the plot. What it does is:

    Qt Code:
    1. // (my y-axis range is -20 to 20)
    2. QRectF newRect(1, -20, 30, 40);
    3. m_Plot->setZoomRect(newRect); // This calls: d_zoomer->zoom(newRect);
    To copy to clipboard, switch view to plain text mode 

    I've added a Before and After screenshots to show what happens after this code runs.
    Before:


    After:

    As you can see the horizontal scrollbar appears but it is disabled. Also the canvas has a small offset that wasn't present before.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,111
    Thanks
    290
    Thanked 844 Times in 831 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Using a zoomer to generate horizontal scrolling without zoom

    Why don't you simply use a QwtPlotPanner instead of trying to mangle the zoomer code to do the same thing? The panner is designed to move the canvas around without changing the zoom level.

    If you need to restrict the panning to one axis only, then you can derive from QwtPlotPanner and reimplement as required. I don't remember exactly which methods need to be changed, but it shouldn't be too hard to figure that out.

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

    frankiefrank (2nd January 2011)

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

    Default Re: Using a zoomer to generate horizontal scrolling without zoom

    Quote Originally Posted by frankiefrank View Post
    Meaning, if my X scale is 10 seconds, and I'm rescaling it to 11, I want the displayed plot to start from 1 and the scrollbar to enable scrolling back to 0.
    It's about connecting a QAbstractSlider or QwtAbstractSlider to QwtPlot::setAxisScale.

    This has nothing to do with the ScrollZoomer class from the realtime example - beside, that it also connects a QAbstractSlider ( scroll bar ) with QwtPlot::setAxisScale.

    Uwe

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

    frankiefrank (2nd January 2011)

  7. #5
    Join Date
    Dec 2010
    Location
    Israel
    Posts
    90
    Thanks
    59
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using a zoomer to generate horizontal scrolling without zoom

    Thanks for the replies, most of the threads I found on this subject were answered by referring to the realtime example, so I followed that. Now I understand what was the main point (the slider->setaxisscale connection)

    Is there an example using the panner?

    By the way I managed to correct my original code by calling setZoomBase() after changing the axis scale.

Similar Threads

  1. Replies: 1
    Last Post: 7th December 2010, 06:49
  2. how to zoom in zoom out tableview in QT programming?
    By nageshvk in forum Qt Programming
    Replies: 0
    Last Post: 27th October 2010, 05:05
  3. Horizontal Scrolling QListWidget
    By bl1nk in forum Qt Programming
    Replies: 1
    Last Post: 17th July 2010, 08:44
  4. How to get vertical/horizontal zoom box?
    By knicewar in forum Qwt
    Replies: 3
    Last Post: 23rd March 2010, 04:09
  5. Replies: 1
    Last Post: 16th November 2009, 05:25

Tags for this Thread

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.