本文主要是介绍QChart 选中图例对应折线变色,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
因为项目中需要用的折线比较多,查找某一条比较困难所以做了选中图例折线变色的功能,代码比较简单:
QColor m_color;
QChart m_chart;
void MainWindow::markers()//关联初始化
{
foreach(QLegendMarker* pLegendMarker, m_chart->legend()->markers())
{
connect(pLegendMarker, SIGNAL(hovered(bool)), this,SLOT(sltHandleMarkerClicked(bool)));
}
}
void MainWindow::sltHandleMarkerClicked(bool status)
{
QLegendMarker* poLegendMarker = qobject_cast<QLegendMarker*> (sender());
switch (poLegendMarker->type())
{
case QLegendMarker::LegendMarkerTypeXY:
{
QLineSeries* LineSeries = dynamic_cast<QLineSeries*>(poLegendMarker->series());
poLegendMarker->setVisible(true);
if(status)
{
m_color = LineSeries->color();
LineSeries->setColor(QColor(255,0,0));
}
else{
LineSeries->setColor(m_color);
LineSeries->chart()->legend()->setColor(m_color);
}
break;
}
default:
{
qDebug() << "Unknown type";
break;
}
}
}
效果图:前
后:
下载:https://download.csdn.net/download/u010304326/10930311
这篇关于QChart 选中图例对应折线变色的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!