QCustomPlot圖形和圖例同步前言
我現在有幾條折線,折線和圖例一一對應,不管點擊圖例或者折線,相關的都高亮
QCustomPlot圖形和圖例同步方法
// 鏈接信號槽 m_plot即為QCustomPlot對象 connect(m_plot, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
void ChartOperate::selectionChanged() { for (int i=0; i<m_plot->graphCount(); ++i) { setSelectChtLineStyle(i); } } void ChartOperate::setSelectChtLineStyle(int sceneIndex) { QCPGraph *graph = m_plot->graph(sceneIndex); QCPPlottableLegendItem *item = m_plot->legend->itemWithPlottable(graph); if (item->selected() || graph->selected()) { item->setSelected(true); QPen pen; pen.setWidth(3); pen.setColor(COLOR_BLUE); graph->selectionDecorator()->setPen(pen); graph->setSelection(QCPDataSelection(graph->data()->dataRange())); } }
QCustomPlot圖形和圖例同步最終效果
原文地址:https://itzhai.cn/xuexijiaocheng/884.html