PDA

View Full Version : qt drawing like a banner.



Pablo220372
6th June 2011, 12:20
Hi everybody,

I need a suggestion from you. I have to draw points collected from an external data provider micro controller, continuously. Basically, it is like drawing a curve, from left to right between two Y values, continuously. So, when a value reach the right margin, the drawing does not stop, but continue to draw point on screen. Ex. print the sin function from left to right continuously. Do you have any idea how to do it? thx for any suggestions.

Cheers,

mvuori
6th June 2011, 15:21
Create a widget on-screen, but don't draw directly on it.

Instead, create a bitmap or image to draw on. Each time you draw another point, copy the whole image to the widget.

Now, here's the trick: When you get to the right edge, make room to the new data point by copying it to the left (copy a region slightly offset from the left edge, to the right edge, using for example QImage::Copy() & QPainter::DrawImage() to "paste" it extend the cordinate axises a bit and draw the new data points. This will get nice scrolling of the display.

You may need to think of the widget as having perhaps many rectangles that are updated in different ways.

Santosh Reddy
6th June 2011, 17:57
You can try exploring Qwt

wysota
6th June 2011, 17:58
There is a different trick one might use to avoid unnecessary moving of data. Use more than one pixmap --- when you have no space left in the pixmap, create another one and start filling it with data. Once you have more pixmaps than can fit the display, remove the first pixmap to free memory.

Pablo220372
7th June 2011, 16:12
Thanks a lot guys, yours ideas are very good. In the meanwhile I checked for the QWT plugin and downloaded the source code with examples. There is one that helps for this case, and it is the "oscilloscope" one. Very cool example because you can change the frequency, interval, time, etc. But (there is always a but ), when checking at the plot.cpp file, I got stacked in the updateCurve() and incrementInterval() functions. It speaks about a "clip" and honestly I cannot follow the logic of the code. If you have time (or ever have locked at it), would be nice what this all mean. I really appreciate again your time.
Hope you can help me out
Cheers,