def radial_gradient(color, color_light=50): """ radial_gradient(QColor, QColor) radial_gradient(QColor, int) Return a radial gradient. `color_light` can be a QColor or an int. In the later case the light color is derived from `color` using `saturated(color, color_light)`. """ if not isinstance(color_light, QColor): color_light = saturated(color, color_light) gradient = QRadialGradient(0.5, 0.5, 0.5) gradient.setColorAt(0.0, color_light) gradient.setColorAt(0.5, color_light) gradient.setColorAt(1.0, color) gradient.setCoordinateMode(QRadialGradient.ObjectBoundingMode) return gradient
def rebuildDataBrushIfNeeded(self): if not self.m_rebuildBrush or not self.m_gradientData or self.m_barStyle == self.BarStyle.LINE: return self.m_rebuildBrush = False p = self.palette() if self.m_barStyle == self.BarStyle.EXPAND: dataBrush = QRadialGradient(0.5, 0.5, 0.5, 0.5, 0.5) dataBrush.setCoordinateMode(QGradient.StretchToDeviceMode) for i in range(0, len(self.m_gradientData)): dataBrush.setColorAt(self.m_gradientData[i][0], self.m_gradientData[i][1]) p.setBrush(QPalette.Highlight, dataBrush) else: dataBrush = QConicalGradient(QPointF(0.5, 0.5), self.m_nullPosition) dataBrush.setCoordinateMode(QGradient.StretchToDeviceMode) for i in range(0, len(self.m_gradientData)): dataBrush.setColorAt(1 - self.m_gradientData[i][0], self.m_gradientData[i][1]) p.setBrush(QPalette.Highlight, dataBrush) self.setPalette(p)