Hi,
How can I add generic extra text to a legend?
Text that is independent from the curves.
Hi,
How can I add generic extra text to a legend?
Text that is independent from the curves.
What exactly do you want t achieve - having additional entries on the legend or having a different text than the title of the corresponding plot item ?
Uwe
Hi ??? [flok],
create a new curve object, set line attribute to NoLine, set legend text, add to plot. It will show up in the legend, but not paint anything in the plot.
Bye,
Andreas
Andreas
When doing this hack it would be enough to add a dummy QwtPlotItem with the QwtPlotItem::Legend attribute being enabled.
But of course it is also possible to add entries manually to the legend, by calling QwtLegend::updateLegend - even if calling this method is due to its "over-abstraction" kind of hard to use.
Uwe
flok (23rd January 2019)
Ok I succeeded in adding entries by:
void addToLegend(const QString & key, const QStringList & what, QwtAbstractLegend *const legend)
{
QList<QwtLegendData> list;
for(QStringList::const_iterator it = what.begin(); it != what.end(); it++) {
QwtLegendData data;
data.setValue(QwtLegendData::Role::TitleRole, QVariant(*it));
list << data;
}
legend->updateLegend(QVariant(key), list);
}
then I do:
QStringList le;
le.append("hello");
le.append("bicycle");
le.append("1");
addToLegend("key", le, graph -> legend());
Unfortunately when calling this, say, two times, the layout gets messed up: the order of the items becomes seemingly random.
Is there a way in which I can either sort them or keep them in the same order as added?
I also tried adding items individually and them giving them a key-in-order (a, b, c, etc) but that did not help.
Qwt is open source - you can check/debug what is going on in your case easily.
Maybe also have a look at the stockchart example, that shows how to implement a totally different type of legend.
HTH,
Uwe
Bookmarks