我希望在我的画布中有一个交互式图例,但是我无法让它工作。我正在使用qwt6.1.2,这个版本不再可以选择将图例作为“ExternalLegend”插入,而是使用类qwtPlotLegendItem来处理画布内的图例。但是,当我阅读文档时,我看到了:
与QwtLegend相反,图例项目不是交互式的。
外部QwtLegend在图表顶部带有透明背景 画布可能是具有类似效果的另一种选择。
我的问题是:如何在情节画布上显示QwtLegend?
在QwtPlot的文档中,我读到了:
未插入绘图小部件布局的图例需要 连接到legendDataChanged()信号。调用updateLegend() 启动此信号进行初始更新。
我已经连接了legendDataChanged信号并通过调用updateLegend()来触发它,但现在我仍然坚持下一步该做什么。关于如何进行的任何提示?
答案 0 :(得分:0)
好的,我得到了它的工作:
QwtPlot* plot;
// Attach some plots/histograms to the plot.
MyLegend* legend = new MyLegend(plot);
MyLegend ::MyLegend (QwtPlot * pPlot)
: m_pPlot(pPlot)
{
setParent(m_pPlot);
setGeometry(0, 0, 100, 100);
connect(m_pPlot, &QwtPlot::legendDataChanged,
this, &MyLegend ::LegendDataChanged);
m_pPlot->updateLegend();
}
void MyLegend ::LegendDataChanged(const QVariant &itemInfo, const QList< QwtLegendData > &data)
{
updateLegend(itemInfo, data);
}