def get_path(self): path = QPainterPath() rect = QRectF(self.rect()) path.arcMoveTo(rect, 0) path.arcTo(rect, 0, 360) path.closeSubpath() return path
def updateAngle(self, startAngle, spanAngle): self._startAngle = startAngle self._spanAngle = spanAngle path = QPainterPath() path.arcMoveTo(self._parent._rect, startAngle) path.arcTo(self._parent._rect, startAngle, spanAngle) self.setPath(path)
def create_circle_path(x_center: int, y_center: int, radius: int) -> QPainterPath: rect = QRectF(x_center - radius, y_center - radius, radius * 2, radius * 2) circle_path = QPainterPath() circle_path.arcMoveTo(rect, 0) circle_path.arcTo(rect, 0, 360) circle_path.closeSubpath() return circle_path
def get_circle_path(center_pos: list, radius: int): rect = QRectF(center_pos[0] - radius, center_pos[1] - radius, radius * 2, radius * 2) seed_path = QPainterPath() seed_path.arcMoveTo(rect, 0) seed_path.arcTo(rect, 0, 360) seed_path.closeSubpath() return seed_path
def get_circle_seed_path(circle_seed) -> QPainterPath: rect = QRectF(circle_seed.position.x() - circle_seed.radius, circle_seed.position.y() - circle_seed.radius, circle_seed.radius * 2, circle_seed.radius * 2) seed_path = QPainterPath() seed_path.arcMoveTo(rect, 0) seed_path.arcTo(rect, 0, 360) seed_path.closeSubpath() return seed_path
def set_shape(self, width, height): ''' ANSWER has round, disjoint sides - does not fit in a polygon ''' self.width, self.height = width, height point = 20 #width / 2.85 path = QPainterPath() left = QRect(0, 0, point, height) right = QRect(width - point, 0, point, height) path.arcMoveTo(left, 125) path.arcTo(left, 125, 110) path.arcMoveTo(right, -55) path.arcTo(right, -55, 110) path.moveTo(width, height) self.setPath(path) super(DecisionAnswer, self).set_shape(width, height)
class ControlButton(QWidget): def __init__(self, index, name, func, parent): super().__init__(parent) self.index = index self.name = name self.function = func self.resize(TILE_WIDTH << 2, TILE_HEIGHT << 2) self.show() self.opacity = None self.setMouseTracking(True) self.color = QColor(50 * self.index, 255, 255 - 10 * self.index) self.gradient = QRadialGradient( 50 + 10 * self.index, 50 - 10 * self.index, 500 - 50 * self.index, 50 + 10 * self.index, 100 - 10 * self.index) self.gradient.setColorAt(0, QColor(200, 200, 200)) self.gradient.setColorAt(0.5, QColor(50 * self.index, 255, 255 - 10 * self.index)) self.gradient.setColorAt(1, QColor(200, 200, 200)) self.brush = QBrush(self.gradient) self.path = QPainterPath() rect = QRectF(TILE_WIDTH * 1.5, TILE_HEIGHT * 1.5, TILE_WIDTH * 1.5, TILE_HEIGHT * 1.5) total = self.parent().total - 1 if total < 3: total = 3 if self.index == 0: self.path.arcMoveTo(rect, 90) self.path.arcTo(rect, 90, 360) else: self.path.arcMoveTo(QRectF(self.rect()), 90 + self.index * 360 // total) self.path.arcTo(QRectF(self.rect()), 90 + self.index * 360 // total, 360 // total) self.path.arcTo(rect, 90 + self.index * 360 // total + 360 // total, -360 // total) self.path.arcTo(QRectF(self.rect()), 90 + self.index * 360 // total, 0) def paintEvent(self, event): painter = QPainter(self) painter.setBrush(self.brush) if self.opacity is None or self.parent().vanishing: painter.setOpacity(self.parent().opacity / 255) else: painter.setOpacity(self.opacity / 255) pen = QPen(QColor(100, 100, 100, 150)) pen.setWidth(10) painter.setPen(pen) painter.drawPath(self.path) painter.setPen(QColor(0, 0, 0)) painter.drawText(self.path.controlPointRect(), Qt.AlignCenter, self.name)
def paintEvent(self, event: QtGui.QPaintEvent) -> None: super().paintEvent(event) painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing, True) pen = QPen(Qt.red) pen.setWidth(2) painter.setPen(pen) if self._bezier_path is None and self._init_line: painter.drawLine(self._init_line[0], self._init_line[1]) if self._bezier_path is not None: self._bezier_path.paint(painter) p = QPainterPath() p.arcMoveTo(100, 100, 100, 50, 30) p.arcTo(100, 100, 100, 50, 30, 120) n = QPainterPath() n.moveTo(100, 110) n.lineTo(200, 110)
def paintEvent(self, evt): x1 = QPoint(0, -70) x2 = QPoint(0, -90) x3 = QPoint(-90, 0) x4 = QPoint(-70, 0) extRect = QRectF(-90, -90, 180, 180) intRect = QRectF(-70, -70, 140, 140) midRect = QRectF(-44, -80, 160, 160) unitRect = QRectF(-50, 60, 110, 50) speedInt = self.speed #speedDec = (self.speed * 10.0) - (speedInt * 10) s_SpeedInt = speedInt.__str__()[0:4] powerAngle = self.power * 270.0 / 100.0 dummyPath = QPainterPath() dummyPath.moveTo(x1) dummyPath.arcMoveTo(intRect, 90 - powerAngle) powerPath = QPainterPath() powerPath.moveTo(x1) powerPath.lineTo(x2) powerPath.arcTo(extRect, 90, -1 * powerAngle) powerPath.lineTo(dummyPath.currentPosition()) powerPath.arcTo(intRect, 90 - powerAngle, powerAngle) painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) painter.translate(self.width() / 2, self.height() / 2) side = min(self.width(), self.height()) painter.scale(side / 200.0, side / 200.0) painter.save() painter.rotate(-135) if self.displayPowerPath: externalPath = QPainterPath() externalPath.moveTo(x1) externalPath.lineTo(x2) externalPath.arcTo(extRect, 90, -270) externalPath.lineTo(x4) externalPath.arcTo(intRect, 180, 270) painter.setPen(self.powerPathColor) painter.drawPath(externalPath) painter.setBrush(self.powerGradient) painter.setPen(Qt.NoPen) painter.drawPath(powerPath) painter.restore() painter.save() painter.translate(QPointF(0, -50)) painter.setPen(self.unitTextColor) fontFamily = self.font().family() unitFont = QFont(fontFamily, 9) painter.setFont(unitFont) painter.drawText(unitRect, Qt.AlignCenter, "{}".format(self.unit)) painter.restore() painter.setPen(self.unitTextColor) fontFamily = self.font().family() unitFont = QFont(fontFamily, 12) painter.setFont(unitFont) painter.drawText(unitRect, Qt.AlignCenter, "{}".format(self.title)) speedColor = QColor(0, 0, 0) speedFont = QFont(fontFamily, 30) fm1 = QFontMetrics(speedFont) speedWidth = fm1.width(s_SpeedInt) #speedDecFont = QFont(fontFamily, 23) #fm2 = QFontMetrics(speedDecFont) #speedDecWidth = fm2.width(s_SpeedDec) leftPos = -1 * speedWidth + 40 leftDecPos = leftPos + speedWidth topPos = 10 topDecPos = 10 painter.setPen(self.speedTextColor) painter.setFont(speedFont) painter.drawText(leftPos, topPos, s_SpeedInt)
def setupGraphics(self): """ Set up the graphics. """ shape_rect = QRectF(-24, -24, 48, 48) self.shapeItem = NodeBodyItem(self) self.shapeItem.setShapeRect(shape_rect) self.shapeItem.setAnimationEnabled(self.__animationEnabled) # Rect for widget's 'ears'. anchor_rect = QRectF(-31, -31, 62, 62) self.inputAnchorItem = SinkAnchorItem(self) input_path = QPainterPath() start_angle = 180 - self.ANCHOR_SPAN_ANGLE / 2 input_path.arcMoveTo(anchor_rect, start_angle) input_path.arcTo(anchor_rect, start_angle, self.ANCHOR_SPAN_ANGLE) self.inputAnchorItem.setAnchorPath(input_path) self.outputAnchorItem = SourceAnchorItem(self) output_path = QPainterPath() start_angle = self.ANCHOR_SPAN_ANGLE / 2 output_path.arcMoveTo(anchor_rect, start_angle) output_path.arcTo(anchor_rect, start_angle, - self.ANCHOR_SPAN_ANGLE) self.outputAnchorItem.setAnchorPath(output_path) self.inputAnchorItem.hide() self.outputAnchorItem.hide() # Title caption item self.captionTextItem = NameTextItem(self) self.captionTextItem.setPlainText("") self.captionTextItem.setPos(0, 33) def iconItem(standard_pixmap): item = GraphicsIconItem(self, icon=standard_icon(standard_pixmap), iconSize=QSize(16, 16)) item.hide() return item self.errorItem = iconItem(QStyle.SP_MessageBoxCritical) self.warningItem = iconItem(QStyle.SP_MessageBoxWarning) self.infoItem = iconItem(QStyle.SP_MessageBoxInformation) ################################ # PyQt 5.10 crashes because of this call (2) #self.backgroundItem = QGraphicsPathItem(self) self.backgroundItem = QGraphicsPathItem(None) ################################ backgroundrect = QPainterPath() backgroundrect.addRoundedRect(anchor_rect.adjusted(-4, -2, 4, 2), 5, 5, mode=Qt.AbsoluteSize) self.backgroundItem.setPen(QPen(Qt.NoPen)) self.backgroundItem.setBrush(QPalette().brush(QPalette.Highlight)) self.backgroundItem.setOpacity(0.5) self.backgroundItem.setPath(backgroundrect) self.backgroundItem.setZValue(-10) self.backgroundItem.setVisible(self.isSelected()) self.prepareGeometryChange() self.__boundingRect = None