In my Qt application (Qt 5.15 C++) I'm drawing a path over a map with QPainter::drawPath with a constant color, but would like to change the color for each point to represent altitude.
So the final goal is to have x,y as northing and easting and the path line changes the color to represent the 3rd dimension (altitude), being for example blue 0 altitude, red maximum altitude.
I already have a function that converts depth to a QColor and if I'm plotting points only, I can do it by using setPen before drawing each point.
Although,
I have looked into QGradient, but it's not clear if that's the best way to go and how to use it in this case.
Any ideas?
If you are using QPainter::drawPath()
it means that you have QPainterPath
object at hand. With this object, you can get its total QPainterPath::length()
, then cut it into individual line segments using points QPainterPath::pointAtPercent()
so that each of the segments is small enough to look as a smooth path (use the length to calculate the percentage steps between the start and end points of the path). Then you can paint the sequence of segments (i.e. short lines), each with a different color which you get from your depth function.