前言
在使用QCustomPlot过程中,我画的是折线图,我想实现在我上移下移折线图时,可以设置当前上移下移的是那条线。找了许久都没发现怎么搞,然后查找高亮的方法结果发现还是可以用的,此处折磨许久,记录备用
实现方法
void ChartOperate::setArbitrarilyLineStyle(int lineIndex)
{
for (int i=0; i<m_plot->graphCount(); ++i)
{
if(i == lineIndex)
{
QCPGraph *graph = m_plot->graph(i);
QCPPlottableLegendItem *item = m_plot->legend->itemWithPlottable(graph);
QPen pen = highLightLineStyle();
item->setSelected(true);
graph->selectionDecorator()->setPen(pen);
graph->setSelection(QCPDataSelection(graph->data()->dataRange()));
m_plot->replot();
}
}
}
展示效果