python类QPen()的实例源码

graphs.py 文件源码 项目:Laborejo 作者: hilbrichtsoftware 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, parentTransparentBlock, staticExportItem):
        super(CCGraphBlockEndMarker, self).__init__(0,-28,0,28) #x, y, w, h
        self.parentTransparentBlock = parentTransparentBlock
        self.parentCCPath = self.parentTransparentBlock.parent
        self.staticExportItem = staticExportItem
        self.setFlags(QtWidgets.QGraphicsItem.ItemIsMovable|QtWidgets.QGraphicsItem.ItemSendsGeometryChanges|QtWidgets.QGraphicsItem.ItemIsFocusable)
        self.setAcceptHoverEvents(True)
        self.setCursor(QtCore.Qt.SizeHorCursor)
        self.lastPos = self.pos()
        #self.setBrush(QtGui.QColor("red"))
        pen = QtGui.QPen()  # creates a default pen
        if not self.staticExportItem["exportsAllItems"]:
            pen.setStyle(QtCore.Qt.DashDotLine)
        pen.setWidth(2)
        self.setPen(pen)
        self.setZValue(10)

        self.inactivePen = pen
        self.inactivePen.setColor(QtGui.QColor("black"))

        self.activePen = QtGui.QPen(pen)
        self.activePen.setColor(QtGui.QColor("cyan"))
timeline.py 文件源码 项目:Laborejo 作者: hilbrichtsoftware 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, parentCCPath, staticExportItem):
        #super().__init__(0,-1*parentCCPath.rect().height(),0, parentCCPath.rect().height()) #x1, y1, x2, y2
        super().__init__(0,-1, 0, parentCCPath.rect().height() + 4) #x1, y1, x2, y2
        assert not self.line().isNull() #needed to do self.line().setLength(x)
        self.parentCCPath = parentCCPath
        self.staticExportItem = staticExportItem
        self.setFlags(QtWidgets.QGraphicsItem.ItemIsMovable|QtWidgets.QGraphicsItem.ItemSendsGeometryChanges|QtWidgets.QGraphicsItem.ItemIsFocusable|QtWidgets.QGraphicsItem.ItemClipsToShape)
        self.setAcceptHoverEvents(True)
        self.setCursor(QtCore.Qt.SizeHorCursor)
        #self.setBrush(QtGui.QColor("red"))
        pen = QtGui.QPen()  # creates a default pen
        if not self.staticExportItem["exportsAllItems"]:
            pen.setStyle(QtCore.Qt.DotLine)
        pen.setWidth(2)
        self.setPen(pen)

        self.inactivePen = pen
        self.inactivePen.setColor(QtGui.QColor("black"))

        self.activePen = QtGui.QPen(pen)
        self.activePen.setColor(QtGui.QColor("cyan"))
conductor.py 文件源码 项目:Laborejo 作者: hilbrichtsoftware 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, parent):
        self.parentTransparentBlock = parent
        super().__init__(0,-1, 0, parent.rect().height()-4) #x1, y1, x2, y2
        self.setFlags(QtWidgets.QGraphicsItem.ItemIsMovable|QtWidgets.QGraphicsItem.ItemSendsGeometryChanges|QtWidgets.QGraphicsItem.ItemIsFocusable|QtWidgets.QGraphicsItem.ItemClipsToShape)
        self.setAcceptHoverEvents(True)
        self.setCursor(QtCore.Qt.SizeHorCursor)

        pen = QtGui.QPen()  # creates a default pen
        if not self.parentTransparentBlock.staticExportItem["exportsAllItems"]:
            pen.setStyle(QtCore.Qt.DotLine)
        pen.setWidth(2)
        self.setPen(pen)

        self.inactivePen = pen
        self.inactivePen.setColor(QtGui.QColor("black"))

        self.activePen = QtGui.QPen(pen)
        self.activePen.setColor(QtGui.QColor("cyan"))

        self.minimalSize = api.D1 / constantsAndConfigs.ticksToPixelRatio
