Python PyQt5.QtGui.QPainter.HighQualityAntialiasing() Examples
The following are 6
code examples of PyQt5.QtGui.QPainter.HighQualityAntialiasing().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
PyQt5.QtGui.QPainter
, or try the search function
.
Example #1
Source File: CLoadingBar.py From CustomWidgets with GNU General Public License v3.0 | 6 votes |
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)
Example #2
Source File: visual.py From stytra with GNU General Public License v3.0 | 5 votes |
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)
Example #3
Source File: custom_widgets.py From parsec-cloud with GNU Affero General Public License v3.0 | 5 votes |
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()
Example #4
Source File: CAvatar.py From CustomWidgets with GNU General Public License v3.0 | 5 votes |
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)
Example #5
Source File: CircleImage.py From PyQt with GNU General Public License v3.0 | 5 votes |
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) #####################核心实现#########################
Example #6
Source File: LabeledArrow.py From urh with GNU General Public License v3.0 | 5 votes |
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