QCustomPlot Discussion and Comments

Multicolor axis tickReturn to overview

Hi all!
Is there any way to use one multicolor axis lable tick to display data?
I want to see my X axis lable at range < 0 with red color and > 0 with green color.

There's no public interface for this special requirement. You'll need to modify the QCPAxis draw methods. To be precise, the QCPAxis::drawTickLabel and possibly placeTickLabel and getTickLabelData methods. You can do this either by subclassing QCPAxis (and QCustomPlot so it uses the new axis class) or by directly modifying the code.

Here's one way to do it: Add a flag to the struct QCPAxis::TickLabelData which indicates whether the data label shall be red or green (could also use a QColor). Have the drawTickLabel method respect that color and set the painter's pen accordingly, before drawing the text. In the placeTickLabel or getTickLabelData you'll have to set the flag/color in the label data struct instance.