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 __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)
Esempio n. 3
0
    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
Esempio n. 4
0
 def _pointsToPath(self, points: List[QtCore.QPointF]) -> QPainterPath:
     """Converts list of `QtCore.QPointF` objects to a `QPainterPath`."""
     path = QPainterPath()
     path.addPolygon(QPolygonF(points))
     return path