Qcustomplot设置图例与曲线同步选中

本文介绍了如何在Qcustomplot中设置图例与曲线同步选中。通过调整Qcustomplot属性,定义槽函数并连接信号槽,实现了点击图例时曲线相应显示隐藏的效果。详细步骤包括Qcustomplot的初步使用,槽函数的编写等。
摘要由CSDN通过智能技术生成

Qcustomplot入门请点击: Qcustomplot入门教程
1、设置Qcustomplot属性:

//设置基本坐标轴(左侧Y轴和下方X轴)可拖动、可缩放、曲线可选、legend可选、设置伸缩比例,使所有图例可见
CustomPlot->setInteractions(QCP::iRangeDrag|QCP::iRangeZoom| QCP::iSelectAxes |
                                  QCP::iSelectLegend | QCP::iSelectPlottables); 
//设置legend只能选择图例
CustomPlot->legend->setSelectableParts(QCPLegend::spItems);

对于这个应用,这两项为必选:QCP::iSelectAxes |QCP::iSelectLegend

2、头文件中定义槽函数:

private slots:
    void selectionChanged();

3、连接信号槽:

connect(ui->customPlot, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));

4、编写槽函数:

void MainWindow::selectionChanged()
{  
  // make top and bottom axes be selected synchronously, and handle axis and tick labels as 
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值