I have a QwtPlot with a couple of lines in it. It also has a legend.
Now apart from the description of the lines themself, I would like to add extra text describing the graph in general.
E.g. "line a: length of frog, line b: weight of frog" and then as an extra "outside temperature is 12C" (the temperature is then not drawn).
The description of QwtPlot shown in legend is QwtLegendData
. Further in the QwtPlotItem
doc (which is a superclass of all QwtPlots):
QwtLegendData is basically a list of QVariants that makes it possible to overload and reimplement legendData() to return almost any type of information, that is understood by the receiver that acts as the legend.
So everything that you need is to pull the existing "automated" legend from the plot and add one more QwtLegendData
to it. It also needs a QVariant as a "key" to distinguish between Datas for each plot, but it can be really anything expectably different from the keys of real plots. Even default (empty) QVariant()
will do, if you don't plan to add any more such extra texts.
QwtLegendData data;
data.setValue(QwtLegendData::Role::TitleRole, QVariant("Outside temperature is 12C"));
QList<QwtLegendData> list;
list << data;
QwtAbstractLegend* existingLegend = frogPlot.legend();
// "update" with a new key really means "insert"
existingLegend->updateLegend(QVariant("Temperature comment extra text"), list);