QtCharts is it posible to have gradient lines?
-
Hi
Maybe you can use
https://doc.qt.io/qt-5.10/qtcharts-customchart-example.html
and draw the gradient as background and let graph be transparent on the actual
plot values. -
How to make line be transparent like in that picture? Because if I set it like this:
QPen green(QColor(0, 0, 0, 0x00));
green.setWidth(2);
m_series->setPen(green);line just becomes invisible. If I set chart background like this:
QBrush brush (QImage(":image/image.png"));
chart->setPlotAreaBackgroundBrush(brush);
chart->setPlotAreaBackgroundVisible(true);
whole chart area then has that image and line is still invisible. if I setPlotAreaBackgroundVisible(false) background disappears, but line is still invisible. How to have, that only chart line shows that background? -
Starting from the aforementioned example, replace
// Customize series QPen pen(QRgb(0xfdb157)); pen.setWidth(5); series->setPen(pen);
with
QLinearGradient lineGradient; lineGradient.setStart(QPointF(0, 1)); lineGradient.setFinalStop(QPointF(1, 0)); lineGradient.setColorAt(0.0, Qt::blue); lineGradient.setColorAt(1.0, Qt::red); lineGradient.setCoordinateMode(QGradient::StretchToDeviceMode); series->setPen(QPen(QBrush(lineGradient),5));