'Return a color for a given value.
**Arguments:**
x               Value (position on gradient) of requested color.
toQColor        If true, returns a QColor object, else returns a (r,g,b,a) tuple.'

def getColor(self, x, toQColor=True):

    ticks = self.listTicks()
    if (x <= ticks[0][1]):
        c = ticks[0][0].color
        if toQColor:
            return QtGui.QColor(c)
        else:
            return (c.red(), c.green(), c.blue(), c.alpha())
    if (x >= ticks[(-1)][1]):
        c = ticks[(-1)][0].color
        if toQColor:
            return QtGui.QColor(c)
        else:
            return (c.red(), c.green(), c.blue(), c.alpha())
    x2 = ticks[0][1]
    for i in range(1, len(ticks)):
        x1 = x2
        x2 = ticks[i][1]
        if ((x1 <= x) and (x2 >= x)):
            break
    dx = (x2 - x1)
    if (dx == 0):
        f = 0.0
    else:
        f = ((x - x1) / dx)
    c1 = ticks[(i - 1)][0].color
    c2 = ticks[i][0].color
    if (self.colorMode == 'rgb'):
        r = ((c1.red() * (1.0 - f)) + (c2.red() * f))
        g = ((c1.green() * (1.0 - f)) + (c2.green() * f))
        b = ((c1.blue() * (1.0 - f)) + (c2.blue() * f))
        a = ((c1.alpha() * (1.0 - f)) + (c2.alpha() * f))
        if toQColor:
            return QtGui.QColor(int(r), int(g), int(b), int(a))
        else:
            return (r, g, b, a)
    elif (self.colorMode == 'hsv'):
        (h1, s1, v1, _) = c1.getHsv()
        (h2, s2, v2, _) = c2.getHsv()
        h = ((h1 * (1.0 - f)) + (h2 * f))
        s = ((s1 * (1.0 - f)) + (s2 * f))
        v = ((v1 * (1.0 - f)) + (v2 * f))
        c = QtGui.QColor()
        c.setHsv(h, s, v)
        if toQColor:
            return c
        else:
            return (c.red(), c.green(), c.blue(), c.alpha())
