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.

    Thanks
    0_1497268880238_upload-1f78228f-b720-4e66-9906-2efe36073bbd



  • 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);
    gradient.setCoordinateMode(QGradient::StretchToDeviceMode);
    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.