QwtLegendData::setValue(QwtLegendData::Role::IconRole, ...)
Brought to you by:
rathmann
Good day Uwe!
I'm trying to add a QwtPlotMarker to the legend of my Plot with an Icon that represents it's actual style: a colored dotted line.
This is how my attempt look like:
void MCUPlotWidget::addLimit(const MCUPlotLimit::Description &desc)
{
_limits[desc.id] = new MCUPlotLimit(desc);
_limits[desc.id]->attachTo(_plot);
QPixmap pm(32, 32);
pm.fill(Qt::transparent);
QPainter painter(&pm);
painter.setPen(QPen(QBrush(desc.color), 3, Qt::DotLine));
painter.drawLine(pm.rect().topLeft(), pm.rect().bottomRight());
QIcon icon(pm);
QwtLegendData ld;
ld.setValue(QwtLegendData::Role::TitleRole, desc.name);
ld.setValue(QwtLegendData::Role::IconRole, icon);
_legend->updateLegend(_limits[desc.id]->limit(), QList<QwtLegendData>{ld});
}
But no matter what I try, the icon doesn't appear on the legend widget - only the name of my legend data. I see that the Icon for a QwtLegendData should be of type QwtGraphic, but there is no way to set a QwtGraphic with the method QwtLegendData::setValue since it is missing a conversation to a QVariant.
Am I doing something wrong?
Best regards
Anton from MCU
Anonymous
Hallo Anton,
this sound more like a support request. Please contact me on the mailing list or by private email. and I will try to elaborate how to do it with the current implementation of Qwt