def rotated_by(self, pixmap, angle): ans = pixmap.copy() ans.fill(Qt.GlobalColor.transparent) p = QPainter(ans) p.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform) p.setRenderHint(QPainter.RenderHint.Antialiasing) sz = ans.size().width() / ans.devicePixelRatio() p.translate(sz // 2, sz // 2) p.rotate(angle) p.translate(-sz // 2, -sz // 2) p.drawPixmap(0, 0, pixmap) p.end() return ans
def paintEvent(self, event): if (not self.m_displayedWhenStopped) and (not self.isAnimated()): return width = min(self.width(), self.height()) painter = QPainter(self) painter.setRenderHint(QPainter.RenderHint.Antialiasing) outerRadius = (width - 1) * 0.5 innerRadius = (width - 1) * 0.5 * 0.4375 capsuleHeight = outerRadius - innerRadius capsuleWidth = width * 3 / 32 capsuleRadius = capsuleWidth / 2 for i in range(0, 12): color = QtGui.QColor(self.m_color) if self.isAnimated(): color.setAlphaF(1.0 - (i / 12.0)) else: color.setAlphaF(0.2) painter.setPen(Qt.PenStyle.NoPen) painter.setBrush(color) painter.save() painter.translate(self.rect().center()) painter.rotate(self.m_angle - (i * 30.0)) width = -1 * capsuleWidth / 2 height = -1 * (innerRadius + capsuleHeight) painter.drawRoundedRect( round(width), round(height), round(capsuleWidth), round(capsuleHeight), capsuleRadius, capsuleRadius, ) painter.restore()