You can do a linear interpolation and build the QColor. Let's assume you want the color at the point P, which is on the line between startP and endP.
double segmentLength = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
double pdist = sqrt((xp-x1)*(xp-x1) + (yp-y1)*(yp-y1));
double ratio = pdist/segmentLength;
int red = (int)(ratio*startRedVal + (1-ratio)*endRedValue); //in your case, the values are 12 and 122
int green = (int)(ratio*startGreenVal + (1-ratio)*endGreenValue); //in your case, the values are 23 and 233
int blue = (int)(ratio*startBlueVal + (1-ratio)*endBlueValue); //in your case, the values are 24 and 244
double segmentLength = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
double pdist = sqrt((xp-x1)*(xp-x1) + (yp-y1)*(yp-y1));
double ratio = pdist/segmentLength;
int red = (int)(ratio*startRedVal + (1-ratio)*endRedValue); //in your case, the values are 12 and 122
int green = (int)(ratio*startGreenVal + (1-ratio)*endGreenValue); //in your case, the values are 23 and 233
int blue = (int)(ratio*startBlueVal + (1-ratio)*endBlueValue); //in your case, the values are 24 and 244
To copy to clipboard, switch view to plain text mode
Bookmarks