I am drawing a line in an object derived from QWidget. I can set the pen to draw a line in the color of my choice. What I want to be able to do is change the color of the pen when it’s current y coordinate is above a specified value.
One option is simply to split the line I want to draw into two separate halves; split where the y coordinate is above the specified value. While there is nothing wrong with this method, I was hoping that there was a simpler method I could use.
What I want to be able to do is basically extend the drawline function. I want to be able to change the drawing algorithm so that, for each pixel it wants to set the color of, it will check which color to use based on a supplied function.
I would not recommend to overload the basic drawing algorithm. I think it be more easy to use a
QGradientwhen drawing the line?