I tried subclassing QwtPlotCurve, and it seems to ALMOST be working. Here's my code for MyQwtPlotCurve:
// MyQwtPlotCurve.h //
{
public:
MyQwtPlotCurve();
MyQwtPlotCurve(const QString& title);
void enable_legend_value(bool on);
void set_legend_value(double value);
private:
bool m_value_enabled;
double m_value;
};
// MyQwtPlotCurve.h //
class MyQwtPlotCurve : public QwtPlotCurve
{
public:
MyQwtPlotCurve();
MyQwtPlotCurve(const QString& title);
void updateLegend(QwtLegend* legend);
void enable_legend_value(bool on);
void set_legend_value(double value);
private:
bool m_value_enabled;
double m_value;
};
To copy to clipboard, switch view to plain text mode
and the relevant part of the cpp file:
void MyQwtPlotCurve
::updateLegend(QwtLegend* legend
) {
printf("Update legend!\n")
if (m_value_enabled)
{
QWidget *widget
= legend
->find
(this);
if ( !widget || !widget->inherits("QwtLegendItem") )
return;
QString text
= legendItem
->text
().
text();
printf("Trying to set marker text: '%s'\n", new_text.toLocal8Bit().constData());
legendItem->setText(new_text);
legendItem->update();
}
}
void MyQwtPlotCurve::updateLegend(QwtLegend* legend)
{
QwtPlotCurve::updateLegend(legend);
printf("Update legend!\n")
if (m_value_enabled)
{
QWidget *widget = legend->find(this);
if ( !widget || !widget->inherits("QwtLegendItem") )
return;
QwtLegendItem* legendItem = (QwtLegendItem*)widget;
QString text = legendItem->text().text();
QString new_text = text + " " + QString().setNum(m_value);
printf("Trying to set marker text: '%s'\n", new_text.toLocal8Bit().constData());
legendItem->setText(new_text);
legendItem->update();
}
}
To copy to clipboard, switch view to plain text mode
That first printf is never printed unless I call updateLegend explicitly. I can then see a flicker as my extra text appears, but it seems to be immediately overwritten.
I'm only using instances of MyQwtPlotCurve, so why isn't my updateLegend() being used?
I'm using Qwt 5.2.1.
Thanks,
- Tom
EDIT: Found my error! Forgot the "const" modifier on MyQwtPlotCurve::updateLegend().
Bookmarks