After working a bit on that, I have found a way to do it although I do not really like it because it involves changing the sourcecode of the library. In the qcustomplot.h I have added a new enumtype to represent the new color gradient (arround line 4424) and int qcustomplot.cpp I have added a new case for the switch at line 15852 that runs the following code when the new enumtype is set:
case gpJetTrunk:
setColorInterpolation(ciRGB);
setColorStopAt(0, Qt::transparent);
setColorStopAt(1e-5, QColor(0, 0, 100));
setColorStopAt(0.15, QColor(0, 50, 255));
setColorStopAt(0.35, QColor(0, 255, 255));
setColorStopAt(0.65, QColor(255, 255, 0));
setColorStopAt(0.85, QColor(255, 30, 0));
setColorStopAt(1-1e-5, QColor(100, 0, 0));
setColorStopAt(1, Qt::transparent);
break;
After this I have realised that mybe the good solution is to create a new class inheriting from
QCPColorGradient and reimplement the function
QCPColorGradient::loadPresets(GradientPreset preset)
. Here is what I did:
class MyQCPColorGradient: public QCPColorGradient{
public:
MyQCPColorGradient(){}
~MyQCPColorGradient(){}
void loadPreset(MyQCPColorGradient::GradientPreset preset){
QCPColorGradient::setColorInterpolation(MyQCPColorGradient::ciRGB);
QCPColorGradient::setColorStopAt(0, Qt::transparent);
QCPColorGradient::setColorStopAt(1e-5, QColor(0, 0, 100));
QCPColorGradient::setColorStopAt(0.15, QColor(0, 50, 255));
QCPColorGradient::setColorStopAt(0.35, QColor(0, 255, 255));
QCPColorGradient::setColorStopAt(0.65, QColor(255, 255, 0));
QCPColorGradient::setColorStopAt(0.85, QColor(255, 30, 0));
QCPColorGradient::setColorStopAt(1-1e-5, QColor(100, 0, 0));
QCPColorGradient::setColorStopAt(1, Qt::transparent);
}
};
Then I use this new color gradient to set it in the QColorMap using the
QColorMap::setGradient(const QCPColorGradient &gradient)
method. Although everithing compiles, I only see black. any good idea on why that might happen?