One legend on the top of my plot which displays 3 or more different QwtPlotZoneItems. When I add them to a legend they are displayed without icon but I need the color of brush/pen because it indicates a certain state.
Should be something like this:
class YourZoneItem: public QwtPlotZoneItem
{
....
virtual QwtGraphic legendIcon
( int,
const QSizeF &size
) const override
{
return defaultIcon( brush().color(), size );
}
};
class YourZoneItem: public QwtPlotZoneItem
{
....
virtual QwtGraphic legendIcon( int, const QSizeF &size ) const override
{
return defaultIcon( brush().color(), size );
}
};
To copy to clipboard, switch view to plain text mode
I use multiple plots which use the same x-Axis and they all have the same marked Zones. So on top of my plots i want to have a legend indicating which color represents which state.
Plots and legends are connected by QwtPlot::legendDataChanged() -> QwtAbstractLegend::updateLegend(). When not using QwtPlot::insertLegend() you are free to put a legend ( or more than one ) wherever you want to - but you have to set up the connection manually. In this case QwtPlotRenderer does not know about your layout and you would have to write some code in case you need to have the legend on a PDF.
I can imagine, that you have to derive from QwtLegend overloading updateLegend() to sort out certain types of items, you don't want to have on this legend ( for the one on top all beside the zones ).
It might help to have a look at legend.cpp from the stockchart example, where you can see how to evaluate the parameters of QwtAbstractLegend::updateLegend().
Uwe
Bookmarks