本文整理汇总了Python中PyQt4.QtGui.QLinearGradient.setSpread方法的典型用法代码示例。如果您正苦于以下问题:Python QLinearGradient.setSpread方法的具体用法?Python QLinearGradient.setSpread怎么用?Python QLinearGradient.setSpread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QLinearGradient
的用法示例。
在下文中一共展示了QLinearGradient.setSpread方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drawLineSection
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setSpread [as 别名]
def drawLineSection(self, painter, firstP, secondP, firstCorner, secondCorner):
direction = self.getPointToPointDirection(firstP, secondP)
thickness = self.CONNECTION_THICKNESS * self.zoomFactor()
halfthick = thickness / 2
cornerRoundness = halfthick ** 0.5
cornerOffset = halfthick * cornerRoundness * (4 * self.zoomFactor()**2)
innerCorner = halfthick * (cornerRoundness + 1)
outerCorner = halfthick * (cornerRoundness - 1)
rect = self.getRectBetweenTwoPoints(firstP, secondP, firstCorner, secondCorner)
# Paint witch color gradient (PyQt4)
if direction == self.ConnectionDirection.LEFT: # horizontal, negative
brush = QLinearGradient(rect.x(), rect.y(), rect.x(), rect.y() + halfthick)
elif direction == self.ConnectionDirection.RIGHT: # horizontal, positive
brush = QLinearGradient(rect.x(), rect.y(), rect.x(), rect.y() + halfthick)
elif direction == self.ConnectionDirection.UP: # vertical, negative
brush = QLinearGradient(rect.x(), rect.y(), rect.x() + halfthick, rect.y())
elif direction == self.ConnectionDirection.DOWN: # vertical, positive
brush = QLinearGradient(rect.x(), rect.y(), rect.x() + halfthick, rect.y())
brush.setSpread(QLinearGradient.ReflectSpread)
brush.setColorAt(0, self.FILL_COLOR1)
brush.setColorAt(1, self.FILL_COLOR2)
painter.setBrush(brush)
painter.drawRect(rect)
示例2: _gen_striped_gradient
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setSpread [as 别名]
def _gen_striped_gradient(basecolor):
"""Just generate a standard gradient, for use as a background"""
g = QLinearGradient()
g.setSpread(g.ReflectSpread)
g.setStart(0,0)
g.setFinalStop(2, 2)
g.setColorAt(0.0, QColor(basecolor))
g.setColorAt(0.35, QColor(0,0,0,0))
g.setColorAt(0.75, QColor(0,0,0,0))
g.setColorAt(1.0, QColor(basecolor))
return g
示例3: drawSection
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setSpread [as 别名]
def drawSection(self, painter, sectionIndex):
""" This is going to replace drawLineSection
"""
firstP = self.mapFromParent(self._route[sectionIndex])
secondP = self.mapFromParent(self._route[sectionIndex +1])
direction = self.getPointToPointDirection(firstP, secondP)
if self.CONNECTION_TYPE!="ORTHOGONAL" or direction == self.ConnectionDirection.UNDEFINED:
self.drawStraightLine(painter, firstP, secondP)
return
previousP = None
nextP = None
if sectionIndex == 0:
lastDirection = self.sourceDirection()
else:
previousP = self.mapFromParent(self._route[sectionIndex -1])
lastDirection = self.getPointToPointDirection(previousP, firstP)
if sectionIndex > len(self._route) -3:
nextDirection = self.targetDirection()
else:
nextP = self.mapFromParent(self._route[sectionIndex +2])
nextDirection = self.getPointToPointDirection(secondP, nextP)
firstCorner = self.getCornerType(lastDirection, direction)
secondCorner = self.getCornerType(direction, nextDirection)
minDist = self.CONNECTION_THICKNESS * self.zoomFactor() * 4
maxRadius = None
if previousP:
xDist = abs(firstP.x() - previousP.x())
yDist = abs(firstP.y() - previousP.y())
if xDist > 0 and xDist < minDist:
maxRadius = 0.5 * xDist
elif yDist > 0 and yDist < minDist:
maxRadius = 0.5 * yDist
xDist = abs(firstP.x() - secondP.x())
yDist = abs(firstP.y() - secondP.y())
if xDist > 0 and xDist < minDist:
maxRadius = 0.5 * xDist
elif yDist > 0 and yDist < minDist:
maxRadius = 0.5 * yDist
#if maxRadius:
self.drawCorner(painter, firstP, firstCorner, maxRadius)
# print "_____________________ darawSection _______________________"
# print "firstP", firstP
# print "secondP", secondP
# print "lastDirection", self.connectionDirectionString(lastDirection)
# print " firstCorner", self.cornerTypeString(firstCorner)
# print "direction", self.connectionDirectionString(direction)
# print " secondCorner", self.cornerTypeString(secondCorner)
# print "nextDirection", self.connectionDirectionString(nextDirection)
# print "\n\n"
thickness = self.CONNECTION_THICKNESS * self.zoomFactor()
halfthick = thickness / 2
cornerRoundness = halfthick ** 0.5
cornerOffset = halfthick * cornerRoundness * (4 * self.zoomFactor()**2)
innerCorner = halfthick * (cornerRoundness + 1)
outerCorner = halfthick * (cornerRoundness - 1)
rect = self.getRectBetweenTwoPoints(firstP, secondP, firstCorner, secondCorner)
# Paint witch color gradient (PyQt4)
if direction == self.ConnectionDirection.LEFT: # horizontal, negative
brush = QLinearGradient(rect.x(), rect.y(), rect.x(), rect.y() + halfthick)
elif direction == self.ConnectionDirection.RIGHT: # horizontal, positive
brush = QLinearGradient(rect.x(), rect.y(), rect.x(), rect.y() + halfthick)
elif direction == self.ConnectionDirection.UP: # vertical, negative
brush = QLinearGradient(rect.x(), rect.y(), rect.x() + halfthick, rect.y())
elif direction == self.ConnectionDirection.DOWN: # vertical, positive
brush = QLinearGradient(rect.x(), rect.y(), rect.x() + halfthick, rect.y())
else:
# Should already be drawn above --> direction == self.ConnectionDirection.UNDEFINED
return
if painter.redirected(painter.device()):
# e.q. QPixmap.grabWidget()
painter.setBrush(self.FILL_COLOR1)
else:
brush.setSpread(QLinearGradient.ReflectSpread)
brush.setColorAt(0, self.FILL_COLOR1)
brush.setColorAt(1, self.FILL_COLOR2)
painter.setBrush(brush)
painter.drawRect(rect)