Results 1 to 9 of 9

Thread: How to plot the real time data in qwtplot while erasing fixed-width old data?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2020
    Location
    HongKong
    Posts
    4
    Qt products
    Qt4 Qt5 Qt/Embedded

    Question Re: How to plot the real time data in qwtplot while erasing fixed-width old data?

    Quote Originally Posted by Uwe View Post
    QWidget does not offer to "erase" something - all you can do is to redraw from scratch. This is why QwtPlotDirectPainter is useful - it at least allows to draw on top of something existing.

    Uwe
    Another way to achieve the effect I want,and in this way, the CPU usage is also very small,but need to write a lot of code,use the most primitive QPainter , not as concise as the qwt.The code snippet is as follows:
    Qt Code:
    1. void Mywidget::paintEvent(QPaintEvent* event)
    2. {
    3. QPainter painter(this);
    4. painter.drawPixmap(0,0,m_gridPixmap);//paint grid backgroup pixmap
    5. painter.drawPixmap(0,0,m_curvePixmap);//paint curve pixmap on the top, and set QPainter::CompositionMode_Source mode when paint m_curvePixmap
    6. painter.end();
    7. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void Mywidget::updateCurvePixmap()
    2. {
    3. QPainter painter;
    4. painter.begin(&m_curvePixmap);
    5. painter.setCompositionMode(QPainter::CompositionMode_Source);
    6.  
    7. //Calculate the current 12 refreshed area first,and fill transparent
    8. for(int i = 0; i < 12;i++)
    9. {
    10. QRect rect;//The calculation process is omitted here!!!
    11. painter.fillRect(rect,Qt::transparent);
    12.  
    13. //Plot newly added data points
    14. QPolygonF points;//The process of filling points is omitted!!!
    15. painter.drawPoints(points);
    16. }
    17. painter.end();
    18.  
    19. //At this point, the new data point is successfully partial updated on the m_curvePixmap,Partial refresh widget
    20. QRegion region;//save all need updated area
    21. for(int i = 0; i < 12;i++)
    22. {
    23. QRect rect;//The calculation process is omitted here!!!
    24. region += rect;
    25. }
    26. update(region );
    27. }
    To copy to clipboard, switch view to plain text mode 
    Refer to this example:https://doc.qt.io/qt-5/qtwidgets-pai...n-example.html,
    Used this class method:QPainter::setCompositionMode.

    In order to achieve the effect I want, is this the only way?
    Last edited by lockdown; 10th May 2020 at 17:19.

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

    Default Re: How to plot the real time data in qwtplot while erasing fixed-width old data?

    Guess what you mean by this code snippet is that you draw each curve to its own pixmap first and the plot is done finally by drawing the pixmaps.
    Then you would have only one drawPolyline call, when only one curve has changed.
    Of course the code as being posted is not even close to what needs to be done in reality - but the idea is understood.

    So your code will have a positive effect, when having several curves, that are updated on different intervals - but it won't help for a situation with one curve and many points.

    Uwe

  3. #3
    Join Date
    May 2020
    Location
    HongKong
    Posts
    4
    Qt products
    Qt4 Qt5 Qt/Embedded

    Default Re: How to plot the real time data in qwtplot while erasing fixed-width old data?

    Quote Originally Posted by Uwe View Post
    Guess what you mean by this code snippet is that you draw each curve to its own pixmap first and the plot is done finally by drawing the pixmaps.
    Then you would have only one drawPolyline call, when only one curve has changed.
    Of course the code as being posted is not even close to what needs to be done in reality - but the idea is understood.

    So your code will have a positive effect, when having several curves, that are updated on different intervals - but it won't help for a situation with one curve and many points.

    Uwe
    All curves plot in the only m_curvePixmap,I update the code snippet in the previous reply. All curves partial update at the same time ,update every 30ms.

    The original code looks too complicated,I just want to try to modify it as simple as the qwt.

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

    Default Re: How to plot the real time data in qwtplot while erasing fixed-width old data?

    Quote Originally Posted by lockdown View Post
    All curves plot in the only m_curvePixmap,....
    Then your code does not make any sense.

    Uwe

  5. #5
    Join Date
    May 2020
    Location
    HongKong
    Posts
    4
    Qt products
    Qt4 Qt5 Qt/Embedded

    Default Re: How to plot the real time data in qwtplot while erasing fixed-width old data?

    Quote Originally Posted by Uwe View Post
    Then your code does not make any sense.

    Uwe
    I have renewed.Thanks for the quick reply!

    What I don’t understand is why these my two methods are so different, why the CPU consumption is so different? Looks like they are doing the same partial refresh.

    Maybe as you said:QWidget does not offer to "erase" something - all you can do is to redraw from scratch.

  6. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: How to plot the real time data in qwtplot while erasing fixed-width old data?

    Quote Originally Posted by lockdown View Post
    What I don’t understand is why these my two methods are so different, why the CPU consumption is so different?
    Hard to say what your code is doing as the code snippet does not show the real code.

    But the plot canvas is actually using a backing store ( a QPixmap ), that gets updated on certain operations like when the size of the canvas is changing or replot has been called.
    Beside that the content of the widget is always restored from this backing store only.

    So when calling QWidget::update( region ) only all what happens is, that the rectangles from region will be copied from the backing store of the canvas to another backing store - the default one every widgets has.

    Uwe

  7. #7
    Join Date
    Jun 2020
    Posts
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to plot the real time data in qwtplot while erasing fixed-width old data?

    @lockdown Have you found a way to achieve this? because I am running in circles about the same issue and that would be really great help.

Similar Threads

  1. Replies: 2
    Last Post: 31st December 2019, 19:24
  2. Plot the graph for real time data
    By swinetha in forum Qwt
    Replies: 13
    Last Post: 1st August 2013, 05:56
  3. Replies: 2
    Last Post: 5th April 2013, 05:58
  4. real time data display
    By hammer256 in forum Qt Programming
    Replies: 13
    Last Post: 25th March 2013, 17:47
  5. Replies: 1
    Last Post: 27th April 2011, 11:35

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
  •  
Qt is a trademark of The Qt Company.