I want to draw a polyline using QPainter. The line should change color dynamically according to point coordinates.

In order to achieve this, I'd like to subclass QGradientin order to obtain a QFunctionGradient where I can set a std::function<QColor(QPointF)> that gives me the color of a point given its coordinates.

So, at first, how It's possibile to draw a polyline with QPainter and color it according to a QGradient?

And it's possible to subclass QPainter and use this subclass inside QBrush?