How to show ticks and subticks on zerolines in QCustomPlot?

888 views Asked by At

Is there any way of showing ticks and subticks over zerolines in QCustomPlot? I couldn't find anything in documentation.

2

There are 2 answers

0
Adnan On BEST ANSWER

I had to create ticks and subticks with QCPItemLine. Here is the code:

for(int i=-65; i<=65; i+=10)
{
    // Ticks
    QCPItemLine *tickHLine=new QCPItemLine(ui->customPlot);
    ui->customPlot->addItem(tickHLine);
    tickHLine->start->setCoords(i,-1);
    tickHLine->end->setCoords(i,1);
    tickHLine->setPen(QPen(QColor(137, 140, 140), 1));

    //Subticks
    QCPItemLine *subTickHLine=new QCPItemLine(ui->customPlot);
    ui->customPlot->addItem(subTickHLine);
    subTickHLine->start->setCoords(i+5,-2);
    subTickHLine->end->setCoords(i+5,2);
    subTickHLine->setPen(QPen(QColor(137, 140, 140), 1));
}
0
DerManu On

You may have your layers mixed up. Make sure your grid is on a layer below the axis, because the zero line is part of the grid, and the ticks part of the axis. So for example:

axis->setLayer("axes");
axis->grid()->setLayer("grid");

Note that "axes" and "grid" are layers that exist by default. And normally the grid is already placed on the correct layer, so what you are experiencing is probably due to clearing the default setup/plot layout and then creating a new axis rect all on one layer.