本文整理汇总了Python中PySide.QtGui.QPainter.setOpacity方法的典型用法代码示例。如果您正苦于以下问题:Python QPainter.setOpacity方法的具体用法?Python QPainter.setOpacity怎么用?Python QPainter.setOpacity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QPainter
的用法示例。
在下文中一共展示了QPainter.setOpacity方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setOpacity [as 别名]
def paintEvent(self, pe):
# make an arrow polygon right in the middle
painter = QPainter(self)
painter.setPen(Qt.NoPen)
# draw the background transparent rect
painter.save()
painter.setOpacity(self.BACKGROUND_OPACITY)
# get the rectangle coordinates it should extend over the whole width with only a portion at the center
painter.setBrush(Qt.black)
empty_space_percent = 1 - self.BACKROUND_HEIGHT_PERCENT
rect_top = empty_space_percent / 2 * self.height()
rect_height = self.BACKROUND_HEIGHT_PERCENT * self.height()
painter.drawRect(0, rect_top, self.width(), rect_height)
painter.restore()
painter.setRenderHint(QPainter.Antialiasing)
pen = QPen()
pen.setWidth(self.ARROW_LINE_WIDTH)
pen.setCapStyle(Qt.RoundCap)
if self._mouse_inside:
pen.setColor(self._hover_color)
else:
pen.setColor(self._normal_color)
# get the arrow coords
painter.setPen(pen)
self_center = QPointF(self.width() / 2, self.height() / 2) # use this as the arrow tip for now
if self._direction == self.LEFT:
h_shift = self._arrow_width
elif self._direction == self.RIGHT:
h_shift = - self._arrow_width
v_shift = self._arrow_height / 2
top_point = self_center + QPointF(h_shift, - v_shift)
bottom_point = self_center + QPointF(h_shift, v_shift)
painter.drawLine(top_point, self_center)
painter.drawLine(self_center, bottom_point)
示例2: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setOpacity [as 别名]
def paintEvent(self, paintEvent):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.scale(self.scale, self.scale)
painter.drawRect(0, 0, 511, 511)
painter.drawImage(0, 0, self.image)
if self.freeze_image is not None and self.freeze_image is not self.image:
painter.setOpacity(0.3)
painter.drawImage(0, 0, self.freeze_image)
示例3: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setOpacity [as 别名]
def paintEvent(self, pe):
painter = QPainter(self)
icon = QPixmap(self._icon)
icon = icon.scaled(self.size(), Qt.IgnoreAspectRatio)
if not self._mouse_over or not self._enabled:
painter.setOpacity(self._normal_opacity)
else:
painter.setOpacity(self._hover_opacity)
painter.drawPixmap(0, 0, icon)
示例4: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setOpacity [as 别名]
def paintEvent(self, pe):
super(ProgressLineEdit, self).paintEvent(pe)
painter = QPainter(self)
painter.setOpacity(self.property("_progress_opacity"))
sopb = QStyleOptionProgressBarV2()
sopb.minimum = 0
sopb.maximum = 100
sopb.progress = self._progress
sopb.initFrom(self)
self.style().drawControl(QStyle.CE_ProgressBarContents, sopb, painter, self)
示例5: drawPreview
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setOpacity [as 别名]
def drawPreview(self, endPoint_x, endPoint_y):
painter = QPainter(self.imagePreview)
painter.setPen(QPen(
self.myPenColor,
self.myPenWidth,
QtCore.Qt.SolidLine,
QtCore.Qt.RoundCap,
QtCore.Qt.RoundJoin))
painter.setClipping(True)
painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
painter.setRenderHint(QPainter.HighQualityAntialiasing, True)
painter.setRenderHint(QPainter.Antialiasing, True)
painter.setOpacity(0.5)
if self.tools['circle']:
x1 = self.firstPoint_x
y1 = self.firstPoint_y
x2 = endPoint_x
y2 = endPoint_y
painter.drawEllipse(x1, y1, (x2 - x1), (y2 - y1))
if self.tools['line']:
painter.drawLine(
self.firstPoint_x, self.firstPoint_y, endPoint_x, endPoint_y)
if self.tools['rect']:
painter.drawRect(
self.firstPoint_x, self.firstPoint_y,
endPoint_x - self.firstPoint_x,
endPoint_y - self.firstPoint_y)
if self.tools['roundRect']:
x1 = self.firstPoint_x
y1 = self.firstPoint_y
dx = endPoint_x - self.firstPoint_x
dy = endPoint_y - self.firstPoint_y
if x1 > endPoint_x and y1 > endPoint_y:
painter.drawRoundedRect(
endPoint_x, endPoint_y, -dx, -dy, 20, 20, 0)
else:
painter.drawRoundedRect(x1, y1, dx, dy, 20., 20.)
self.update()
示例6: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setOpacity [as 别名]
def paintEvent(self, event):
"""Display a translucent rounded rectangle."""
roundness = 10
rect = self.rect()
bgcolor = self.palette().color(QPalette.Background)
alpha_bgcolor = QColor(50, 50, 50, 150)
# alpha_bgcolor = QColor(bgcolor.red(), bgcolor.green(),
# bgcolor.blue(), 150)
painter = QPainter()
painter.begin(self)
painter.save()
painter.setRenderHint(QPainter.Antialiasing)
painter.setPen(Qt.red)
rounded_rect = QPainterPath()
rounded_rect.addRoundRect(1, 1, rect.width() - 2, rect.height() - 2, roundness, roundness)
painter.setClipPath(rounded_rect)
self.setMask(painter.clipRegion())
painter.setOpacity(1.0)
painter.fillPath(rounded_rect, QBrush(alpha_bgcolor))
painter.restore()
painter.end()