workaround missing setStops binding

This commit is contained in:
KIU Shueng Chuan 2021-01-10 16:27:24 +08:00
parent b0f7dda102
commit c4addbeaea
2 changed files with 14 additions and 2 deletions

View File

@ -359,7 +359,13 @@ class ColorMap(object):
pos, color = self.getStops(mode=self.BYTE)
color = [QtGui.QColor(*x) for x in color]
g.setStops(list(zip(pos, color)))
stops = zip(pos, color)
if hasattr(g, 'setStops'):
g.setStops(list(stops))
else:
# PySide6 has a missing setStops binding
for pos, col in stops:
g.setColorAt(pos, col)
return g
def getColors(self, mode=None):

View File

@ -626,9 +626,10 @@ class GradientEditorItem(TickSliderItem):
def getGradient(self):
"""Return a QLinearGradient object."""
g = QtGui.QLinearGradient(QtCore.QPointF(0,0), QtCore.QPointF(self.length,0))
stops = []
if self.colorMode == 'rgb':
ticks = self.listTicks()
g.setStops([(x, QtGui.QColor(t.color)) for t,x in ticks])
stops = [(x, QtGui.QColor(t.color)) for t,x in ticks]
elif self.colorMode == 'hsv': ## HSV mode is approximated for display by interpolating 10 points between each stop
ticks = self.listTicks()
stops = []
@ -641,7 +642,12 @@ class GradientEditorItem(TickSliderItem):
x = x1 + dx*j
stops.append((x, self.getColor(x)))
stops.append((x2, self.getColor(x2)))
if hasattr(g, 'setStops'):
g.setStops(stops)
else:
# PySide6 has a missing setStops binding
for pos, col in stops:
g.setColorAt(pos, col)
return g
def getColor(self, x, toQColor=True):