Python PyQt5.QtGui 模块,QPolygonF() 实例源码

我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用PyQt5.QtGui.QPolygonF()

项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def __init__(self, startp=Point(), endp=None,
                 length=60.0, angle=50.0,
                 color=QtCore.Qt.red, pencolor=QtCore.Qt.green,
                 startarrow=True):
        """
        Initialisation of the class.
        """
        self.sc = None
        super(Arrow, self).__init__()

        self.startp = QtCore.QPointF(startp.x, -startp.y)
        self.endp = endp

        self.length = length
        self.angle = angle
        self.startarrow = startarrow
        self.allwaysshow = False

        self.arrowHead = QPolygonF()
        self.setFlag(QGraphicsItem.ItemIsSelectable, False)
        self.myColor = color
        self.pen = QPen(pencolor, 1, QtCore.Qt.SolidLine)
        self.pen.setCosmetic(True)
        self.arrowSize = 8.0
项目:vivisect-py3    作者:bat-serjo    | 项目源码 | 文件源码
def renderEdge(self, eid, einfo, points):
        scene = self.scene()

        # If we have been drawn already, get rid of it.
        gproxy = einfo.get('gproxy')
        if gproxy:
            scene.removeItem(gproxy)

        qpoints = [QtCore.QPointF(x, y) for (x, y) in points]
        qpoly = QtGui.QPolygonF(qpoints)

        ecolor = self._vg_graph.getMeta('edgecolor', '#000')
        ecolor = einfo.get('color', ecolor)

        pen = QtGui.QPen(QtGui.QColor(ecolor))
        gproxy = self.scene().addPolygon(qpoly, pen=pen)
        gproxy.setZValue(-1.0)

        einfo['gproxy'] = gproxy
项目:bubblesub    作者:rr-    | 项目源码 | 文件源码
def _draw_video_pos(self, painter):
        if not self._api.video.current_pts:
            return
        x = self._pts_to_x(self._api.video.current_pts)
        painter.setPen(QtCore.Qt.NoPen)
        painter.setBrush(get_color(self._api, 'spectrogram/video-marker'))

        width = 7
        polygon = QtGui.QPolygonF()
        for x, y in [
            (x - width / 2, 0),
            (x + width / 2, 0),
            (x + width / 2, SLIDER_SIZE),
            (x + 1, SLIDER_SIZE + width / 2),
            (x + 1, painter.viewport().height() - 1),
            (x, painter.viewport().height() - 1),
            (x, SLIDER_SIZE + width / 2),
            (x - width / 2, SLIDER_SIZE),
        ]:
            polygon.append(QtCore.QPointF(x, y))

        painter.drawPolygon(polygon)
项目:echolocation    作者:hgross    | 项目源码 | 文件源码
def _add_latest_input_line(self, angle):
        """Adds a line to the graphic scene that visualizes a scanned angle"""
        mx, my = self._get_middle()
        angle_rad = deg2rad(angle)
        angle_1_rad = deg2rad(angle - self.measurement_angle/2.0)
        angle_2_rad = deg2rad(angle + self.measurement_angle/2.0)
        length = max(self.width(), self.height())

        start_point = (mx, my)
        p1 = (mx + length * math.cos(angle_1_rad), my + length * math.sin(angle_1_rad))
        p2 = (mx + length * math.cos(angle_2_rad), my + length * math.sin(angle_2_rad))

        gradient_start_point, gradient_end_point = (mx, my), (mx + length * math.cos(angle_rad), my + length * math.sin(angle_rad))
        gradient = QLinearGradient(*gradient_start_point, *gradient_end_point)
        gradient.setColorAt(0, Qt.transparent)
        gradient.setColorAt(0.8, Qt.red)
        gradient.setColorAt(1, Qt.darkRed)

        triangle = QPolygonF()
        triangle.append(QPointF(*start_point))
        triangle.append(QPointF(*p1))
        triangle.append(QPointF(*p2))
        triangle.append(QPointF(*start_point))

        self.scene.addPolygon(triangle, pen=QPen(Qt.transparent), brush=QBrush(gradient))
