You can set a color gradient to QPen by displaying the look you want.
QPen::QPen(const QBrush &brush, qreal width, Qt::PenStyle style =
Qt::SolidLine, Qt::PenCapStyle cap = Qt::SquareCap, Qt::PenJoinStyle
join = Qt::BevelJoin)
Constructs a pen with the specified brush, width, pen style, cap style
and join style.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCustomPlot *customplot = new QCustomPlot;
customplot->setWindowTitle("Gradient Color");
customplot->resize(640, 480);
QCPCurve curve(customplot->xAxis, customplot->yAxis);
QVector<double> x, y;
for(int i=0; i < 1000; i++){
double x_ = qDegreesToRadians(i*1.0);
x << x_;
y << qCos(x_)*qExp(-0.2*x_);
}
customplot->xAxis->setRange(0, qDegreesToRadians(1000.0));
customplot->yAxis->setRange(-1, 1);
QLinearGradient gradient(customplot->rect().topLeft(), customplot->rect().topRight());
gradient.setColorAt(0.0, QColor::fromRgb(14, 11, 63));
gradient.setColorAt(1.0, QColor::fromRgb(58, 98, 240));
QPen pen(gradient, 5);
curve.setPen(pen);
curve.setData(x, y);
customplot->show();
return a.exec();
}
