PDA

View Full Version : qwtplot->print() removes dummy markers from legend



Ban-chan
22nd October 2009, 16:09
First some background:
I essentially have a scrollbar to shift between different plots (1 qwt plot with one curve attached but I simply change the data the curve points to when the scroll bar is moved). Works fine. Depending on the data set being plotted I have a variable number of qwtplotmarkers that are plotted. When I move the scroll bar to change to a new plot I delete the old markers and create new ones. This works fine as well.

Since I am deleting and creating new markers I can't simply attach them to the legend. What I did was create a dummy marker and add it to the legend like so:

dummyMarker is declared in header (QwtPlotMarker *dummyMarker)
lgndDummy is a QwtLegendCurveItem (see newest repository if using qwt 5.2.0) set as checkable




dummyMarker = new QwtPlotMarker;
dummyMarker->attach(mainPlot);

legend->insert(dummyMarker,lgndDummy);


I then use lgndDummy's signal "checked" to toggle whether the actual markers I attached to plot are shown or hidden. This works fine.

When I go to save an image of the plot using the "print all" options and the print() function I found that this function removes these dummy items from the legend (the markers are still visible on the plot). This occurs before the image is saved as the image only shows the curve in the legend.

So my question is: Is there a better way to do this or something I can do to prevent plot->print() from removing my dummy legend items?

Uwe
23rd October 2009, 08:57
Derive from QwtPlotMarker, and implement updateLegend(). Then enable QwtPlotItem::Legend for one of your markers.
Another solution is to implement a dummy plot item, that paints nothing on the canvas, but implements the updateLegend() method.

Uwe

Ban-chan
27th October 2009, 13:40
Got it working! Thanks Uwe.