LineChart: one line with different colors

  • Hello,

    I want to plot a LineChart using diffrent colors for the same QLineSeries. I have been searching but I found nothing. Does anyone know if this is possible with Qt?

    I attach a photo to show what I would like to do.


  • I found a kind of solution to do this using gradients. It is probably not the best way but by now it accomplishes the goal.

    QLinearGradient gradient(0,0,0,1);
    gradient.setColorAt(0, Qt::blue);
    gradient.setColorAt(threshold_low-0.1, Qt::blue);
    gradient.setColorAt(threshold_low, Qt::gray);
    gradient.setColorAt(threshold_up, Qt::gray);
    gradient.setColorAt(threshold_up+0.1, Qt::red);
    gradient.setColorAt(1, Qt::red);
    QPen pen(QBrush(gradient), 2);

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.