项目:Computer-graphics    作者:Panda-Lewandowski    | 项目源码 | 文件源码
def turn():
    global epi_x, epi_y, p1, p2, p3, p4, rect
    write_log()
    teta = math.radians(window.spin_deg.value())
    t_x = window.spin_turn_x.value()
    t_y = window.spin_turn_y.value()
    scene.clear()

    rect_t = QPolygonF(4)
    p1 = [t_x + (p1[0] - t_x) * math.cos(teta) + (p1[1] - t_y) * math.sin(teta),
          t_y - (p1[0] - t_x) * math.sin(teta) + (p1[1] - t_y) * math.cos(teta)]
    p2 = [t_x + (p2[0] - t_x) * math.cos(teta) + (p2[1] - t_y) * math.sin(teta),
          t_y - (p2[0] - t_x) * math.sin(teta) + (p2[1] - t_y) * math.cos(teta)]
    p3 = [t_x + (p3[0] - t_x) * math.cos(teta) + (p3[1] - t_y) * math.sin(teta),
          t_y - (p3[0] - t_x) * math.sin(teta) + (p3[1] - t_y) * math.cos(teta)]
    p4 = [t_x + (p4[0] - t_x) * math.cos(teta) + (p4[1] - t_y) * math.sin(teta),
          t_y - (p4[0] - t_x) * math.sin(teta) + (p4[1] - t_y) * math.cos(teta)]
    rect[0] = QPointF(p1[0], p1[1])
    rect[1] = QPointF(p2[0], p2[1])
    rect[2] = QPointF(p3[0], p3[1])
    rect[3] = QPointF(p4[0], p4[1])
    scene.addPolygon(rect, pen=p, brush=b)
    l = len(epi_x)
    for i in range(l):
        x1 = t_x + (epi_x[i] - t_x) * math.cos(teta) + (epi_y[i] - t_y) * math.sin(teta)
        y1 = t_y - (epi_x[i] - t_x) * math.sin(teta) + (epi_y[i] - t_y) * math.cos(teta)
        epi_x[i] = x1
        epi_y[i] = y1
        scene.addLine(epi_x[i], epi_y[i], epi_x[i] + 0.01, epi_y[i] + 0.01, pen=p)
项目:Computer-graphics    作者:Panda-Lewandowski    | 项目源码 | 文件源码
def sutherland_hodgman(clip, pol, norm):
    # ????????? ????????? ??????? ?????????? ? ?????
    clip.append(clip[0])

    s = None
    f = None
    # ???? ?? ???????? ??????????
    for i in range(len(clip) - 1):
        new = []  # ????? ?????? ??????
        for j in range(len(pol)):    # ???? ?? ???????? ??????????????
            if j == 0:
                f = pol[j]
            else:
                t = is_intersection([s, pol[j]], [clip[i], clip[i + 1]], norm)
                if t:
                    new.append(t)

            s = pol[j]
            if is_visiable(s,  clip[i], clip[i + 1], norm):
                    new.append(s)

        if len(new) != 0:
            t = is_intersection([s, f], [clip[i], clip[i + 1]], norm)
            if t:
                new.append(t)

        pol = copy.deepcopy(new)

    if len(pol) == 0:
        return False
    else:
        return QPolygonF(pol)
