Results 1 to 3 of 3

Thread: Realtime example ScrollZoomer and QwtPlotItem::Margins flag

  1. #1
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Realtime example ScrollZoomer and QwtPlotItem::Margins flag

    Hello,

    I'm currently experimenting with the ScrollZoomer class provided by Qwt realtime example. I want to add some margin between the trace and the canvas, so I derived a class PlotCurve from QwtPlotCurve setting the Margins attribute and overriding getCanvasMarginHint():
    Qt Code:
    1. PlotCurve::PlotCurve(const QString& name)
    2. : QwtPlotCurve(name)
    3. {
    4. setItemAttribute(Margins, true);
    5. setCurveAttribute(Fitted, false);
    6. }
    7.  
    8. PlotCurve::~PlotCurve()
    9. {
    10. }
    11.  
    12. void PlotCurve::getCanvasMarginHint(const QwtScaleMap &xMap,
    13. const QwtScaleMap &yMap,
    14. const QRectF &canvasRect,
    15. double &left,
    16. double &top,
    17. double &right,
    18. double &bottom
    19. )const
    20. {
    21. left = 5.0;
    22. right = 0.0;
    23. top = 20;
    24. bottom = 10.0;
    25. }
    To copy to clipboard, switch view to plain text mode 
    When creating a trace in the X range [0,100] and starting to zoom into this trace I observed that the axis scales ran into the area occupied by the vertical slider. This has the bad side effect that I cannot zoom around the last trace points.

    To check if this also happens with the realtime code, I used the PlotCurve class above also in the realtime example and changed the realtime example X range from 1000 to 100. Moreover I changed the application style to cleanlooks, so that the misalignment is better visible. Here are 2 screenshots. The first one shows the application where everything is ok while the second one shows the failure occurring after the next zoom step.
    Attachment 10780 Attachment 10781
    Going up the zoom stack by 1 (back to the previously state where everything was ok) we observe that it is failing now too:
    zoom_fail_after_step_back.png
    I even tried setting left, top, right and bottom all to 0. The result is similar. Only when resetting the Margins flag to false in PlotCurve zooming behaves as expected. Note that it also works with a range of 1000 (both in realtime example and my application).

    Any ideas how to fix this?

    Thanks for any suggestions
    ars

    Edit 1: Setting top and right in getCanvasMarginHint() to values >= scrollbar extent prevents the scales from running into the scrollbar area.
    Last edited by ars; 3rd December 2014 at 17:40. Reason: Additional information

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

    Default Re: Realtime example ScrollZoomer and QwtPlotItem::Margins flag

    Quote Originally Posted by ars View Post
    I'm currently experimenting with the ScrollZoomer class provided by Qwt realtime example. I want to add some margin between the trace and the canvas, so I derived a class PlotCurve from QwtPlotCurve setting the Margins attribute and overriding getCanvasMarginHint()
    As the scroll zoomer also manipulates the canvas margin this won't work. But using the Margins attribute ( necessary for bar charts, where the bar needs extra space ) is probably not want you want to do.

    Instead I guess this is your code:

    Qt Code:
    1. plot->plotLayout()->setCanvasMargin( ... );
    To copy to clipboard, switch view to plain text mode 
    You have to do it before the scroll zoomer gets created, as the zoomer modifies the margins by adding/subtracting the scroll bar extent from the current margins.

    Uwe

  3. #3
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Realtime example ScrollZoomer and QwtPlotItem::Margins flag

    Hello Uwe,

    thanks for your reply. It's now working (with some additional changes specific to my application) as I've expected.

    Best regards
    ars

Similar Threads

  1. QwtPlotItem copy, or better solution
    By Asting in forum Qwt
    Replies: 2
    Last Post: 14th June 2014, 23:25
  2. Replies: 1
    Last Post: 16th December 2013, 20:30
  3. Replies: 0
    Last Post: 18th January 2011, 02:19
  4. ScrollZoomer: ScrollbarAlwaysOn
    By FelixB in forum Qwt
    Replies: 0
    Last Post: 14th October 2010, 16:30
  5. ScrollZoomer not working properly..
    By Raghaw in forum Qwt
    Replies: 1
    Last Post: 30th October 2009, 06:51

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.