本文整理汇总了Python中PyQt5.QtGui.QPainter.HighQualityAntialiasing方法的典型用法代码示例。如果您正苦于以下问题:Python QPainter.HighQualityAntialiasing方法的具体用法?Python QPainter.HighQualityAntialiasing怎么用?Python QPainter.HighQualityAntialiasing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QPainter
的用法示例。
在下文中一共展示了QPainter.HighQualityAntialiasing方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from PyQt5.QtGui import QPainter [as 别名]
# 或者: from PyQt5.QtGui.QPainter import HighQualityAntialiasing [as 别名]
def paintEvent(self, _):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing, True)
painter.setRenderHint(QPainter.HighQualityAntialiasing, True)
painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
# 背景
painter.fillRect(self.rect(), Qt.transparent)
# 进度块
ratio = (self.value() - self.minimum()) / \
(self.maximum() - self.minimum())
width = self.rect().width() * ratio
if self.isError:
color = QColor(self._failedColor or CLoadingBar.FailedColor)
else:
color = QColor(self._color or CLoadingBar.Color)
color.setAlpha(self._alpha)
painter.setBrush(color)
painter.setPen(Qt.NoPen)
painter.drawRoundedRect(QRectF(0, 0, width, self.height()), 2, 2)
示例2: draw_block
# 需要导入模块: from PyQt5.QtGui import QPainter [as 别名]
# 或者: from PyQt5.QtGui.QPainter import HighQualityAntialiasing [as 别名]
def draw_block(self, p, point, w, h):
if self._qbackground.height() < h * 1.5 or self._qbackground.width() < w * 1.5:
self.create_pattern(1.5 * np.max([h, w]))
point.setX((w - self._qbackground.width()) / 2)
point.setY((h - self._qbackground.height()) / 2)
p.setRenderHint(QPainter.HighQualityAntialiasing)
p.drawImage(point, self._qbackground)
示例3: paintEvent
# 需要导入模块: from PyQt5.QtGui import QPainter [as 别名]
# 或者: from PyQt5.QtGui.QPainter import HighQualityAntialiasing [as 别名]
def paintEvent(self, event):
super().paintEvent(event)
if not self.is_revoked:
return
rect = event.rect()
painter = QPainter(self)
painter.setRenderHints(QPainter.HighQualityAntialiasing)
pen = QPen(QColor(218, 53, 69))
pen.setWidth(5)
pen.setJoinStyle(Qt.RoundJoin)
pen.setCapStyle(Qt.RoundCap)
painter.setPen(pen)
painter.drawEllipse(rect.right() - 53, 3, 50, 53)
painter.drawLine(rect.right() - 44, 44, rect.right() - 12, 12)
painter.end()
示例4: paintEvent
# 需要导入模块: from PyQt5.QtGui import QPainter [as 别名]
# 或者: from PyQt5.QtGui.QPainter import HighQualityAntialiasing [as 别名]
def paintEvent(self, event):
super(CAvatar, self).paintEvent(event)
# 画笔
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing, True)
painter.setRenderHint(QPainter.HighQualityAntialiasing, True)
painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
# 绘制
path = QPainterPath()
diameter = min(self.width(), self.height())
if self.shape == self.Circle:
radius = int(diameter / 2)
elif self.shape == self.Rectangle:
radius = 4
halfW = self.width() / 2
halfH = self.height() / 2
painter.translate(halfW, halfH)
path.addRoundedRect(
QRectF(-halfW, -halfH, diameter, diameter), radius, radius)
painter.setClipPath(path)
# 如果是动画效果
if self.rotateAnimation.state() == QPropertyAnimation.Running:
painter.rotate(self._angle) # 旋转
painter.drawPixmap(
QPointF(-self.pixmap.width() / 2, -self.pixmap.height() / 2), self.pixmap)
else:
painter.drawPixmap(-int(halfW), -int(halfH), self.pixmap)
# 如果在加载
if self.loadingTimer.isActive():
diameter = 2 * self.pradius
painter.setBrush(
QColor(45, 140, 240, (1 - self.pradius / 10) * 255))
painter.setPen(Qt.NoPen)
painter.drawRoundedRect(
QRectF(-self.pradius, -self.pradius, diameter, diameter), self.pradius, self.pradius)
示例5: __init__
# 需要导入模块: from PyQt5.QtGui import QPainter [as 别名]
# 或者: from PyQt5.QtGui.QPainter import HighQualityAntialiasing [as 别名]
def __init__(self, *args, antialiasing=True, **kwargs):
super(Label, self).__init__(*args, **kwargs)
self.Antialiasing = antialiasing
self.setMaximumSize(200, 200)
self.setMinimumSize(200, 200)
self.radius = 100
#####################核心实现#########################
self.target = QPixmap(self.size()) # 大小和控件一样
self.target.fill(Qt.transparent) # 填充背景为透明
p = QPixmap("Data/Images/head.jpg").scaled( # 加载图片并缩放和控件一样大
200, 200, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation)
painter = QPainter(self.target)
if self.Antialiasing:
# 抗锯齿
painter.setRenderHint(QPainter.Antialiasing, True)
painter.setRenderHint(QPainter.HighQualityAntialiasing, True)
painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
# painter.setPen(# 测试圆圈
# QPen(Qt.red, 5, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
path = QPainterPath()
path.addRoundedRect(
0, 0, self.width(), self.height(), self.radius, self.radius)
# **** 切割为圆形 ****#
painter.setClipPath(path)
# painter.drawPath(path) # 测试圆圈
painter.drawPixmap(0, 0, p)
self.setPixmap(self.target)
#####################核心实现#########################
示例6: paint
# 需要导入模块: from PyQt5.QtGui import QPainter [as 别名]
# 或者: from PyQt5.QtGui.QPainter import HighQualityAntialiasing [as 别名]
def paint(self, painter, QStyleOptionGraphicsItem, QWidget_widget=None):
"""
@type painter: QPainter
@param QStyleOptionGraphicsItem:
@param QWidget_widget:
@return:
"""
painter.setPen(self.pen())
x1 = self.line().x1()
y1 = self.line().y1()
y2 = self.line().y2()
x_arrowSize = 10
y_arrowSize = 0.1 * abs(y2 - y1)
labelheight = 0.75 * abs(y2 - y1)
painter.drawLine(QPointF(x1, y1), QPointF(x1, y1 + labelheight / 2))
painter.drawLine(QPointF(x1, y1), QPointF(x1 + x_arrowSize / 4, y1 + y_arrowSize / 2))
painter.drawLine(QPointF(x1, y1), QPointF(x1 - x_arrowSize / 4, y1 + y_arrowSize / 2))
painter.drawLine(QPointF(x1, y2 - labelheight / 2), QPointF(x1, y2))
painter.drawLine(QPointF(x1, y2), QPointF(x1 + x_arrowSize / 4, y2 - y_arrowSize / 2))
painter.drawLine(QPointF(x1, y2), QPointF(x1 - x_arrowSize / 4, y2 - y_arrowSize / 2))
painter.setRenderHint(QPainter.HighQualityAntialiasing)
fm = painter.fontMetrics()
pixelsWide = fm.width(self.label)
pixelsHigh = fm.height()
scale_factor = (0.2 * labelheight) / fm.height()
scale_factor = scale_factor if scale_factor > 0 else 0.0000000000000000001
painter.scale(1, scale_factor)
# print(y1, y2, pixelsHigh)
painter.drawText(QPointF(x1 - pixelsWide / 2, (1 / scale_factor) * (y1 + y2) / 2 + pixelsHigh / 4), self.label)
# painter.drawText(QPointF(x1 - pixelsWide/2, (y1+y2+pixelsHigh)/2), self.label)
del painter