本文整理汇总了Python中PyQt4.QtGui.QLinearGradient.setColorAt方法的典型用法代码示例。如果您正苦于以下问题:Python QLinearGradient.setColorAt方法的具体用法?Python QLinearGradient.setColorAt怎么用?Python QLinearGradient.setColorAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QLinearGradient
的用法示例。
在下文中一共展示了QLinearGradient.setColorAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updateColor
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setColorAt [as 别名]
def updateColor(self):
"""
Update the color on the sampleModel
modify to fit to the actual view
"""
if not self.view.sampleTableView.selectedIndexes():#not self.acTree.selectedIndexes():
return
idx = self.view.sampleTableView.selectedIndexes()[0]
sample = self.model.sample(idx.data().toString(), fullNameEntry=False)
if sample is None:
self.view.showErrorMessage('Error', 'Please choose only one file...')
return
color = QColorDialog.getColor()
if not color.isValid():
return
sample.color=color.getRgbF()[:-1]
#make the gradient color here to
color =QColor.fromRgbF(*(sample.color+(1.,)))
colorr=QColor.fromRgbF(*(sample.color+(.5,)))
gradient=QLinearGradient(-100, -100, 100, 100)
gradient.setColorAt(0.7, colorr)
gradient.setColorAt(1, color)
#for m in (self.view.sampleModel, self.view.spectraModel, self.view.peakModel,
# self.view.clusterModel):#self.view.chromaModel,
for i in xrange(self.view.sampleModel.rowCount()):
item=self.view.sampleModel.item(i,0)
if item.text()== sample.shortName():
item.setBackground(QBrush(gradient))
示例2: paintEvent
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setColorAt [as 别名]
def paintEvent(self, e):
"""
Paint the horizontal handle as a gradient, paint
the vertical handle as a line.
"""
painter = QPainter(self)
topColor = QColor(145, 145, 145)
bottomColor = QColor(142, 142, 142)
gradientStart = QColor(252, 252, 252)
gradientStop = QColor(223, 223, 223)
if self.orientation() == Qt.Vertical:
painter.setPen(topColor)
painter.drawLine(0, 0, self.width(), 0)
painter.setPen(bottomColor)
painter.drawLine(0, self.height() - 1, self.width(), self.height() - 1)
linearGrad = QLinearGradient(QPointF(0, 0), QPointF(0, height() - 3))
linearGrad.setColorAt(0, gradientStart)
linearGrad.setColorAt(1, gradientStop)
painter.fillRect(QRect(QPoint(0, 1), self.size() - QSize(0, 2)), QBrush(linearGrad))
else:
painter.setPen(topColor)
painter.drawLine(0, 0, 0, self.height())
示例3: drawLineSection
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setColorAt [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)
示例4: gradient_darker
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setColorAt [as 别名]
def gradient_darker(grad, factor):
"""Return a copy of the QGradient darkened by factor.
.. note:: Only QLinearGradeint and QRadialGradient are supported.
"""
if type(grad) is QGradient:
if grad.type() == QGradient.LinearGradient:
grad = sip.cast(grad, QLinearGradient)
elif grad.type() == QGradient.RadialGradient:
grad = sip.cast(grad, QRadialGradient)
if isinstance(grad, QLinearGradient):
new_grad = QLinearGradient(grad.start(), grad.finalStop())
elif isinstance(grad, QRadialGradient):
new_grad = QRadialGradient(grad.center(), grad.radius(),
grad.focalPoint())
else:
raise TypeError
new_grad.setCoordinateMode(grad.coordinateMode())
for pos, color in grad.stops():
new_grad.setColorAt(pos, color.darker(factor))
return new_grad
示例5: createLinearGradient
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setColorAt [as 别名]
def createLinearGradient(self, itemRect, startColor, endColor):
start = QPointF(itemRect.left(), itemRect.top())
stop = QPointF(itemRect.right(), itemRect.bottom())
linearGradient = QLinearGradient(start, stop)
linearGradient.setColorAt(0, startColor)
linearGradient.setColorAt(1, endColor)
return linearGradient
示例6: initialize
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setColorAt [as 别名]
def initialize(self, points, show_fresnel, frequency):
self.pts = {
PT1: points[0],
PT2: points[-1]
}
self.fresnel_visible = show_fresnel
self.frequency = frequency
# Construct static geometry to be included in the scene
path = self.path_for(points)
height = path.boundingRect().height()
gradient = QLinearGradient(QPointF(0., height), QPointF(0., 0.))
gradient.setColorAt(0, QColor(0x00b300))
gradient.setColorAt(1, QColor(0x331a00))
# Create the scene
self.scene = QGraphicsScene(self.dialog)
# Add geometries to the scene, keeping a reference to each
self.path = self.scene.addPath(path, QPen(Qt.blue, 1), QBrush(gradient))
# Update the scene; i.e. correct pen-colours etc.
self.update_scene(add_geometries=True)
# Set up the view with the constructed scene
self.view.setScene(self.scene)
self.view.ensureVisible(self.scene.sceneRect())
self.view.scale(1., -1.)
示例7: ReflectivityFrame
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setColorAt [as 别名]
class ReflectivityFrame(QFrame):
SIZE_X = 400
SIZE_Y = 100
def __init__(self, parent=None):
QFrame.__init__(self, parent)
self.reflectivity = 0
self.setMinimumSize(self.SIZE_X, self.SIZE_Y)
self.setMaximumSize(self.SIZE_X, self.SIZE_Y)
self.gradient = QLinearGradient(0.0, 0.0, 0.0, self.SIZE_Y)
self.gradient.setColorAt(0, Qt.white)
self.gradient.setColorAt(1, Qt.black)
def set_reflectivity(self, r):
self.reflectivity = self.SIZE_Y - r*self.SIZE_Y/4095.0
self.repaint()
def paintEvent(self, event):
qp = QPainter()
qp.begin(self)
qp.setBrush(self.gradient)
qp.setPen(Qt.transparent)
qp.drawRect(0, 0, self.SIZE_X, self.SIZE_Y)
qp.setBrush(QBrush(Qt.red))
qp.setPen(Qt.red)
qp.drawLine(0, self.reflectivity, self.SIZE_X, self.reflectivity)
qp.end()
示例8: drawSpan
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setColorAt [as 别名]
def drawSpan(self, painter, rect):
opt = QStyleOptionSlider()
QSlider.initStyleOption(self, opt)
# area
groove = self.style().subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderGroove, self)
if opt.orientation == QtCore.Qt.Horizontal:
groove.adjust(0, 0, -1, 0)
else:
groove.adjust(0, 0, 0, -1)
# pen & brush
painter.setPen(QPen(self.gradientLeftColor, 0))
if opt.orientation == QtCore.Qt.Horizontal:
self.setupPainter(painter, opt.orientation, groove.center().x(),
groove.top(), groove.center().x(),
groove.bottom())
else:
self.setupPainter(painter, opt.orientation, groove.left(),
groove.center().y(), groove.right(),
groove.center().y())
# draw groove
intersected = QtCore.QRectF(rect.intersected(groove))
gradient = QLinearGradient(intersected.topLeft(), intersected.topRight())
gradient.setColorAt(0, self.gradientLeft)
gradient.setColorAt(1, self.gradientRight)
painter.fillRect(intersected, gradient)
示例9: paintEvent
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setColorAt [as 别名]
def paintEvent(self, event):
"""This function create gradient background"""
painter = QPainter(self)
gradient = QLinearGradient(QPointF(100, 0), QPointF(100, 100))
gradient.setColorAt(1, QColor(COLOR_SCHEME['server_widget_bg1']))
gradient.setColorAt(0, QColor(COLOR_SCHEME['server_widget_bg2']))
painter.fillRect(self.rect(), gradient)
示例10: paintEvent
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setColorAt [as 别名]
def paintEvent(self,event):
titleHeight = 40
bottomHeight = 50
#画标题背景
painter = QPainter(self)
painter.save()
linearGradient = QLinearGradient(0, 0,0,titleHeight)
linearGradient.setColorAt(0, QColor(60,150,255))
linearGradient.setColorAt(0.1, QColor(6,88,200))
linearGradient.setColorAt(1, QColor(80,150,255))
painter.setBrush(QBrush(linearGradient))
contenRect = QRect(0, 0, self.width(), titleHeight)
painter.fillRect(contenRect, QBrush(linearGradient))
painter.restore()
#画标题内容
painter.save()
painter.setPen(QPen(QColor(255, 255, 255),1))
font = painter.font()
font.setPointSize(12)
painter.setFont(font)
painter.drawText(QPoint(10,25), self.title)
painter.restore()
#画中间白色背景
painter.save()
painter.setPen(QPen(QColor(255, 255, 255),1))
brush = QBrush(QColor(242,242,242))
painter.setBrush(brush)
contenRect = QRect(0, titleHeight, self.width()-1, self.height() - titleHeight - bottomHeight)
# painter.fillRect(contenRect, brush)
painter.drawRect(contenRect)
painter.restore()
#画提示信息内容
painter.save()
painter.setPen(QPen(QColor(1, 1, 1),1))
font = painter.font()
font.setPointSize(15)
painter.setFont(font)
fm = QFontMetrics(font)
infoWidth = fm.width(self.hintInfo)
painter.drawText(QPoint((self.width() - infoWidth - 10)/2, 150), self.hintInfo)
painter.restore()
#画底层背景
painter.save()
brush = QBrush(QColor(219,234,255))
painter.setBrush(brush)
contenRect = QRect(0, self.height() - bottomHeight, self.width(), bottomHeight)
painter.fillRect(contenRect, brush)
painter.restore()
示例11: __gradient
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setColorAt [as 别名]
def __gradient(self):
left = QPointF(self.contentsRect().topLeft())
right = QPointF(self.contentsRect().topRight())
gradient = QLinearGradient(left, right)
gradient.setColorAt(0.9, self.palette().color(QPalette.WindowText))
gradient.setColorAt(1.0, self.palette().color(QPalette.Window))
pen = QPen()
pen.setBrush(QBrush(gradient))
return pen
示例12: createLinearGradient
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setColorAt [as 别名]
def createLinearGradient(self, itemRect, startColor, endColor):
'''
Creates linear gradient starting from top left to bottom right
'''
start = QPointF(itemRect.left(), itemRect.top())
stop = QPointF(itemRect.right(), itemRect.bottom())
linearGradient = QLinearGradient(start, stop)
linearGradient.setColorAt(0, startColor)
linearGradient.setColorAt(1, endColor)
return linearGradient
示例13: paintEvent
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setColorAt [as 别名]
def paintEvent(self, _):
p = QPainter(self)
points = [QPoint(self.width(), -1), QPoint(self.width(), self.height()),
QPoint(0, self.height() / 2), QPoint(0, self.height() / 2 - 1)]
grad = QLinearGradient(0, 0, 0, self.height())
grad.setColorAt(0, self.color1)
grad.setColorAt(1, self.color2)
p.setBrush(grad)
p.setPen(QPen(Qt.NoPen))
p.drawPolygon(QPolygon(points))
示例14: paintEvent
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setColorAt [as 别名]
def paintEvent(self, event):
painter = QPainter(self)
font_metrics = QFontMetrics(self.font())
if font_metrics.width(self.text()) > self.contentsRect().width():
label_width = self.size().width()
gradient = QLinearGradient(0, 0, label_width, 0)
gradient.setColorAt(1-50.0/label_width, self.palette().color(self.foregroundRole()))
gradient.setColorAt(1.0, Qt.transparent)
painter.setPen(QPen(QBrush(gradient), 1.0))
painter.drawText(self.contentsRect(), Qt.TextSingleLine | int(self.alignment()), self.text())
示例15: get_coloured_root_item
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setColorAt [as 别名]
def get_coloured_root_item(filepath, color, colorr):
root = QStandardItem(filepath)
gradient = QLinearGradient(-100, -100, 100, 100)
gradient.setColorAt(0.7, colorr)
gradient.setColorAt(1, color)
root.setBackground(QBrush(gradient))
root.setEditable(False)
root.setCheckState(Qt.Checked)
root.setCheckable(True)
return root