items.py 文件源码 项目:PointlessMaker 作者: aboood40091 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def paint(self, painter, option, widget):
        painter.setClipRect(option.exposedRect)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)

        if self.isSelected():
            painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 92, 196, 240)))
            painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255), 1))

        else:
            painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 92, 196, 120)))
            painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0), 1))

        painter.drawRoundedRect(self.itemRect, 4 * (globals.TileWidth / 16), 4 * (globals.TileWidth / 16))

        painter.setFont(self.font)
        painter.drawText(self.itemRect, Qt.AlignCenter, str(self.type))
Selection.py 文件源码 项目:urh 作者: jopohl 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def __init__(self, *args, fillcolor, opacity, parent=None):
        if len(args) == 0:
            super().__init__(parent)
        elif len(args) == 1:
            super().__init__(args[0], parent)
        elif len(args) == 4:
            x0, y0, w, h = args
            super().__init__(x0, y0, w, h, parent)

        self.finished = False
        self.selected_edge = None  # type: int
        self.resizing = False

        self.setBrush(fillcolor)
        self.setPen(QPen(QColor(Qt.transparent), Qt.FlatCap))
        self.setOpacity(opacity)
Modulator.py 文件源码 项目:urh 作者: jopohl 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def data_scene(self) -> QGraphicsScene:
        ones = np.ones(self.samples_per_bit, dtype=np.float32) * 1
        zeros = np.ones(self.samples_per_bit, dtype=np.float32) * -1
        n = self.samples_per_bit * len(self.display_bits)
        y = []
        for bit in self.display_bits:
            if bit == "0":
                y.extend(zeros)
            elif bit == "1":
                y.extend(ones)
        x = np.arange(0, n).astype(np.int64)
        scene = ZoomableScene()
        scene.setSceneRect(0, -1, n, 2)
        scene.setBackgroundBrush(constants.BGCOLOR)
        scene.addLine(0, 0, n, 0, QPen(constants.AXISCOLOR, Qt.FlatCap))
        y = np.array(y) if len(y) > 0 else np.array(y).astype(np.float32)
        path = path_creator.array_to_QPath(x, y)
        scene.addPath(path, QPen(constants.LINECOLOR, Qt.FlatCap))
        return scene
homography.py 文件源码 项目:SantosGUI 作者: santosfamilyfoundation 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, parent):
        super(HomographyScene, self).__init__(parent)
        self.points = []
        self.main_pixmap_item = None  # Either None or a QGraphicsPixmapItem representing the loaded image

        # Point configuration
        self.point_rad = 12  # Radius, in pixels
        self.point_pen_color = QtGui.QColor(255, 74, 13, 230)  # R, G, B, A
        self.point_pen = QtGui.QPen(self.point_pen_color, 6)
        self.point_brush_color = QtGui.QColor(195, 13, 255, 20)  # R, G, B, A
        self.point_brush = QtGui.QBrush(self.point_brush_color)
        self.point_selected = False
        self.selected_point = None

        font = QtGui.QFont()
        font.setPixelSize(48)
        font.setBold(True)
        self.label_font = font
        self.label_pen_color = QtGui.QColor(0, 0, 0)  # R, G, B
        self.label_pen = QtGui.QPen(self.label_pen_color, 2)
        self.label_brush_color = QtGui.QColor(255, 255, 255)  # R, G, B
        self.label_brush = QtGui.QBrush(self.label_brush_color)
concentriccircles.py 文件源码 项目:pyqt5-example 作者: guinslym 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, self.antialiased)
        painter.translate(self.width() / 2, self.height() / 2)

        for diameter in range(0, 256, 9):
            delta = abs((self.frameNo % 128) - diameter / 2)
            alpha = 255 - (delta * delta) / 4 - diameter
            if alpha > 0:
                painter.setPen(QPen(QColor(0, diameter / 2, 127, alpha), 3))

                if self.floatBased:
                    painter.drawEllipse(QRectF(-diameter / 2.0,
                            -diameter / 2.0, diameter, diameter))
                else:
                    painter.drawEllipse(QRect(-diameter / 2,
                            -diameter / 2, diameter, diameter))
