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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM