Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QCustomPlot fixed grid and subGrid lines



  • Hi,

    I am working on a project where I need to replicate ECG lines with fixed grid and subgrid lines. Something like this https://ecglibrary.com/ecgs/norm_2x.png
    I am working with QCustomPlot library as stated in topic description.
    I need to have doted lines every 2mm (converted to resolution) and fixed lines every 10mm.

    Does anyone have suggestions?


  • Lifetime Qt Champion



  • @mrjj From the documentation I understand that I need to use QCPAxisTickerFixed class, but I do not understand how to determine tick step on order to have grid lines every 2mm and 10mm.



  • I have managed to setup tick and subtick grid lines with this code. But I am not sure how to determine distance between these lines.

    /* X Axis: Style /
    ui->printPlot->xAxis->grid()->setPen(QPen(QColor(170, 170, 170, 255), 1, Qt::SolidLine));
    ui->printPlot->xAxis->grid()->setSubGridPen(QPen(QColor(170, 170, 170, 255), 1, Qt::DotLine));
    ui->printPlot->xAxis->grid()->setVisible(true);
    ui->printPlot->xAxis->grid()->setSubGridVisible(true);
    ui->printPlot->xAxis->setBasePen(QPen(QColor(170, 170, 170, 255)));
    ui->printPlot->xAxis->setTickPen(QPen(QColor(170, 170, 170, 255)));
    ui->printPlot->xAxis->setSubTickPen(QPen(QColor(170, 170, 170, 255)));
    ui->printPlot->xAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
    ui->printPlot->xAxis->setTickLabelColor(QColor(170, 170, 170, 255));
    //ui->printPlot->xAxis->setTickLabelFont(font);
    /
    Range */

    	/* Y Axis */
    	ui->printPlot->yAxis->grid()->setPen(QPen(QColor(170, 170, 170, 255), 1, Qt::SolidLine));
    	ui->printPlot->yAxis->grid()->setSubGridPen(QPen(QColor(170, 170, 170, 255), 1, Qt::DotLine));
    	ui->printPlot->yAxis->grid()->setVisible(true);
    	ui->printPlot->yAxis->grid()->setSubGridVisible(true);
    	ui->printPlot->yAxis->setBasePen(QPen(QColor(170, 170, 170, 255)));
    	ui->printPlot->yAxis->setTickPen(QPen(QColor(170, 170, 170, 255)));
    	ui->printPlot->yAxis->setSubTickPen(QPen(QColor(170, 170, 170, 255)));
    	ui->printPlot->yAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
    	ui->printPlot->yAxis->setTickLabelColor(QColor(170, 170, 170, 255));
    	//ui->printPlot->yAxis->setTickLabelFont(font);
    	/* Range */

Log in to reply