bubbleswidget.py 文件源码 项目:pyqt5-example 作者: guinslym 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self, parent=None):

        super(BubblesWidget, self).__init__(parent)

        self.pen = QPen(QColor("#cccccc"))
        self.bubbles = []
        self.backgroundColor1 = self.randomColor()
        self.backgroundColor2 = self.randomColor().darker(150)
        self.newBubble = None

        random.seed()

        self.animation_timer = QTimer(self)
        self.animation_timer.setSingleShot(False)
        self.animation_timer.timeout.connect(self.animate)
        self.animation_timer.start(25)

        self.bubbleTimer = QTimer()
        self.bubbleTimer.setSingleShot(False)
        self.bubbleTimer.timeout.connect(self.expandBubble)

        self.setMouseTracking(True)
        self.setMinimumSize(QSize(200, 200))
        self.setWindowTitle("Bubble Maker")
demo_app1.py 文件源码 项目:face-identification-tpe 作者: meownoid 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def draw_box(self, n, box, color, style, num):
        x1, y1, x2, y2 = box.left(), box.top(), box.right(), box.bottom()

        x1 = int(x1 * self.i_scale[n])
        y1 = int(y1 * self.i_scale[n])
        x2 = int(x2 * self.i_scale[n])
        y2 = int(y2 * self.i_scale[n])

        width = BASEWIDTH
        if style == 'match':
            width *= 2

        painter = QPainter(self.i_pixmap[n])
        painter.setPen(QPen(QBrush(color), width))
        painter.drawRect(x1, y1, x2 - x1, y2 - y1)
        painter.setPen(QPen(QBrush(TEXTCOLOR), TEXTWIDTH))
        painter.setFont(TEXTFONT)
        painter.drawText(x1, y2 + TEXTSIZE + 2 * BASEWIDTH, '{}: {}'.format(n + 1, num))
        painter.end()
        self.i_lbl[n].setPixmap(self.i_pixmap[n])
map.py 文件源码 项目:satellite-tracker 作者: lofaldli 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def pen(self, color=Qt.black, style=Qt.SolidLine):
        pen = QPen(color)
        pen.setStyle(style)
        return pen
radar.py 文件源码 项目:echolocation 作者: hgross 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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))
radar.py 文件源码 项目:echolocation 作者: hgross 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _add_measurement(self, length, angle, added_time):
        """
        Adds a visualization for a measured distance to the scene
        :param length: length in cm
        :param angle: the angle
        """
        mx, my = self._get_middle()
        angle_rad = deg2rad(angle)
        ex, ey = mx + length * math.cos(angle_rad), my + length * math.sin(angle_rad)

        age = time.time() - added_time
        age = age if age < self.fade_out_time else self.fade_out_time
        alpha_channel_value = scale((0, self.fade_out_time), (255, 0), age)
        assert 0 <= alpha_channel_value <= 255

        brush_color = QColor(self.measured_distances_color)
        brush_color.setAlpha(alpha_channel_value)
        brush = QBrush(brush_color)
        tpen = QPen(brush_color)

        self.scene.addLine(mx, my, ex, ey, pen=tpen)
        self.scene.addEllipse(ex-self.dot_width/2, ey-self.dot_width/2, self.dot_width, self.dot_width, pen=tpen, brush=brush)
