PDA

View Full Version : DirectPainter and z order



ScottBell
6th February 2013, 21:06
This is another about updating a QwtPlotCurve as new data arrives from a time-sensitive source. Refer to the oscilloscope example but create a sweep effect instead of clearing on each restart.

Using Qt 4.8 and qwt-6.0.1, currently developing on Windows and the app will also be on Linux.

Bursts of data arrive, say 50 at a time, up to 100000, then repeat. To update an existing section, first set a QwtPlotDirectPainter pen to black, slightly wider than the actual curve, and redraw the 50 old points. Second I have an overloaded hook to QwtSeriesData->replace(), so update the 50 points. Finally change the DirectPainter pen to normal and draw the new section.

The problem - DirectPainter black pen erases QwtPlotGrid where they overlap. The z value is 10 for grid and 20 for plot curve. Changing these during initialization or before painting makes no difference.

As a guess, does DirectPainter ignore this and assume that its curves are always supposed to be on top?

Several workarounds come to mind but all require a replot. The idea of clip regions is a bit fuzzy, not sure if this means a rectangle or other shape is the only part replotted. I have not run across examples that fit here.

Am I missing something or any suggestions to get the grid points back, or replot only a region?
Thanks,
Scott

Uwe
7th February 2013, 08:18
The problem - DirectPainter black pen erases QwtPlotGrid where they overlap. The z value is 10 for grid and 20 for plot curve.
Plot items are painted in order of increasing z values. So in your setting the curve will always be on top of the grid !


As a guess, does DirectPainter ignore this and assume that its curves are always supposed to be on top?
Yes, the direct painter always paints on top of the existing content - z values are of no meaning when using it.


Am I missing something or any suggestions to get the grid points back, or replot only a region?
You could repaint the grid lines after you have added a new section of your curve.

With the X11 paint engine it is easy, as you can paint outside of paint events. If not you have to do the same what the direct painter does:



install en event filter for the plot canvas
call canvas()-repaint
uninstall the event filter


Inside of the event filter check for paint events and draw the lines that were crossed by the new section of the curve

Uwe