本文整理汇总了Python中qgis.PyQt.QtGui.QGradient.stops方法的典型用法代码示例。如果您正苦于以下问题:Python QGradient.stops方法的具体用法?Python QGradient.stops怎么用?Python QGradient.stops使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.PyQt.QtGui.QGradient
的用法示例。
在下文中一共展示了QGradient.stops方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testQgsVectorGradientRampV2
# 需要导入模块: from qgis.PyQt.QtGui import QGradient [as 别名]
# 或者: from qgis.PyQt.QtGui.QGradient import stops [as 别名]
def testQgsVectorGradientRampV2(self):
# test QgsGradientStop
stop = QgsGradientStop(0.9, QColor(200, 150, 100))
self.assertEqual(stop.offset, 0.9)
self.assertEqual(stop.color, QColor(200, 150, 100))
self.assertEqual(QgsGradientStop(0.1, QColor(180, 20, 30)), QgsGradientStop(0.1, QColor(180, 20, 30)))
self.assertNotEqual(QgsGradientStop(0.1, QColor(180, 20, 30)), QgsGradientStop(0.2, QColor(180, 20, 30)))
self.assertNotEqual(QgsGradientStop(0.1, QColor(180, 20, 30)), QgsGradientStop(0.1, QColor(180, 40, 30)))
# test gradient with only start/end color
r = QgsGradientColorRamp(QColor(200, 0, 0, 100), QColor(0, 200, 0, 200))
self.assertEqual(r.type(), 'gradient')
self.assertEqual(r.color1(), QColor(200, 0, 0, 100))
self.assertEqual(r.color2(), QColor(0, 200, 0, 200))
self.assertEqual(r.isDiscrete(), False)
self.assertEqual(len(r.stops()), 0)
self.assertEqual(r.count(), 2)
self.assertEqual(r.value(0), 0.0)
self.assertEqual(r.value(1), 1.0)
self.assertEqual(r.color(0), QColor(200, 0, 0, 100))
self.assertEqual(r.color(1), QColor(0, 200, 0, 200))
self.assertEqual(r.color(0.5), QColor(100, 100, 0, 150))
# test gradient with stops
r = QgsGradientColorRamp(QColor(200, 0, 0), QColor(0, 200, 0), False, [QgsGradientStop(0.1, QColor(180, 20, 40)),
QgsGradientStop(0.9, QColor(40, 60, 100))])
self.assertEqual(r.color1(), QColor(200, 0, 0))
self.assertEqual(r.color2(), QColor(0, 200, 0))
self.assertEqual(r.isDiscrete(), False)
self.assertEqual(len(r.stops()), 2)
self.assertEqual(r.count(), 4)
self.assertEqual(r.value(0), 0.0)
self.assertEqual(r.value(1), 0.1)
self.assertEqual(r.value(2), 0.9)
self.assertEqual(r.value(3), 1.0)
self.assertEqual(r.color(0), QColor(200, 0, 0))
self.assertEqual(r.color(0.05), QColor(190, 10, 20))
self.assertEqual(r.color(0.1), QColor(180, 20, 40))
self.assertEqual(r.color(0.5), QColor(110, 40, 70))
self.assertEqual(r.color(0.9), QColor(40, 60, 100))
self.assertEqual(r.color(0.95), QColor(20, 130, 50))
self.assertEqual(r.color(1), QColor(0, 200, 0))
# test setters
r.setColor1(QColor(0, 0, 200))
self.assertEqual(r.color1(), QColor(0, 0, 200))
self.assertEqual(r.color(0), QColor(0, 0, 200))
r.setColor2(QColor(0, 0, 100))
self.assertEqual(r.color2(), QColor(0, 0, 100))
self.assertEqual(r.color(1.0), QColor(0, 0, 100))
r.setStops([QgsGradientStop(0.4, QColor(100, 100, 40))])
s = r.stops()
self.assertEqual(len(s), 1)
self.assertEqual(s[0].offset, 0.4)
self.assertEqual(s[0].color, QColor(100, 100, 40))
# test info
r.setInfo({'key1': 'val1', 'key2': 'val2'})
self.assertEqual(r.info()['key1'], 'val1')
self.assertEqual(r.info()['key2'], 'val2')
# test creating from properties
props = r.properties()
fromProps = QgsGradientColorRamp.create(props)
self.assertEqual(fromProps.color1(), QColor(0, 0, 200))
self.assertEqual(fromProps.color2(), QColor(0, 0, 100))
s = fromProps.stops()
self.assertEqual(len(s), 1)
self.assertEqual(s[0].offset, 0.4)
c = QColor(s[0].color)
self.assertEqual(c, QColor(100, 100, 40))
self.assertEqual(fromProps.info()['key1'], 'val1')
self.assertEqual(fromProps.info()['key2'], 'val2')
self.assertEqual(fromProps.isDiscrete(), False)
# test cloning ramp
cloned = r.clone()
self.assertEqual(cloned.color1(), QColor(0, 0, 200))
self.assertEqual(cloned.color2(), QColor(0, 0, 100))
s = cloned.stops()
self.assertEqual(len(s), 1)
self.assertEqual(s[0].offset, 0.4)
c = QColor(s[0].color)
self.assertEqual(c, QColor(100, 100, 40))
self.assertEqual(cloned.info()['key1'], 'val1')
self.assertEqual(cloned.info()['key2'], 'val2')
self.assertEqual(cloned.isDiscrete(), False)
# test discrete ramps
# first with no stops
d = QgsGradientColorRamp(QColor(200, 0, 0), QColor(0, 200, 0), True)
self.assertEqual(d.isDiscrete(), True)
self.assertEqual(d.color(0), QColor(200, 0, 0))
self.assertEqual(d.color(0.5), QColor(200, 0, 0))
self.assertEqual(d.color(1), QColor(0, 200, 0))
# then with stops
d = QgsGradientColorRamp(QColor(200, 0, 0), QColor(0, 200, 0), True, [QgsGradientStop(0.1, QColor(180, 20, 40)),
QgsGradientStop(0.9, QColor(40, 60, 100))])
self.assertEqual(d.isDiscrete(), True)
self.assertEqual(d.color(0), QColor(200, 0, 0))
#.........这里部分代码省略.........
示例2: testQgsVectorGradientRampV2
# 需要导入模块: from qgis.PyQt.QtGui import QGradient [as 别名]
# 或者: from qgis.PyQt.QtGui.QGradient import stops [as 别名]
def testQgsVectorGradientRampV2(self):
# test gradient with only start/end color
r = QgsVectorGradientColorRampV2(QColor(200, 0, 0, 100), QColor(0, 200, 0, 200))
self.assertEqual(r.type(), 'gradient')
self.assertEqual(r.color1(), QColor(200, 0, 0, 100))
self.assertEqual(r.color2(), QColor(0, 200, 0, 200))
self.assertEqual(r.isDiscrete(), False)
self.assertEqual(len(r.stops()), 0)
self.assertEqual(r.count(), 2)
self.assertEqual(r.value(0), 0.0)
self.assertEqual(r.value(1), 1.0)
self.assertEqual(r.color(0), QColor(200, 0, 0, 100))
self.assertEqual(r.color(1), QColor(0, 200, 0, 200))
self.assertEqual(r.color(0.5), QColor(100, 100, 0, 150))
# test gradient with stops
r = QgsVectorGradientColorRampV2(QColor(200, 0, 0), QColor(0, 200, 0), False, [QgsGradientStop(0.1, QColor(180, 20, 40)),
QgsGradientStop(0.9, QColor(40, 60, 100))])
self.assertEqual(r.color1(), QColor(200, 0, 0))
self.assertEqual(r.color2(), QColor(0, 200, 0))
self.assertEqual(r.isDiscrete(), False)
self.assertEqual(len(r.stops()), 2)
self.assertEqual(r.count(), 4)
self.assertEqual(r.value(0), 0.0)
self.assertEqual(r.value(1), 0.1)
self.assertEqual(r.value(2), 0.9)
self.assertEqual(r.value(3), 1.0)
self.assertEqual(r.color(0), QColor(200, 0, 0))
self.assertEqual(r.color(0.05), QColor(190, 10, 20))
self.assertEqual(r.color(0.1), QColor(180, 20, 40))
self.assertEqual(r.color(0.5), QColor(110, 40, 70))
self.assertEqual(r.color(0.9), QColor(40, 60, 100))
self.assertEqual(r.color(0.95), QColor(20, 130, 50))
self.assertEqual(r.color(1), QColor(0, 200, 0))
# test setters
r.setColor1(QColor(0, 0, 200))
self.assertEqual(r.color1(), QColor(0, 0, 200))
self.assertEqual(r.color(0), QColor(0, 0, 200))
r.setColor2(QColor(0, 0, 100))
self.assertEqual(r.color2(), QColor(0, 0, 100))
self.assertEqual(r.color(1.0), QColor(0, 0, 100))
r.setStops([QgsGradientStop(0.4, QColor(100, 100, 40))])
s = r.stops()
self.assertEqual(len(s), 1)
self.assertEqual(s[0].offset, 0.4)
self.assertEqual(s[0].color, QColor(100, 100, 40))
# test info
r.setInfo({'key1': 'val1', 'key2': 'val2'})
self.assertEqual(r.info()['key1'], 'val1')
self.assertEqual(r.info()['key2'], 'val2')
# test creating from properties
props = r.properties()
fromProps = QgsVectorGradientColorRampV2.create(props)
self.assertEqual(fromProps.color1(), QColor(0, 0, 200))
self.assertEqual(fromProps.color2(), QColor(0, 0, 100))
s = fromProps.stops()
self.assertEqual(len(s), 1)
self.assertEqual(s[0].offset, 0.4)
c = QColor(s[0].color)
self.assertEqual(c, QColor(100, 100, 40))
self.assertEqual(fromProps.info()['key1'], 'val1')
self.assertEqual(fromProps.info()['key2'], 'val2')
self.assertEqual(fromProps.isDiscrete(), False)
# test cloning ramp
cloned = r.clone()
self.assertEqual(cloned.color1(), QColor(0, 0, 200))
self.assertEqual(cloned.color2(), QColor(0, 0, 100))
s = cloned.stops()
self.assertEqual(len(s), 1)
self.assertEqual(s[0].offset, 0.4)
c = QColor(s[0].color)
self.assertEqual(c, QColor(100, 100, 40))
self.assertEqual(cloned.info()['key1'], 'val1')
self.assertEqual(cloned.info()['key2'], 'val2')
self.assertEqual(cloned.isDiscrete(), False)
# test discrete ramps
# first with no stops
d = QgsVectorGradientColorRampV2(QColor(200, 0, 0), QColor(0, 200, 0), True)
self.assertEqual(d.isDiscrete(), True)
self.assertEqual(d.color(0), QColor(200, 0, 0))
self.assertEqual(d.color(0.5), QColor(200, 0, 0))
self.assertEqual(d.color(1), QColor(0, 200, 0))
# then with stops
d = QgsVectorGradientColorRampV2(QColor(200, 0, 0), QColor(0, 200, 0), True, [QgsGradientStop(0.1, QColor(180, 20, 40)),
QgsGradientStop(0.9, QColor(40, 60, 100))])
self.assertEqual(d.isDiscrete(), True)
self.assertEqual(d.color(0), QColor(200, 0, 0))
self.assertEqual(d.color(0.05), QColor(200, 0, 0))
self.assertEqual(d.color(0.1), QColor(180, 20, 40))
self.assertEqual(d.color(0.5), QColor(180, 20, 40))
self.assertEqual(d.color(0.9), QColor(40, 60, 100))
self.assertEqual(d.color(0.95), QColor(40, 60, 100))
self.assertEqual(d.color(1), QColor(0, 200, 0))
# to gradient
#.........这里部分代码省略.........