radar.py 文件源码 项目:echolocation 作者: hgross 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _add_circles(self, n, add_text_labels=True):
        """
        Adds n circles to the graphic scene.
        :param n: the number of circles
        """
        pen = QPen(self.circle_line_color)
        pen.setStyle(Qt.DotLine)
        pen.setWidth(self.line_width)
        width, height = self.width(), self.height()
        stepw, steph = width/n, height/n
        mx, my = self._get_middle()

        for i in range(1, n+1):
            w, h = width - i * stepw, height - i * steph
            self.scene.addEllipse((width-w)/2, (height-h)/2, w, h, pen)

            if add_text_labels:
                text = QGraphicsTextItem()
                text.setDefaultTextColor(self.text_label_color)
                text.setPlainText(str(int(w/2)))
                text.setPos(mx+w/2.0, my)

                text2 = QGraphicsTextItem()
                text2.setDefaultTextColor(self.text_label_color)
                text2.setPlainText(str(int(-w / 2)))
                text2.setPos(mx - w / 2.0, my)

                self.scene.addItem(text)
                self.scene.addItem(text2)
port.py 文件源码 项目:PyNoder 作者: johnroper100 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self, port, graph, hOffset, color, connectionPointType):
        super(PortCircle, self).__init__(port)

        self.__port = port
        self._graph = graph
        self._connectionPointType = connectionPointType
        self.__connections = set()
        self._supportsOnlySingleConnections = connectionPointType == 'In'

        self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed))
        size = QtCore.QSizeF(self.__diameter, self.__diameter)
        self.setPreferredSize(size)
        self.setWindowFrameMargins(0, 0, 0, 0)

        self.transform().translate(self.__radius * hOffset, 0)

        self.__defaultPen = QtGui.QPen(QtGui.QColor("#000000"), 1.0)
        self.__hoverPen = QtGui.QPen(QtGui.QColor("#000000"), 1.5)

        self._ellipseItem = QtWidgets.QGraphicsEllipseItem(self)
        self._ellipseItem.setPen(self.__defaultPen)
        self._ellipseItem.setPos(size.width()/2, size.height()/2)
        self._ellipseItem.setRect(
            -self.__radius,
            -self.__radius,
            self.__diameter,
            self.__diameter,
            )

        self.setColor(color)
        self.setAcceptHoverEvents(True)
port.py 文件源码 项目:PyNoder 作者: johnroper100 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def setItem(self, item):
        item.setParentItem(self)
        self.layout().addItem(item)

    # def paint(self, painter, option, widget):
    #     super(ItemHolder, self).paint(painter, option, widget)
    #     painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 0)))
    #     painter.drawRect(self.windowFrameRect())
port.py 文件源码 项目:PyNoder 作者: johnroper100 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def connectionPointType(self):
        return self._connectionPointType

    # def paint(self, painter, option, widget):
    #     super(BasePort, self).paint(painter, option, widget)
    #     painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 0)))
    #     painter.drawRect(self.windowFrameRect())
node.py 文件源码 项目:PyNoder 作者: johnroper100 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def textSize(self):
        return QtCore.QSizeF(
            self.__textItem.textWidth(),
            self.__font.pointSizeF() + self.__labelBottomSpacing
            )

    # def paint(self, painter, option, widget):
    #     super(NodeTitle, self).paint(painter, option, widget)
    #     painter.setPen(QtGui.QPen(QtGui.QColor(0, 255, 0)))
    #     painter.drawRect(self.windowFrameRect())
node.py 文件源码 项目:PyNoder 作者: johnroper100 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def setText(self, text):
        self._titleWidget.setText(text)

    # def paint(self, painter, option, widget):
    #     super(NodeHeader, self).paint(painter, option, widget)
    #     painter.setPen(QtGui.QPen(QtGui.QColor(0, 255, 100)))
    #     painter.drawRect(self.windowFrameRect())
node.py 文件源码 项目:PyNoder 作者: johnroper100 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def addPort(self, port, alignment):
        layout = self.layout()
        layout.addItem(port)
        layout.setAlignment(port, alignment)
        self.adjustSize()
        return port

    # def paint(self, painter, option, widget):
    #     super(PortList, self).paint(painter, option, widget)
    #     painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 0)))
    #     painter.drawRect(self.windowFrameRect())


问题


面经


文章

微信
公众号

扫码关注公众号