Hi,
Here is a complete code that works :
mycurve.h
{
public:
MyCurve(){}
~MyCurve(){}
virtual QList<QwtLegendData>legendData(void) const;
};
class MyCurve : public QwtPlotCurve
{
public:
MyCurve(){}
~MyCurve(){}
virtual QList<QwtLegendData>legendData(void) const;
};
To copy to clipboard, switch view to plain text mode
mycurve.cpp
QList<QwtLegendData> MyCurve::legendData(void) const
{
data
[0].
setValue(QwtLegendData
::UserRole + 1,
QVariant(this
->pen
().
color()));
return data;
}
...MyCurve *curve = new MyCurve();
...
curve->setPen
(QColor(...,...,...
);
curve->legendData();
...
curve->attach(this); ...
void Legend
::updateItem( QStandardItem *item,
const QwtLegendData
&data
) {
...
const QVariant colorValue
= data.
value(QwtLegendData
::UserRole + 1);
if (colorValue.canConvert<QColor>())
curveColor = colorValue.value<QColor>();
}
QList<QwtLegendData> MyCurve::legendData(void) const
{
QList<QwtLegendData> data = QwtPlotCurve::legendData();
data[0].setValue(QwtLegendData::UserRole + 1, QVariant(this->pen().color()));
return data;
}
...MyCurve *curve = new MyCurve();
...
curve->setPen(QColor(...,...,...);
curve->legendData();
...
curve->attach(this); ...
void Legend::updateItem( QStandardItem *item, const QwtLegendData &data )
{
...
const QVariant colorValue = data.value(QwtLegendData::UserRole + 1);
QColor curveColor;
if (colorValue.canConvert<QColor>())
curveColor = colorValue.value<QColor>();
item->setBackground(QBrush(QColor(curveColor)));
}
To copy to clipboard, switch view to plain text mode
Bookmarks