On 21/06/18 11:51, Massimiliano Maini wrote:
I'd need to do something like this: https://imgur.com/MLAEuad

I have a set of (x,y,z) data points and want to plot them on a usual 2d plot ( x and y values), but with the line color depending on the z values (colormap).

How can this be achieved in Qt ?

I'm not sure if I understood correctly; the graph in the picture isn't using a third independent variable for the color of each point, rather it's just using the y (in other words: the color of each point in the line is just a function of its y coordinate.)

Anyhow, short of using a complete graphing solution, you can easily generate a vertical gradient using QLinearGradient (with the number of stops you need), and the curve as a QPainterPath. Then you have a couple of easy options:

1) set the curve as a clip path on a QPainter, and fill a rectangle with the gradient (=> only the path will be filled), or

2) create a transparent QImage of suitable size, draw the path in some solid color, and draw a rectangle filled with the gradient over the path using some composition mode, e.g. SourceIn. Then draw the image on your chart.

HTH,
--
Giuseppe D'Angelo | [email protected] | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to