我有一个QwtPlot,其中有几行。它也有一个传说。
现在,除了对线条本身进行描述之外,我想添加一些额外的文字来描述图形。
例如“ a线:青蛙的长度,b线:青蛙的重量”,然后作为额外的“外部温度为12C”(然后不绘制温度)。
答案 0 :(得分:2)
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);