本文整理汇总了Python中PyQt4.QtGui.QLinearGradient类的典型用法代码示例。如果您正苦于以下问题:Python QLinearGradient类的具体用法?Python QLinearGradient怎么用?Python QLinearGradient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QLinearGradient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
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())
示例2: updateColor
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))
示例3: createLinearGradient
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
示例4: initialize
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.)
示例5: paintEvent
def paintEvent(self, event):
painter = QPainter()
painter.begin(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.fillRect(event.rect(), QBrush(QColor(255, 255, 255, 127)))
painter.setPen(QPen(Qt.NoPen))
for i in xrange(6):
x_pos = self.width() / 2 + 30 * \
math.cos(2 * math.pi * i / 6.0) - 10
y_pos = self.height() / 2 + 30 * \
math.sin(2 * math.pi * i / 6.0) - 10
if (self.counter / 5) % 6 == i:
linear_gradient = QLinearGradient(
x_pos + 10, x_pos, y_pos + 10, y_pos)
linear_gradient.setColorAt(0, QColor(135, 206, 250))
linear_gradient.setColorAt(1, QColor(0, 0, 128))
painter.setBrush(QBrush(linear_gradient))
else:
linear_gradient = QLinearGradient(
x_pos - 10, x_pos, y_pos + 10, y_pos)
linear_gradient.setColorAt(0, QColor(105, 105, 105))
linear_gradient.setColorAt(1, QColor(0, 0, 0))
painter.setBrush(QBrush(linear_gradient))
painter.drawEllipse(
x_pos,
y_pos,
20, 20)
painter.end()
示例6: palette_gradient
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
示例7: ReflectivityFrame
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
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
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
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
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: get_coloured_root_item
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
示例13: createLinearGradient
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
示例14: paintEvent
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: paintEvent
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))