本文整理匯總了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