def __init__(self, connection, parent): super().__init__() self._connection = connection self._source_ui = self._find_ui(parent, connection.source.connector) self._sink_ui = self._find_ui(parent, connection.sink.connector) self.avoid_conn = None self._duplicate_is = None self._duplicate_of = None self._switch_direction_count = 1 self.path = QPainterPath() self.stroker_path = QPainterPath() self.stroker = QPainterPathStroker() self.stroker.setWidth(8) self.update_endpoints() self.setZValue(-10) self.arrow = QGraphicsPolygonItem() self._set_default_appearance() self.setFlag(self.ItemIsFocusable) self._ports_item = Connection_Ports_Item() self._ports_item.setParentItem(self) self._timer = QTimer(self.scene()) self._timer.setSingleShot(True) self._timer.setSingleShot(True) self._timer.timeout.connect(self._start_hover) self._hover_pos = 0, 0 self.set_show_connection_ports_on_hover(False)
def paintEvent(self, e): height = self.height() width = self.width() # draw background painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) painter.setPen(Qt.transparent) painter.setBrush(BACKGROUND) painter.setOpacity(1) path = QPainterPath() path.setFillRule(Qt.WindingFill) path.addRoundedRect(QRectF(8, 0, width - 8, height), 15, 15) painter.drawPath(path.simplified()) # draw sidebar painter.setBrush(SIDEBAR) painter.setOpacity(1) path = QPainterPath() path.setFillRule(Qt.WindingFill) # we draw a fixed-width toolbar background path.addRoundedRect(QRectF(8, 0, 250 - 8, height), 15, 15) path.addRect(QRectF(200, 0, 50, 50)) path.addRect(QRectF(200, height - 50, 50, 50)) painter.drawPath(path.simplified())
def borderPath(self, rect): """ Calculate the painter path for a styled or rounded border When the canvas has no styled background or rounded borders the painter path is empty. :param QRect rect: Bounding rectangle of the canvas :return: Painter path, that can be used for clipping """ if self.testAttribute(Qt.WA_StyledBackground): recorder = QwtStyleSheetRecorder(rect.size()) painter = QPainter(recorder) opt = QStyleOption() opt.initFrom(self) opt.rect = rect self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self) painter.end() if not recorder.background.path.isEmpty(): return recorder.background.path if len(recorder.border.rectList) > 0: return qwtCombinePathList(rect, recorder.border.pathlist) elif self.__data.borderRadius > 0.0: fw2 = self.frameWidth() * 0.5 r = QRectF(rect).adjusted(fw2, fw2, -fw2, -fw2) path = QPainterPath() path.addRoundedRect(r, self.__data.borderRadius, self.__data.borderRadius) return path return QPainterPath()
def qwtCombinePathList(rect, pathList): if not pathList: return QPainterPath() ordered = [None] * 8 for subPath in pathList: index = -1 br = subPath.controlPointRect() if br.center().x() < rect.center().x(): if br.center().y() < rect.center().y(): if abs(br.top() - rect.top()) < abs(br.left() - rect.left()): index = 1 else: index = 0 else: if abs(br.bottom() - rect.bottom) < abs(br.left() - rect.left()): index = 6 else: index = 7 if subPath.currentPosition().y() > br.center().y(): qwtRevertPath(subPath) else: if br.center().y() < rect.center().y(): if abs(br.top() - rect.top()) < abs(br.right() - rect.right()): index = 2 else: index = 3 else: if abs(br.bottom() - rect.bottom()) < abs(br.right() - rect.right()): index = 5 else: index = 4 if subPath.currentPosition().y() < br.center().y(): qwtRevertPath(subPath) ordered[index] = subPath for i in range(4): if ordered[2 * i].isEmpty() != ordered[2 * i + 1].isEmpty(): return QPainterPath() corners = QPolygonF(rect) path = QPainterPath() for i in range(4): if ordered[2 * i].isEmpty(): path.lineTo(corners[i]) else: path.connectPath(ordered[2 * i]) path.connectPath(ordered[2 * i + 1]) path.closeSubpath() return path
def paint(self, p, opt, widget): # Enforce constraints on handles r2 = Point(np.cos(np.radians(self.thetacenter)), np.sin(np.radians(self.thetacenter))) # chi center direction vector # constrain innerhandle to be parallel to outerhandle, and shorter than outerhandle self.innerhandle.setPos(r2 * self.innerradius) # constrain widthhandle to be counter-clockwise from innerhandle widthangle = np.radians(self.thetawidth / 2 + self.thetacenter) widthv = Point(np.cos(widthangle), np.sin(widthangle)) if self.thetawidth > 0 else r2 # constrain widthhandle to half way between inner and outerhandles self.widthhandle.setPos(widthv * (self.innerradius + self.outerradius) / 2) # constrain handles to base values self.outerhandle.setPos(r2 * self.outerradius) pen = self.currentPen pen.setColor(QColor(0, 255, 255)) p.setPen(pen) r = self.boundingRect() # p.drawRect(r) p.setRenderHint(QPainter.Antialiasing) p.scale(r.width(), r.height()) # workaround for GL bug centerangle = self.innerhandle.pos().angle(Point(1, 0)) startangle = centerangle - self.thetawidth / 2 endangle = centerangle + self.thetawidth / 2 r = QCircRectF(radius=0.5) if self.innerradius < self.outerradius and self.thetawidth > 0: p.drawArc(r, -startangle * 16, -self.thetawidth * 16) radius = self.innerradius / self.outerradius / 2 r = QCircRectF() r.radius = radius if self.innerradius < self.outerradius and self.thetawidth > 0: p.drawArc(r, -startangle * 16, -self.thetawidth * 16) pen.setStyle(Qt.DashLine) p.setPen(pen) p.drawLine(QPointF(0., 0.), self.widthhandle.pos().norm() / 2) r1v = self.innerhandle.pos().norm() p.drawLine(QPointF(0., 0.), (-1. * self.widthhandle.pos() + 2 * self.widthhandle.pos().dot(r1v) * r1v).norm() / 2) pen.setStyle(Qt.SolidLine) if self.innerradius < self.outerradius and self.thetawidth > 0: path = QPainterPath() path.moveTo((-1. * self.widthhandle.pos() + 2 * self.widthhandle.pos().dot(r1v) * r1v).norm() / 2) path.arcTo(r, -startangle, -self.thetawidth) # inside path.lineTo(self.widthhandle.pos().norm() / 2) # ? side path.arcTo(QCircRectF(radius=0.5), -endangle, self.thetawidth) # outside path.lineTo((-1. * self.widthhandle.pos() + 2 * self.widthhandle.pos().dot(r1v) * r1v).norm() / 2) self.path = path p.fillPath(path, QBrush(QColor(0, 255, 255, 20)))
def paintEvent(self, a0: QPaintEvent) -> None: super().paintEvent(a0) painter = QPainter(self) painter.save() painter.setRenderHint(QPainter.Antialiasing) rect = QRectF(self.margin, self.margin, self.width() - self.margin * 2, self.height() - 2 * self.margin) painter.setBrush(Qt.white) painter.setPen(Qt.white) painter.drawRect(rect) painter.restore() painter.save() painter.setRenderHint(QPainter.Antialiasing) pen = QPen() pen.setWidth(3) painter.setPen(pen) path = QPainterPath() height, width = rect.height() + self.margin, rect.width() + self.margin path.moveTo(self.margin, height) path.cubicTo(height * 0.5, width * 0.9, height * 0.9, width * 0.5, height, self.margin) painter.drawPath(path) painter.restore()
def setData( self, x, height, width=0.8, bottom=None, *, align="center", fillcolor=None, edgecolor=None, ) -> None: # assume vertical cbook._check_in_list(["center", "edge"], align=align) y = bottom if y is None: y = 0 x, height, width, y = np.broadcast_arrays(np.atleast_1d(x), height, width, y) if align == "center": try: left = x - width / 2 except TypeError as e: raise TypeError( f"the dtypes of parameters x ({x.dtype}) " f"and width ({width.dtype}) " f"are incompatible" ) from e elif align == "edge": left = x else: raise RuntimeError(f"unknown align mode {align}") bottom = y # prepare to draw if edgecolor is None: edgecolor = (128, 128, 128) # getConfigOption("foreground") pen = mkPen(edgecolor) if fillcolor is None: fillcolor = (128, 128, 128) brush = mkBrush(fillcolor) self.qpicture = QPicture() self.path = QPainterPath() p = QPainter(self.qpicture) p.setPen(pen) p.setBrush(brush) # draw rects = zip(left, bottom, width, height) for l, b, w, h in rects: rect = QRectF(l, b, w, h) p.drawRect(rect) self.path.addRect(rect) p.end() self.prepareGeometryChange()
def drawValue(self, p: QPainter, baseRect: QRectF, value: float, delta: float): if value == self.m_min: return if self.m_barStyle == self.BarStyle.EXPAND: p.setBrush(self.palette().highlight()) p.setPen(QPen(self.palette().shadow().color(), self.m_dataPenWidth)) radius = (baseRect.height() / 2) / delta p.drawEllipse(baseRect.center(), radius, radius) return if self.m_barStyle == self.BarStyle.LINE: p.setPen(QPen(self.palette().highlight().color(), self.m_dataPenWidth)) p.setBrush(Qt.NoBrush) if value == self.m_max: p.drawEllipse(baseRect.adjusted(self.m_outlinePenWidth / 2, self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2)) else: arcLength = 360 / delta p.drawArc(baseRect.adjusted(self.m_outlinePenWidth / 2, self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2), int(self.m_nullPosition * 16), int(-arcLength * 16)) return dataPath = QPainterPath() dataPath.setFillRule(Qt.WindingFill) if value == self.m_max: dataPath.addEllipse(baseRect) else: arcLength = 360 / delta dataPath.moveTo(baseRect.center()) dataPath.arcTo(baseRect, self.m_nullPosition, -arcLength) dataPath.lineTo(baseRect.center()) p.setBrush(self.palette().highlight()) p.setPen(QPen(self.palette().shadow().color(), self.m_dataPenWidth)) p.drawPath(dataPath)
def get_line_path(points, shape_type): line_path = QPainterPath() if shape_type == 'rectangle' and len(points) == 2: rectangle = Shape.getRectFromLine(*points) line_path.addRect(rectangle) elif shape_type == 'circle' and len(points) == 2: rectangle = Shape.getCircleRectFromLine(points) line_path.addEllipse(rectangle) elif shape_type == 'linestrip' and points: line_path.moveTo(points[0]) for p in points: line_path.lineTo(p) elif shape_type in ['curve', 'freeform'] and points: # Paint Bezier curve across given points. refined_points = BezierB(points).smooth() line_path.moveTo(refined_points[0]) for p in refined_points: line_path.lineTo(p) elif points: line_path.moveTo(points[0]) for p in points: line_path.lineTo(p) if shape_type == 'polygon': line_path.lineTo(points[0]) return line_path
def paintEvent(self, event): painter = QPainter(self) painter.setRenderHints(QPainter.Antialiasing) side = min(self.width(), self.height()) painter.scale(side / 32.0, side / 32.0) painter.setPen(Qt.NoPen) if not self.is_pressed: painter.setBrush(self.back_color) else: painter.setBrush( QColor(self.back_color.red() + 30, self.back_color.green() + 30, self.back_color.blue() + 30)) painter.drawRoundedRect(QRect(0, 0, 32, 32), 8, 8) if self.is_checked: check_path = QPainterPath() check_path.moveTo(self.x1) check_path.lineTo(self.x2) check_path.lineTo(self.x3) pen = QPen(self.check_color, self.check_thick, Qt.SolidLine) painter.setPen(pen) painter.drawPath(check_path)
def draw_icon(self, painter): path = QPainterPath(QPointF(0, 0.3)) path.lineTo(0, 0.9) path.lineTo(1, 0.3) path.lineTo(1, 0.9) path.closeSubpath() painter.drawPath(path) painter.drawLine(QPointF(0.5, 0.6), QPointF(0.5, 0.15)) # Draw the arrow end-caps painter.setBrush(QBrush(QColor(0, 0, 0))) top_arrow_point = QPointF(0.65, 0.36) arrow = QPolygonF([ QPointF(-0.09, 0.0), QPointF(-0.005, 0.0), QPointF(-0.005, 0.8), QPointF(0.005, 0.8), QPointF(0.005, 0.0), QPointF(0.09, 0.0), QPointF(0.00, -0.25) ]) t = QTransform() t.rotate(35) top_arrow_r = t.map(arrow) arrow_l = top_arrow_r.translated(top_arrow_point) painter.drawPolygon(arrow_l) painter.setBrush(self._interlock_brush) painter.drawRect(QRectF(0.3, 0, 0.4, 0.15))
def paintEvent(self, event): painter = QPainter(self) painter.setRenderHints(QPainter.Antialiasing) if self.label_width <= 0: return painter.setPen(Qt.NoPen) if self.hover: painter.setBrush( QColor(self.back_color.red() + 30, self.back_color.green() + 30, self.back_color.blue() + 30)) else: painter.setBrush(self.back_color) painter.drawRoundedRect(QRect(0, 0, self.width(), self.height()), self.border_radius, self.border_radius) x1 = QPointF(self.label_width + float(self.height() / 3), float(self.height() * 0.45)) x2 = QPointF( self.label_width + float(self.height() * (0.66 + self.rate) / 2), float(self.height() * 0.55)) x3 = QPointF(self.width() - float(self.height() / 3), float(self.height() * 0.45)) check_path = QPainterPath() check_path.moveTo(x1) check_path.lineTo(x2) check_path.lineTo(x3) pen = QPen(self.text_color, self.drop_thick, Qt.SolidLine) painter.setPen(pen) painter.drawPath(check_path)
def __drawHorizontal(self, widget, option, painter, size, width): x_pos = option.rect.topLeft().x() if option.rect.width() == 0: # create indicators top_indicator = self.createTriangle(size, attrs.NORTH) top_indicator.translate(QPoint(x_pos, size + (width / 2))) bot_indicator = self.createTriangle(size, attrs.SOUTH) bot_indicator.translate( QPoint(x_pos, option.rect.height() - size - (width / 2))) # draw painter.drawPolygon(top_indicator) painter.drawPolygon(bot_indicator) painter.drawLine( QPoint(x_pos, size + (width / 2)), QPoint(x_pos, option.rect.height() - size + (width / 2))) # set fill color background_color = QColor(*iColor["rgba_gray_1"]) brush = QBrush(background_color) path = QPainterPath() path.addPolygon(top_indicator) path.addPolygon(bot_indicator) painter.fillPath(path, brush) # drop on else: painter.drawRoundedRect(option.rect, 1, 1)
def _makePath(self): self._path = QPainterPath() self._path.moveTo(self._xData[0], self._yData[0]) for k, idx in enumerate(self._xData): d = self._yData[k] self._path.lineTo(idx, d)
def paintEvent(self, event): painter = QPainter(self) painter.setClipRegion(event.region()) if ( self.testPaintAttribute(self.BackingStore) and self.__data.backingStore is not None ): bs = self.__data.backingStore if QT_MAJOR_VERSION >= 5: pixelRatio = bs.devicePixelRatio() else: pixelRatio = 1.0 if bs.size() != self.size() * pixelRatio: bs = QwtPainter.backingStore(self, self.size()) if self.testAttribute(Qt.WA_StyledBackground): p = QPainter(bs) qwtFillBackground(p, self) self.drawCanvas(p, True) else: p = QPainter() if self.__data.borderRadius <= 0.0: # print('**DEBUG: QwtPlotCanvas.paintEvent') QwtPainter.fillPixmap(self, bs) p.begin(bs) self.drawCanvas(p, False) else: p.begin(bs) qwtFillBackground(p, self) self.drawCanvas(p, True) if self.frameWidth() > 0: self.drawBorder(p) p.end() painter.drawPixmap(0, 0, self.__data.backingStore) else: if self.testAttribute(Qt.WA_StyledBackground): if self.testAttribute(Qt.WA_OpaquePaintEvent): qwtFillBackground(painter, self) self.drawCanvas(painter, True) else: self.drawCanvas(painter, False) else: if self.testAttribute(Qt.WA_OpaquePaintEvent): if self.autoFillBackground(): qwtFillBackground(painter, self) qwtDrawBackground(painter, self) else: if self.borderRadius() > 0.0: clipPath = QPainterPath() clipPath.addRect(self.rect()) clipPath = clipPath.subtracted(self.borderPath(self.rect())) painter.save() painter.setClipPath(clipPath, Qt.IntersectClip) qwtFillBackground(painter, self) qwtDrawBackground(painter, self) painter.restore() self.drawCanvas(painter, False) if self.frameWidth() > 0: self.drawBorder(painter) if self.hasFocus() and self.focusIndicator() == self.CanvasFocusIndicator: self.drawFocusIndicator(painter)
def draw_icon(self, painter): path = QPainterPath(QPointF(0, 0.3)) path.lineTo(0, 0.9) path.lineTo(1, 0.3) path.lineTo(1, 0.9) path.closeSubpath() painter.drawPath(path) prev_brush = painter.brush() prev_pen = painter.pen() painter.setPen(Qt.NoPen) painter.setBrush(self._arrow_brush) arrow = QPolygonF([ QPointF(0.2, 0), QPointF(0.2, 0.20), QPointF(0.5, 0.40), QPointF(0.8, 0.20), QPointF(0.8, 0) ]) painter.drawPolygon(arrow) painter.setPen(prev_pen) painter.setBrush(prev_brush) painter.drawLine(QPointF(0.2, 0), QPointF(0.5, 0.20)) painter.drawLine(QPointF(0.2, 0.20), QPointF(0.5, 0.40)) painter.drawLine(QPointF(0.5, 0.20), QPointF(0.8, 0)) painter.drawLine(QPointF(0.5, 0.40), QPointF(0.8, 0.20)) painter.drawLine(QPointF(0.5, 0.6), QPointF(0.5, 0.0))
def __drawVertical(self, widget, option, painter, size, width): # drop between y_pos = option.rect.topLeft().y() if option.rect.height() == 0: # create indicators l_indicator = self.createTriangle(size, attrs.EAST) l_indicator.translate(QPoint(size + (width / 2), y_pos)) r_indicator = self.createTriangle(size, attrs.WEST) r_indicator.translate( QPoint(widget.width() - size - (width / 2), y_pos)) # draw painter.drawPolygon(l_indicator) painter.drawPolygon(r_indicator) painter.drawLine( QPoint(size + (width / 2), y_pos), QPoint(widget.width() - size - (width / 2), y_pos)) # set fill color background_color = QColor(*iColor["rgba_gray_1"]) brush = QBrush(background_color) path = QPainterPath() path.addPolygon(l_indicator) path.addPolygon(r_indicator) painter.fillPath(path, brush) # drop on else: indicator_rect = QRect((width / 2), y_pos, widget.width() - (width / 2), option.rect.height()) painter.drawRoundedRect(indicator_rect, 1, 1)
def draw_icon(self, painter): path = QPainterPath(QPointF(0, 0.3)) path.lineTo(0, 0.9) path.lineTo(1, 0.3) path.lineTo(1, 0.9) path.closeSubpath() painter.drawPath(path)
def paint(self, q_painter: 'QPainter', style_option_graphics_item: 'QStyleOptionGraphicsItem', widget: 'QWidget' = None): pen = QPen() pen.setColor(self.color) pen.setWidth(3) pen.setJoinStyle(Qt.MiterJoin) # 让箭头变尖 q_painter.setPen(pen) path = QPainterPath() point1 = self.start_port path.moveTo(self.start_port.center_pos) # for i in self.line_items: # i.setPen(QColor(255, 0, 0)) # i.update() for p in self.center_points + [self.end_port]: pen.setWidth(3) q_painter.setPen(pen) path.lineTo(p.center_pos) q_painter.drawLine(QLineF(point1.center_pos, p.center_pos)) arrow = self.draw_arrow(q_painter, point1.center_pos, p.center_pos) path.addPolygon(arrow) # 将箭头添加到连线上 point1 = p
def cubic_path(geom): source, sink = geom.source, geom.sink c1, c2 = geom.points_c1_c2() # cubic spline cubic = QPainterPath(source) cubic.cubicTo(c1, c2, sink) return cubic
def draw_icon(self, painter): path = QPainterPath(QPointF(0, 0)) path.lineTo(1, 1) path.lineTo(0.005, 1) path.lineTo(0.5, 0.5) path.lineTo(0, 0.9) path.closeSubpath() painter.drawPath(path) painter.drawEllipse(QPointF(0.5, 0.5), 0.05, 0.05)
def paint(self, painter, fill=False, canvas=None): from ..application import Application mainwindow = Application.get_main_window() line_pen, last_line_pen, fill_color = self._get_pens_and_colors( canvas, mainwindow.lineColor, mainwindow.fillColor) scale = self.get_scale(canvas) # Draw all vertices self.paint_vertices(painter, self.points, scale, self._highlightIndex, self._highlightMode) line_path1, line_path2 = QPainterPath(), QPainterPath() fill_path = line_path1 # Get path for committed and uncommitted parts # respectively and draw with different colors if self.shape_type == 'curve' and self.points: # Bezier curve needs to be fitted as a whole, # so reimplementing this part here. refined_points = BezierB(self.points).smooth() sep_idx = refined_points.index(self.points[-1]) line_path1.moveTo(refined_points[0]) for p in refined_points[:sep_idx]: line_path1.lineTo(p) line_path2.moveTo(refined_points[sep_idx]) for p in refined_points[sep_idx:]: line_path2.lineTo(p) elif self.shape_type in ['circle', 'rectangle']: painter.setPen(line_pen) line_path2 = self.get_line_path(self.points, self.shape_type) painter.setPen(last_line_pen) painter.drawPath(line_path2) fill_path = line_path2 elif len(self.points) >= 2: # Otherwise, just get 2 different line paths, # painting with different colors. # Use type == 'line' even with polygon to prevent connecting back. line_path1 = self.get_line_path(self.points[:-1], 'line') line_path2 = self.get_line_path(self.points[-2:], 'line') painter.setPen(line_pen) painter.drawPath(line_path1) painter.setPen(last_line_pen) painter.drawPath(line_path2) if fill: painter.fillPath(fill_path, fill_color)
def painterPathForTriangle(): bottomLeft = QPointF(-1.0, -1.0) top = QPointF(0.0, 1.0) bottomRight = QPointF(1.0, -1.0) path = QPainterPath(bottomLeft) path.lineTo(top) path.lineTo(bottomRight) path.closeSubpath() return path
def draw_icon(self, painter): path = QPainterPath(QPointF(0, 0.3)) path.lineTo(0, 0.9) path.lineTo(1, 0.3) path.lineTo(1, 0.9) path.closeSubpath() painter.drawPath(path) painter.drawLine(QPointF(0.5, 0.6), QPointF(0.5, 0.3)) painter.setBrush(self._interlock_brush) painter.drawRect(QRectF(0.2, 0, 0.6, 0.3)) # Draw the N n_path = QPainterPath(QPointF(0.25, 0.25)) n_path.lineTo(0.25, 0.05) n_path.lineTo(0.45, 0.25) n_path.lineTo(0.45, 0.05) painter.drawPath(n_path) # Draw the O painter.drawEllipse(QPointF(0.65, 0.15), 0.1, 0.1)
def draw_icon(self, painter): path = QPainterPath(QPointF(0, 0.3)) path.lineTo(0, 0.9) path.lineTo(1, 0.3) path.lineTo(1, 0.9) path.closeSubpath() painter.drawPath(path) painter.drawLine(QPointF(0.5, 0.6), QPointF(0.5, 0.3)) painter.setBrush(self._interlock_brush) painter.drawRect(QRectF(0.2, 0, 0.6, 0.3))
def copy(self, other): self.__type = other.__type if other.__type == self.Path: self.__path = QPainterPath(other.__path) elif other.__type == self.Pixmap: self.__pixmapData = copy.deepcopy(other.__pixmapData) elif other.__type == self.Image: self.__imageData = copy.deepcopy(other.__imageData) elif other.__type == self.State: self.__stateData == copy.deepcopy(other.__stateData)
def paintEvent(self, event) -> None: super(ToolTip, self).paintEvent(event) x = self.rect().x() + self._anchor_width y = self.rect().y() + self._anchor_width w = self.rect().width() - self._anchor_width * 2 h = self.rect().height() - self._anchor_width * 2 # 背景 painter = QPainter(self) path = QPainterPath() path.addRoundedRect(QRectF(x, y, w, h), 4, 4) # 画锚 if self._direction == ToolTip.TOP: x1 = x + w / 2 - self._anchor_width y1 = y + h x2 = x + w / 2 + self._anchor_width y2 = y + h x3 = x + w / 2 y3 = y + h + self._anchor_width path.moveTo(x1, y1) path.lineTo(x2, y2) path.lineTo(x3, y3) elif self._direction == ToolTip.BOTTOM: x1 = x + w / 2 - self._anchor_width y1 = y x2 = x + w / 2 + self._anchor_width y2 = y x3 = x + w / 2 y3 = y - self._anchor_width path.moveTo(x1, y1) path.lineTo(x2, y2) path.lineTo(x3, y3) elif self._direction == ToolTip.RIGHT: x1 = x y1 = y + h / 2 - self._anchor_width x2 = x y2 = y + h / 2 + self._anchor_width x3 = x - self._anchor_width y3 = y + h / 2 path.moveTo(x1, y1) path.lineTo(x2, y2) path.lineTo(x3, y3) elif self._direction == ToolTip.LEFT: x1 = x + w y1 = y + h / 2 - self._anchor_width x2 = x + w y2 = y + h / 2 + self._anchor_width x3 = x + w + self._anchor_width y3 = y + h / 2 path.moveTo(x1, y1) path.lineTo(x2, y2) path.lineTo(x3, y3) painter.fillPath(path, ResourceLoader().qt_color_separator_dark)
def update_endpoints(self): self.x1, self.y1 = self._get_endpoint(self._source_ui) self.x2, self.y2 = self._get_endpoint(self._sink_ui) if self.x1 is None or self.x2 is None: return False self.path = QPainterPath() self.path.moveTo(self.x1, self.y1) self.path.lineTo(self.x2, self.y2) self.setPath(self.path) self._update_avoid() return True
def drawStar(self, qp): """Draw a star in the preview pane. Parameters ---------- qp: QPainter object """ width = self.rect().width() height = self.rect().height() col = QColor(135, 206, 235) pen = QPen(col, self._value) pen.setJoinStyle(Qt.PenJoinStyle.MiterJoin) qp.setPen(pen) path = QPainterPath() # draw pentagram star_center_x = width / 2 star_center_y = height / 2 # make sure the star equal no matter the size of the qframe if width < height: # not taking it all the way to the edge so the star has room to grow radius_outer = width * 0.35 else: radius_outer = height * 0.35 # start at the top point of the star and move counter clockwise to draw the path. # every other point is the shorter radius (1/(1+golden_ratio)) of the larger radius golden_ratio = (1 + np.sqrt(5)) / 2 radius_inner = radius_outer / (1 + golden_ratio) theta_start = np.pi / 2 theta_inc = (2 * np.pi) / 10 for n in range(11): theta = theta_start + (n * theta_inc) theta = np.mod(theta, 2 * np.pi) if np.mod(n, 2) == 0: # use radius_outer x = radius_outer * np.cos(theta) y = radius_outer * np.sin(theta) else: # use radius_inner x = radius_inner * np.cos(theta) y = radius_inner * np.sin(theta) x_adj = star_center_x - x y_adj = star_center_y - y + 3 if n == 0: path.moveTo(x_adj, y_adj) else: path.lineTo(x_adj, y_adj) qp.drawPath(path)
def build_paths(self): """ """ geo = self.geometry() radius = 0 shadow = self.offset_shadow x0, y0 = geo.x(), geo.y() width, height = geo.width() - shadow, geo.height() - shadow left, top = 0, 0 right, bottom = width, height self.round_rect_path = QPainterPath() self.round_rect_path.moveTo(right, top + radius) self.round_rect_path.arcTo(right - radius, top, radius, radius, 0.0, 90.0) self.round_rect_path.lineTo(left + radius, top) self.round_rect_path.arcTo(left, top, radius, radius, 90.0, 90.0) self.round_rect_path.lineTo(left, bottom - radius) self.round_rect_path.arcTo(left, bottom - radius, radius, radius, 180.0, 90.0) self.round_rect_path.lineTo(right - radius, bottom) self.round_rect_path.arcTo(right - radius, bottom - radius, radius, radius, 270.0, 90.0) self.round_rect_path.closeSubpath() # Top path header = 36 offset = 2 left, top = offset, offset right = width - (offset) self.top_rect_path = QPainterPath() self.top_rect_path.lineTo(right, top + radius) self.top_rect_path.moveTo(right, top + radius) self.top_rect_path.arcTo(right - radius, top, radius, radius, 0.0, 90.0) self.top_rect_path.lineTo(left + radius, top) self.top_rect_path.arcTo(left, top, radius, radius, 90.0, 90.0) self.top_rect_path.lineTo(left, top + header) self.top_rect_path.lineTo(right, top + header)