本文整理汇总了Python中PyQt4.QtGui.QLinearGradient.setFinalStop方法的典型用法代码示例。如果您正苦于以下问题:Python QLinearGradient.setFinalStop方法的具体用法?Python QLinearGradient.setFinalStop怎么用?Python QLinearGradient.setFinalStop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QLinearGradient
的用法示例。
在下文中一共展示了QLinearGradient.setFinalStop方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drawForeground
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setFinalStop [as 别名]
def drawForeground( self, painter, rect ):
"""
Draws the foreground for this scene.
:param painter | <QPainter>
rect | <QRect>
"""
gantt = self.ganttWidget()
header = gantt.treeWidget().header()
width = self.sceneRect().width()
height = header.height()
# create the main color
palette = gantt.palette()
color = palette.color(palette.Button)
textColor = palette.color(palette.ButtonText)
borderColor = color.darker(140)
text_align = Qt.AlignBottom | Qt.AlignHCenter
y = rect.top()
# create the gradient
gradient = QLinearGradient()
gradient.setStart(0, y)
gradient.setFinalStop(0, y + height)
gradient.setColorAt(0, color)
gradient.setColorAt(1, color.darker(120))
painter.setBrush(QBrush(gradient))
painter.drawRect(0, y, width, height)
# add top labels
for rect, label in self._topLabels:
rx = rect.x()
ry = rect.y() + y
rw = rect.width()
rh = rect.height()
painter.setPen(borderColor)
painter.drawRect(rx, ry, rw, rh)
painter.setPen(textColor)
painter.drawText(rx, ry, rw, rh - 2, text_align, label)
# add bottom labels
for rect, label in self._labels:
rx = rect.x()
ry = rect.y() + y
rw = rect.width()
rh = rect.height()
painter.setPen(borderColor)
painter.drawRect(rx, ry, rw, rh)
painter.setPen(textColor)
painter.drawText(rx, ry, rw, rh - 2, text_align, label)
示例2: _gen_striped_gradient
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setFinalStop [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: paint
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setFinalStop [as 别名]
def paint(self, painter, option, widget):
widget = self.scene()._slider
pixmap = self.pixmap()
palette = widget.palette()
base = palette.color(palette.Base)
# draw the reflection
painter.save()
painter.setPen(Qt.NoPen)
transform = painter.transform()
transform.translate(pixmap.width() / 2.0, 0)
transform.rotate(self.angle(), Qt.YAxis)
transform.translate(-pixmap.width() / 2.0, 0)
painter.setTransform(transform)
self.graphicsEffect().setEnabled(self.isSelected())
painter.drawPixmap(0, 0, pixmap)
painter.setBrush(Qt.NoBrush)
painter.setOpacity(0.2)
painter.scale(1, -1)
painter.translate(0, -(pixmap.height()) * 2)
painter.drawPixmap(0, 0, pixmap)
painter.setOpacity(1)
grad = QLinearGradient()
grad.setStart(0, 0)
grad.setFinalStop(0, pixmap.height())
grad.setColorAt(1.0, QColor(0, 0, 0, 0))
grad.setColorAt(0.2, base)
grad.setColorAt(0.0, base)
painter.setBrush(grad)
painter.drawRect(0, 0, pixmap.width(), pixmap.height())
painter.restore()
示例4: drawItem
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setFinalStop [as 别名]
def drawItem(self, item, painter, option):
"""
Draws the inputed item as a bar graph.
:param item | <XChartDatasetItem>
painter | <QPainter>
option | <QStyleOptionGraphicsItem>
"""
dataset = item.dataset()
painter.save()
painter.setRenderHint(painter.Antialiasing)
pen = QPen(dataset.color())
pen.setWidth(0.75)
painter.setPen(pen)
for path in item.buildData('subpaths', []):
gradient = QLinearGradient()
clr = QColor(dataset.color())
clr.setAlpha(220)
gradient.setColorAt(0.0, clr.lighter(180))
gradient.setColorAt(0.1, clr.lighter(160))
gradient.setColorAt(0.25, clr.lighter(140))
gradient.setColorAt(1.0, clr.lighter(125))
if self.orientation() == Qt.Vertical:
gradient.setStart(0, path.boundingRect().bottom())
gradient.setFinalStop(0, path.boundingRect().top())
else:
gradient.setStart(path.boundingRect().left(), 0)
gradient.setFinalStop(path.boundingRect().right(), 0)
painter.setBrush(gradient)
painter.drawPath(path)
painter.restore()
示例5: drawForeground
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setFinalStop [as 别名]
def drawForeground(self, painter, rect):
palette = self._slider.palette()
color = palette.color(palette.Base)
trans = self._slider.viewportTransform()
rect = trans.mapRect(self._slider.rect())
width = rect.width()
rect.setX(abs(rect.x()))
rect.setWidth(width)
clear = QColor(0, 0, 0, 0)
grad = QLinearGradient()
grad.setStart(rect.left(), 0)
grad.setFinalStop(rect.right(), 0)
grad.setColorAt(0.0, color)
grad.setColorAt(0.3, clear)
grad.setColorAt(0.7, clear)
grad.setColorAt(1.0, color)
painter.setBrush(grad)
painter.setPen(Qt.NoPen)
painter.drawRect(rect)
示例6: OWLegendGradient
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setFinalStop [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
示例7: PixmapDial
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setFinalStop [as 别名]
class PixmapDial(QDial):
# enum CustomPaint
CUSTOM_PAINT_NULL = 0
CUSTOM_PAINT_CARLA_WET = 1
CUSTOM_PAINT_CARLA_VOL = 2
CUSTOM_PAINT_CARLA_L = 3
CUSTOM_PAINT_CARLA_R = 4
# enum Orientation
HORIZONTAL = 0
VERTICAL = 1
HOVER_MIN = 0
HOVER_MAX = 9
def __init__(self, parent):
QDial.__init__(self, parent)
self.fPixmap = QPixmap("./bitmaps/dial_01d.png")
self.fPixmapNum = "01"
self.fCustomPaint = self.CUSTOM_PAINT_NULL
self.fHovered = False
self.fHoverStep = self.HOVER_MIN
if self.fPixmap.width() > self.fPixmap.height():
self.fOrientation = self.HORIZONTAL
else:
self.fOrientation = self.VERTICAL
self.fLabel = ""
self.fLabelPos = QPointF(0.0, 0.0)
self.fLabelFont = QFont()
self.fLabelFont.setPointSize(6)
self.fLabelWidth = 0
self.fLabelHeight = 0
self.fLabelGradient = QLinearGradient(0, 0, 0, 1)
if self.palette().window().color().lightness() > 100:
# Light background
c = self.palette().dark().color()
self.fColor1 = c
self.fColor2 = QColor(c.red(), c.green(), c.blue(), 0)
self.fColorT = [self.palette().buttonText().color(), self.palette().mid().color()]
else:
# Dark background
self.fColor1 = QColor(0, 0, 0, 255)
self.fColor2 = QColor(0, 0, 0, 0)
self.fColorT = [Qt.white, Qt.darkGray]
self.updateSizes()
def getSize(self):
return self.fSize
def setCustomPaint(self, paint):
self.fCustomPaint = paint
self.fLabelPos.setY(self.fSize + self.fLabelHeight/2)
self.update()
def setEnabled(self, enabled):
if self.isEnabled() != enabled:
self.fPixmap.load("./bitmaps/dial_%s%s.png" % (self.fPixmapNum, "" if enabled else "d"))
self.updateSizes()
self.update()
QDial.setEnabled(self, enabled)
def setLabel(self, label):
self.fLabel = label
self.fLabelWidth = QFontMetrics(self.fLabelFont).width(label)
self.fLabelHeight = QFontMetrics(self.fLabelFont).height()
self.fLabelPos.setX(float(self.fSize)/2.0 - float(self.fLabelWidth)/2.0)
self.fLabelPos.setY(self.fSize + self.fLabelHeight)
self.fLabelGradient.setColorAt(0.0, self.fColor1)
self.fLabelGradient.setColorAt(0.6, self.fColor1)
self.fLabelGradient.setColorAt(1.0, self.fColor2)
self.fLabelGradient.setStart(0, float(self.fSize)/2.0)
self.fLabelGradient.setFinalStop(0, self.fSize + self.fLabelHeight + 5)
self.fLabelGradientRect = QRectF(float(self.fSize)/8.0, float(self.fSize)/2.0, float(self.fSize*6)/8.0, self.fSize+self.fLabelHeight+5)
self.update()
def setPixmap(self, pixmapId):
self.fPixmapNum = "%02i" % pixmapId
self.fPixmap.load("./bitmaps/dial_%s%s.png" % (self.fPixmapNum, "" if self.isEnabled() else "d"))
if self.fPixmap.width() > self.fPixmap.height():
self.fOrientation = self.HORIZONTAL
else:
self.fOrientation = self.VERTICAL
self.updateSizes()
self.update()
def minimumSizeHint(self):
return QSize(self.fSize, self.fSize)
#.........这里部分代码省略.........
示例8: draw
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setFinalStop [as 别名]
def draw(self, painter, size = None):
"""
:Arguments:
painter : QPainter
Opened painter on which to draw
"""
bounding_rect = QRectF()
position = self.position
transfer_function = self.transfer_function
font = QFont(self.font)
text_color = self.text_color
line_color = self.line_color
line_thickness = self.line_thickness
value_range = self.value_range
if size is None:
viewport = painter.viewport() # viewport rectangle
mat, ok = painter.worldMatrix().inverted()
if not ok:
raise ValueError("Transformation matrix of painter is singular.")
viewport = mat.mapRect(viewport)
else:
viewport = size
# First, prepare the gradient
w = viewport.width()
h = viewport.height()
#print("Size of viewport: {0}x{1}".format(w, h))
gr = QLinearGradient()
nb_values = ceil(w/5.0)
brush_color = QColor()
for i in range(int(nb_values)):
brush_color.setRgbF(*transfer_function.rgba(i/nb_values))
gr.setColorAt(i/nb_values, brush_color)
# Second, find its position
metric = QFontMetricsF(font, painter.device())
font_test = [ str(i)*5 for i in range(10) ]
lim_width = 0
lim_height = 0
for t in font_test:
rect = metric.boundingRect(t)
lim_width = max(lim_width, rect.width())
lim_height = max(lim_height, rect.height())
lim_height *= 3
length = self.scale_length
shift_length = (1-length)/2
width = self.scale_width
shift_width = self.scale_shift_width
delta_value = value_range[1]-value_range[0]
if position == "Top":
scale_rect = QRectF(shift_length*w, shift_width*h, length*w, width*h)
limit_rect(scale_rect, viewport, lim_width, lim_height)
gr.setStart(scale_rect.left(), scale_rect.center().y())
gr.setFinalStop(scale_rect.right(), scale_rect.center().y())
start_pos = scale_rect.bottomLeft()
end_pos = scale_rect.bottomRight()
elif position == "Right":
scale_rect = QRectF((1-shift_width-width)*w, shift_length*h, width*w, length*h)
limit_rect(scale_rect, viewport, lim_width, lim_height)
gr.setStart(scale_rect.center().x(), scale_rect.bottom())
gr.setFinalStop(scale_rect.center().x(), scale_rect.top())
start_pos = scale_rect.bottomLeft()
end_pos = scale_rect.topLeft()
elif position == "Bottom":
scale_rect = QRectF(shift_length*w, (1-shift_width-width)*h, length*w, width*h)
limit_rect(scale_rect, viewport, lim_width, lim_height)
gr.setStart(scale_rect.left(), scale_rect.center().y())
gr.setFinalStop(scale_rect.right(), scale_rect.center().y())
start_pos = scale_rect.topLeft()
end_pos = scale_rect.topRight()
elif position == "Left":
scale_rect = QRectF(shift_width*w, shift_length*h, width*w, length*h)
limit_rect(scale_rect, viewport, lim_width, lim_height)
gr.setStart(scale_rect.center().x(), scale_rect.bottom())
gr.setFinalStop(scale_rect.center().x(), scale_rect.top())
start_pos = scale_rect.bottomRight()
end_pos = scale_rect.topRight()
else:
raise ValueError("Invalid scale position: %s" % position)
shift_pos = (end_pos-start_pos)/delta_value
if position in ["Left", "Right"]:
is_vertical = True
length = scale_rect.height()
else:
is_vertical = False
length = scale_rect.width()
# Get the ticks
ticks = self.selectValues(length, is_vertical, painter)
if len(ticks) == 0:
return
ticks_str, ticks_extra = self._tick2str(ticks)
# Figure the shifts
dist_to_bar = self.text_to_bar
max_width = 0
max_height = 0
for t in ticks_str:
rect = metric.boundingRect(t)
max_width = max(rect.width(), max_width)
max_height = max(rect.height(), max_height)
if position == "Left":
shift_left = dist_to_bar
shift_top = None
#.........这里部分代码省略.........
示例9: GradientLegendItem
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setFinalStop [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
示例10: DigitalPeakMeter
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setFinalStop [as 别名]
#.........这里部分代码省略.........
elif self.fOrientation == self.VERTICAL:
self.fGradientMeter.setColorAt(0.0, Qt.red)
self.fGradientMeter.setColorAt(0.2, Qt.yellow)
self.fGradientMeter.setColorAt(0.4, self.fColorBase)
self.fGradientMeter.setColorAt(0.6, self.fColorBase)
self.fGradientMeter.setColorAt(0.8, self.fColorBase)
self.fGradientMeter.setColorAt(1.0, self.fColorBase)
else:
return qCritical("DigitalPeakMeter::setOrientation(%i) - invalid orientation" % orientation)
self.updateSizes()
def setSmoothRelease(self, value):
if value < 0:
value = 0
elif value > 5:
value = 5
self.fSmoothMultiplier = value
def minimumSizeHint(self):
return QSize(10, 10)
def sizeHint(self):
return QSize(self.fWidth, self.fHeight)
def updateSizes(self):
self.fWidth = self.width()
self.fHeight = self.height()
self.fSizeMeter = 0
if self.fOrientation == self.HORIZONTAL:
self.fGradientMeter.setFinalStop(self.fWidth, 0)
if self.fChannels > 0:
self.fSizeMeter = self.fHeight / self.fChannels
elif self.fOrientation == self.VERTICAL:
self.fGradientMeter.setFinalStop(0, self.fHeight)
if self.fChannels > 0:
self.fSizeMeter = self.fWidth / self.fChannels
def paintEvent(self, event):
painter = QPainter(self)
event.accept()
painter.setPen(Qt.black)
painter.setBrush(Qt.black)
painter.drawRect(0, 0, self.fWidth, self.fHeight)
meterX = 0
painter.setPen(self.fColorBackground)
painter.setBrush(self.fGradientMeter)
for i in range(self.fChannels):
level = self.fChannelsData[i]
if self.fOrientation == self.HORIZONTAL:
value = level * float(self.fWidth)
elif self.fOrientation == self.VERTICAL:
value = float(self.fHeight) - (level * float(self.fHeight))
else:
value = 0.0
示例11: PixmapDial
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setFinalStop [as 别名]
class PixmapDial(QDial):
HORIZONTAL = 0
VERTICAL = 1
CUSTOM_PAINT_CARLA_WET = 1
CUSTOM_PAINT_CARLA_VOL = 2
CUSTOM_PAINT_CARLA_L = 3
CUSTOM_PAINT_CARLA_R = 4
HOVER_MIN = 0
HOVER_MAX = 9
def __init__(self, parent):
QDial.__init__(self, parent)
self.m_pixmap = QPixmap(":/bitmaps/dial_01d.png")
self.m_pixmap_n_str = "01"
self.m_custom_paint = 0
self.m_hovered = False
self.m_hover_step = self.HOVER_MIN
if self.m_pixmap.width() > self.m_pixmap.height():
self.m_orientation = self.HORIZONTAL
else:
self.m_orientation = self.VERTICAL
self.m_label = ""
self.m_label_pos = QPointF(0.0, 0.0)
self.m_label_width = 0
self.m_label_height = 0
self.m_label_gradient = QLinearGradient(0, 0, 0, 1)
if self.palette().window().color().lightness() > 100:
# Light background
self.m_color1 = QColor(100, 100, 100, 255)
self.m_color2 = QColor(0, 0, 0, 0)
self.m_colorT = [self.palette().text().color(), self.palette().mid().color()]
else:
# Dark background
self.m_color1 = QColor(0, 0, 0, 255)
self.m_color2 = QColor(0, 0, 0, 0)
self.m_colorT = [Qt.white, Qt.darkGray]
self.updateSizes()
def getSize(self):
return self.p_size
def setCustomPaint(self, paint):
self.m_custom_paint = paint
self.update()
def setEnabled(self, enabled):
if self.isEnabled() != enabled:
self.m_pixmap.load(":/bitmaps/dial_%s%s.png" % (self.m_pixmap_n_str, "" if enabled else "d"))
self.updateSizes()
self.update()
QDial.setEnabled(self, enabled)
def setLabel(self, label):
self.m_label = label
self.m_label_width = QFontMetrics(self.font()).width(label)
self.m_label_height = QFontMetrics(self.font()).height()
self.m_label_pos.setX((self.p_size / 2) - (self.m_label_width / 2))
self.m_label_pos.setY(self.p_size + self.m_label_height)
self.m_label_gradient.setColorAt(0.0, self.m_color1)
self.m_label_gradient.setColorAt(0.6, self.m_color1)
self.m_label_gradient.setColorAt(1.0, self.m_color2)
self.m_label_gradient.setStart(0, self.p_size / 2)
self.m_label_gradient.setFinalStop(0, self.p_size + self.m_label_height + 5)
self.m_label_gradient_rect = QRectF(self.p_size * 1 / 8, self.p_size / 2, self.p_size * 6 / 8, self.p_size + self.m_label_height + 5)
self.update()
def setPixmap(self, pixmap_id):
if pixmap_id > 10:
self.m_pixmap_n_str = str(pixmap_id)
else:
self.m_pixmap_n_str = "0%i" % pixmap_id
self.m_pixmap.load(":/bitmaps/dial_%s%s.png" % (self.m_pixmap_n_str, "" if self.isEnabled() else "d"))
if self.m_pixmap.width() > self.m_pixmap.height():
self.m_orientation = self.HORIZONTAL
else:
self.m_orientation = self.VERTICAL
self.updateSizes()
self.update()
def minimumSizeHint(self):
return QSize(self.p_size, self.p_size)
def sizeHint(self):
return QSize(self.p_size, self.p_size)
#.........这里部分代码省略.........
示例12: DigitalPeakMeter
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setFinalStop [as 别名]
#.........这里部分代码省略.........
self.m_gradientMeter.setColorAt(0.0, Qt.red)
self.m_gradientMeter.setColorAt(0.2, Qt.yellow)
self.m_gradientMeter.setColorAt(0.4, self.m_colorBase)
self.m_gradientMeter.setColorAt(0.6, self.m_colorBase)
self.m_gradientMeter.setColorAt(0.8, self.m_colorBase)
self.m_gradientMeter.setColorAt(1.0, self.m_colorBase)
self.updateSizes()
def setRefreshRate(self, rate):
self.m_paintTimer.stop()
self.m_paintTimer.setInterval(rate)
self.m_paintTimer.start()
def setSmoothRelease(self, value):
if value < 0:
value = 0
elif value > 5:
value = 5
self.m_smoothMultiplier = value
def minimumSizeHint(self):
return QSize(30, 30)
def sizeHint(self):
return QSize(self.m_width, self.m_height)
def updateSizes(self):
self.m_width = self.width()
self.m_height = self.height()
self.m_sizeMeter = 0
if self.m_orientation == self.HORIZONTAL:
self.m_gradientMeter.setFinalStop(self.m_width, 0)
if self.m_channels > 0:
self.m_sizeMeter = self.m_height / self.m_channels
elif self.m_orientation == self.VERTICAL:
self.m_gradientMeter.setFinalStop(0, self.m_height)
if self.m_channels > 0:
self.m_sizeMeter = self.m_width / self.m_channels
self.update()
def paintEvent(self, event):
painter = QPainter(self)
painter.setPen(Qt.black)
painter.setBrush(Qt.black)
painter.drawRect(0, 0, self.m_width, self.m_height)
meter_x = 0
for i in range(self.m_channels):
level = self.m_channels_data[i]
if level == self.m_lastValueData[i]:
continue
if self.m_orientation == self.HORIZONTAL:
value = level * self.m_width
elif self.m_orientation == self.VERTICAL:
value = float(self.m_height) - (level * self.m_height)
else:
value = 0.0
示例13: paintEvent
# 需要导入模块: from PyQt4.QtGui import QLinearGradient [as 别名]
# 或者: from PyQt4.QtGui.QLinearGradient import setFinalStop [as 别名]
def paintEvent(self, event):
"""
Paints the background for the dock toolbar.
:param event | <QPaintEvent>
"""
x = 1
y = 1
w = self.width()
h = self.height()
clr_a = QColor(220, 220, 220)
clr_b = QColor(190, 190, 190)
grad = QLinearGradient()
grad.setColorAt(0.0, clr_a)
grad.setColorAt(0.6, clr_a)
grad.setColorAt(1.0, clr_b)
# adjust the coloring for the horizontal toolbar
if self.position() & (self.Position.North | self.Position.South):
h = self.minimumPixmapSize().height() + 6
if self.position() == self.Position.South:
y = self.height() - h
grad.setStart(0, y)
grad.setFinalStop(0, self.height())
else:
grad.setStart(0, 0)
grad.setFinalStart(0, h)
# adjust the coloring for the vertical toolbar
if self.position() & (self.Position.East | self.Position.West):
w = self.minimumPixmapSize().width() + 6
if self.position() == self.Position.West:
x = self.width() - w
grad.setStart(x, 0)
grad.setFinalStop(self.width(), 0)
else:
grad.setStart(0, 0)
grad.setFinalStop(w, 0)
painter = QPainter(self)
painter.fillRect(x, y, w, h, grad)
# show the active action
action = self.selectedAction()
if action is not None and \
not self.currentAction() and \
not self._animating:
for lbl in self.actionLabels():
if lbl.action() != action:
continue
geom = lbl.geometry()
size = lbl.pixmapSize()
if self.position() == self.Position.North:
x = geom.left()
y = 0
w = geom.width()
h = size.height() + geom.top() + 2
elif self.position() == self.Position.East:
x = 0
y = geom.top()
w = size.width() + geom.left() + 2
h = geom.height()
painter.setPen(QColor(140, 140, 40))
painter.setBrush(QColor(160, 160, 160))
painter.drawRect(x, y, w, h)
break