项目:vivisect-py3    作者:bat-serjo    | 项目源码 | 文件源码
def paint(self, painter, option, widget):
        if not self.source or not self.dest:
            return

        # Draw the line itself.
        line = QLineF(self.sourcePoint, self.destPoint)

        if line.length() == 0.0:
            return

        painter.setPen(QPen(Qt.black, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
        painter.drawLine(line)

        # Draw the arrows if there's enough room.
        angle = math.acos(line.dx() / line.length())
        if line.dy() >= 0:
            angle = VGraphEdge.TwoPi - angle

        sourceArrowP1 = self.sourcePoint + QPointF(math.sin(angle + VGraphEdge.Pi / 3) * self.arrowSize,
                                                          math.cos(angle + VGraphEdge.Pi / 3) * self.arrowSize)
        sourceArrowP2 = self.sourcePoint + QPointF(math.sin(angle + VGraphEdge.Pi - VGraphEdge.Pi / 3) * self.arrowSize,
                                                          math.cos(angle + VGraphEdge.Pi - VGraphEdge.Pi / 3) * self.arrowSize);
        destArrowP1 = self.destPoint + QPointF(math.sin(angle - VGraphEdge.Pi / 3) * self.arrowSize,
                                                      math.cos(angle - VGraphEdge.Pi / 3) * self.arrowSize)
        destArrowP2 = self.destPoint + QPointF(math.sin(angle - VGraphEdge.Pi + VGraphEdge.Pi / 3) * self.arrowSize,
                                                      math.cos(angle - VGraphEdge.Pi + VGraphEdge.Pi / 3) * self.arrowSize)

        painter.setBrush(Qt.black)
        painter.drawPolygon(QPolygonF([line.p1(), sourceArrowP1, sourceArrowP2]))
        painter.drawPolygon(QPolygonF([line.p2(), destArrowP1, destArrowP2]))
项目:pypog    作者:cro-ki    | 项目源码 | 文件源码
def generate(self, points, show_label=False):

        qpolygon = QPolygonF([QPointF(xp, yp) for xp, yp in points])

        self.setPolygon(qpolygon)

        pen = QPen()
        pen.setWidth(3)
        self.setPen(pen)

        self.setFlag(QGraphicsItem.ItemIsFocusable)

        self.label = QGraphicsSimpleTextItem("{}-{}".format(self.x, self.y), parent=self)
        self.label.setVisible(show_label)

        if len(points) == 6:
            k = 0.5 if (self.x % 2) != 0 else 0
            self.label.setPos(QPointF(((self.x * 0.866) + 0.2886) * 120, (self.y + k + 0.5) * 120))
        else:
            self.label.setPos(QPointF(self.x * 120, self.y * 120))

        font = QFont()
        font.setPointSize(20)
        self.label.setFont(font)
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def __init__(self, starCount=1, maxStarCount=5):
        self._starCount = starCount
        self._maxStarCount = maxStarCount

        self.starPolygon = QPolygonF([QPointF(1.0, 0.5)])
        for i in range(5):
            self.starPolygon << QPointF(0.5 + 0.5 * math.cos(0.8 * i * math.pi),
                                        0.5 + 0.5 * math.sin(0.8 * i * math.pi))

        self.diamondPolygon = QPolygonF()
        self.diamondPolygon << QPointF(0.4, 0.5) \
                            << QPointF(0.5, 0.4) \
                            << QPointF(0.6, 0.5) \
                            << QPointF(0.5, 0.6) \
                            << QPointF(0.4, 0.5)
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def __init__(self, starCount=1, maxStarCount=5):
        self._starCount = starCount
        self._maxStarCount = maxStarCount

        self.starPolygon = QPolygonF([QPointF(1.0, 0.5)])
        for i in range(5):
            self.starPolygon << QPointF(0.5 + 0.5 * math.cos(0.8 * i * math.pi),
                                        0.5 + 0.5 * math.sin(0.8 * i * math.pi))

        self.diamondPolygon = QPolygonF()
        self.diamondPolygon << QPointF(0.4, 0.5) \
                            << QPointF(0.5, 0.4) \
                            << QPointF(0.6, 0.5) \
                            << QPointF(0.5, 0.6) \
                            << QPointF(0.4, 0.5)
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def __init__(self, starCount=1, maxStarCount=5):
        self._starCount = starCount
        self._maxStarCount = maxStarCount

        self.starPolygon = QPolygonF([QPointF(1.0, 0.5)])
        for i in range(5):
            self.starPolygon << QPointF(0.5 + 0.5 * math.cos(0.8 * i * math.pi),
                                        0.5 + 0.5 * math.sin(0.8 * i * math.pi))

        self.diamondPolygon = QPolygonF()
        self.diamondPolygon << QPointF(0.4, 0.5) \
                            << QPointF(0.5, 0.4) \
                            << QPointF(0.6, 0.5) \
                            << QPointF(0.5, 0.6) \
                            << QPointF(0.4, 0.5)
项目:KerbalPie    作者:Vivero    | 项目源码 | 文件源码
def _assemble_plot(self, qpainter):
        qpainter.save()
        #---

        # draw bounding box
        qpainter.setPen(self._bbox_pen)
        qpainter.setBrush(self._bbox_brush)
        qpainter.drawRect(self._bbox_rect)

        # x-axis
        qpainter.setFont(self._labelFont)
        qpainter.setPen(self._axes_tick_pen)
        qpainter.setBrush(self._axes_tick_brush)
        for tick_line in self._xaxis_ticks:
            qpainter.drawLine(tick_line)

        for i in range(len(self._xaxis_ticks_text)):
            qpainter.drawText(self._xaxis_ticks_text_rect[i], Qt.AlignVCenter | Qt.AlignHCenter, self._xaxis_ticks_text[i])

        # y-axis
        for tick_line in self._yaxis_ticks:
            qpainter.drawLine(tick_line)

        for i in range(len(self._yaxis_ticks_text)):
            qpainter.drawText(self._yaxis_ticks_text_rect[i], Qt.AlignVCenter | Qt.AlignHCenter, self._yaxis_ticks_text[i])

        # x-axis origin
        qpainter.setPen(self._axes_origin_pen)
        qpainter.setBrush(self._axes_origin_brush)
        if self._xaxis_origin_x > self._bbox_x0 and self._xaxis_origin_x < self._bbox_x1:
            qpainter.drawLine(self._xaxis_origin_line)

        # y-axis origin
        if self._yaxis_origin_y > self._bbox_y0 and self._yaxis_origin_y < self._bbox_y1:
            qpainter.drawLine(self._yaxis_origin_line)

        # draw plots
        for plot_key in self._plot_points.keys():
            qpainter.setPen(self._plot_pens[plot_key])
            qpainter.setBrush(QBrush(Qt.NoBrush))

            if self._plot_draw_method[plot_key] == 'line' and len(self._plot_points[plot_key]) > 1:
                qpainter.drawPolyline(QPolygonF(self._plot_points[plot_key]))

            else:
                for plot_point in self._plot_points[plot_key]:
                    qpainter.drawPoint(plot_point)


        #---
        qpainter.restore()



    # G E T T E R S   /   S E T T E R S 
    #===========================================================================