QCustomPlot图形和图例同步方法
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
本文作者:不随。
本文链接:https://www.cnblogs.com/tmblog/p/12661780.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步