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