Question

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

Was it helpful?

Solution 2

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));
}

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top