QCustomPlot adding subTicks
-
Hi All,
I am using QCustomPlot and want to do some customization for my x axis subTick labels. I have tried add a custom layer on top of main layer or grid layer, it will complains bool __cdecl QCustomPlot::moveLayer(class QCPLayer *,class QCPLayer *,enum QCustomPlot::LayerInsertMode) otherLayer not a layer of this QCustomPlot: 0
The closest approaches is like below:
QVector<double> subTickPositions; for (int i = 1; i < tickerLog->ticks().keys().size(); ++i) { double subTickPosition = (tickerLog->ticks().keys()[i - 1] + tickerLog->ticks().keys()[i]) / 2.0; subTickPositions.append(subTickPosition); } // Set custom labels for subticks if needed QVector<QString> subTickLabels; for (int i = 1; i < tickerLog->ticks().keys().size(); ++i) { double lower = tickerLog->ticks().values()[i - 1].toDouble(); double upper = tickerLog->ticks().values()[i].toDouble(); double subTickPosition = (lower + upper) / 2.0; subTickLabels.append(QString::number(subTickPosition)); } // Manually draw subticks and labels for (int i = 0; i < subTickPositions.size(); ++i) { double subTickPosition = subTickPositions.at(i); QString subTickLabel = subTickLabels.value(i); // Draw label at the specified position QCPItemText *label = new QCPItemText(plot); label->position->setCoords(subTickPosition, plot->yAxis->range().lower); // Adjust the label position label->setText(subTickLabel); }
And the chart I am getting is like below (as you might see the label is being cut off by the plot's x Axis.
Wish anyone could help!! And this is the newest version 2.1.1
Best,