本文整理汇总了Python中PyQt4.QtGui.QLinearGradient.setStops方法的典型用法代码示例。如果您正苦于以下问题:Python QLinearGradient.setStops方法的具体用法?Python QLinearGradient.setStops怎么用?Python QLinearGradient.setStops使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QLinearGradient
的用法示例。
在下文中一共展示了QLinearGradient.setStops方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: palette_gradient
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setStops [as 别名]
def palette_gradient(colors, discrete=False):
n = len(colors)
stops = numpy.linspace(0.0, 1.0, n, endpoint=True)
gradstops = [(float(stop), color) for stop, color in zip(stops, colors)]
grad = QLinearGradient(QPointF(0, 0), QPointF(1, 0))
grad.setStops(gradstops)
return grad
示例2: create_gradient
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setStops [as 别名]
def create_gradient(base_color, stop=QPointF(0, 0),
finalStop=QPointF(0, 1)):
"""
Create a default linear gradient using `base_color` .
"""
grad = QLinearGradient(stop, finalStop)
grad.setStops([(0.0, base_color),
(0.5, base_color),
(0.8, base_color.darker(105)),
(1.0, base_color.darker(110)),
])
grad.setCoordinateMode(QLinearGradient.ObjectBoundingMode)
return grad
示例3: OWLegendGradient
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setStops [as 别名]
class OWLegendGradient(QGraphicsObject):
gradient_width = 20
def __init__(self, palette, values, parent):
QGraphicsObject.__init__(self, parent)
self.parent = parent
self.palette = palette
self.values = values
self.legend = parent
self.label_items = [QGraphicsTextItem(text, self) for text in values]
for i in self.label_items:
i.setTextWidth(50)
self.rect = QRectF()
self.gradient_item = QGraphicsRectItem(self)
self.gradient = QLinearGradient()
self.gradient.setStops([(v*0.1, self.palette[v*0.1]) for v in range(11) ])
self.orientation = Qt.Horizontal
self.set_orientation(Qt.Vertical)
def set_orientation(self, orientation):
if self.orientation == orientation:
return
self.orientation = orientation
if self.orientation == Qt.Vertical:
height = max([item.boundingRect().height() for item in self.label_items])
total_height = height * max(5, len(self.label_items))
interval = (total_height - self.label_items[-1].boundingRect().height()) / (len(self.label_items) -1)
self.gradient_item.setRect(10, 0, self.gradient_width, total_height)
self.gradient.setStart(10, 0)
self.gradient.setFinalStop(10, total_height)
self.gradient_item.setBrush(QBrush(self.gradient))
self.gradient_item.setPen(QPen(Qt.NoPen))
y = 0
x = 30
for item in self.label_items:
move_item_xy(item, x, y, self.parent.graph.animate_plot)
y += interval
self.rect = QRectF(10, 0, self.gradient_width + max([item.boundingRect().width() for item in self.label_items]), self.label_items[0].boundingRect().height() * max(5, len(self.label_items)))
else:
width = 50
height = max([item.boundingRect().height() for item in self.label_items])
total_width = width * max(5, len(self.label_items))
interval = (total_width - self.label_items[-1].boundingRect().width()) / (len(self.label_items) -1)
self.gradient_item.setRect(0, 0, total_width, self.gradient_width)
self.gradient.setStart(0, 0)
self.gradient.setFinalStop(total_width, 0)
self.gradient_item.setBrush(QBrush(self.gradient))
self.gradient_item.setPen(QPen(Qt.NoPen))
x = 0
y = 30
for item in self.label_items:
move_item_xy(item, x, y, self.parent.graph.animate_plot)
x += interval
self.rect = QRectF(0, 0, total_width, self.gradient_width + height)
def boundingRect(self):
return getattr(self, 'rect', QRectF())
def paint(self, painter, option, widget):
pass
示例4: GradientLegendItem
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setStops [as 别名]
class GradientLegendItem(QGraphicsObject, GraphicsWidgetAnchor):
gradient_width = 20
def __init__(self, title, palette, values, parent):
QGraphicsObject.__init__(self, parent)
GraphicsWidgetAnchor.__init__(self)
self.parent = self.legend = parent
self.palette = palette
self.values = values
self.title = QGraphicsTextItem('%s:' % title, self)
f = self.title.font()
f.setBold(True)
self.title.setFont(f)
self.title_item = QGraphicsRectItem(self.title.boundingRect(), self)
self.title_item.setPen(QPen(Qt.NoPen))
self.title_item.stackBefore(self.title)
self.label_items = [QGraphicsTextItem(text, self) for text in values]
for i in self.label_items:
i.setTextWidth(50)
self.rect = QRectF()
self.gradient_item = QGraphicsRectItem(self)
self.gradient = QLinearGradient()
self.gradient.setStops([(v * 0.1, self.palette[v * 0.1])
for v in range(11)])
self.orientation = Qt.Horizontal
self.set_orientation(Qt.Vertical)
self.setFlag(QGraphicsItem.ItemIgnoresTransformations, True)
self.setFlag(QGraphicsItem.ItemIsMovable, True)
def set_orientation(self, orientation):
return
if self.orientation == orientation:
return
self.orientation = orientation
if self.orientation == Qt.Vertical:
height = max(item.boundingRect().height()
for item in self.label_items)
total_height = height * max(5, len(self.label_items))
interval = (total_height -
self.label_items[-1].boundingRect().height()
) / (len(self.label_items) - 1)
self.gradient_item.setRect(10, 0, self.gradient_width, total_height)
self.gradient.setStart(10, 0)
self.gradient.setFinalStop(10, total_height)
self.gradient_item.setBrush(QBrush(self.gradient))
self.gradient_item.setPen(QPen(Qt.NoPen))
y = -20 # hja, no; dela --> pri boundingRect() zato pristejem +20
x = 0
move_item_xy(self.title, x, y, False)
y = 10
x = 30
for item in self.label_items:
move_item_xy(item, x, y, False)
# self.parent.graph.animate_plot)
y += interval
self.rect = QRectF(10, 0,
self.gradient_width +
max(item.boundingRect().width()
for item in self.label_items),
self.label_items[0].boundingRect().height() *
max(5, len(self.label_items)))
else:
# za horizontalno orientacijo nisem dodajal title-a
width = 50
height = max(item.boundingRect().height()
for item in self.label_items)
total_width = width * max(5, len(self.label_items))
interval = (total_width -
self.label_items[-1].boundingRect().width()
) / (len(self.label_items) - 1)
self.gradient_item.setRect(0, 0, total_width, self.gradient_width)
self.gradient.setStart(0, 0)
self.gradient.setFinalStop(total_width, 0)
self.gradient_item.setBrush(QBrush(self.gradient))
self.gradient_item.setPen(QPen(Qt.NoPen))
x = 0
y = 30
for item in self.label_items:
move_item_xy(item, x, y, False)
# self.parent.graph.animate_plot)
x += interval
self.rect = QRectF(0, 0, total_width, self.gradient_width + height)
# noinspection PyPep8Naming
def boundingRect(self):
width = max(self.rect.width(), self.title_item.boundingRect().width())
height = self.rect.height() + self.title_item.boundingRect().height()
return QRectF(self.rect.left(), self.rect.top(), width, height)
def paint(self, painter, option, widget):
pass