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