Python PyQt5.QtGui.QPainterPath() Examples

The following are 30 code examples of PyQt5.QtGui.QPainterPath(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PyQt5.QtGui , or try the search function .
Example #1
Source File: attribute.py    From eddy with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, width=20, height=20, brush=None, **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)
        brush = brush or AttributeNode.DefaultBrush
        pen = AttributeNode.DefaultPen
        self.fpolygon = Polygon(QtGui.QPainterPath())
        self.background = Polygon(QtCore.QRectF(-14, -14, 28, 28))
        self.selection = Polygon(QtCore.QRectF(-14, -14, 28, 28))
        self.polygon = Polygon(QtCore.QRectF(-10, -10, 20, 20), brush, pen)
        self.label = NodeLabel(template='attribute', pos=lambda: self.center() - QtCore.QPointF(0, 22), parent=self)
        self.label.setAlignment(QtCore.Qt.AlignCenter)

    #############################################
    #   INTERFACE
    ################################# 
Example #2
Source File: membership.py    From eddy with GNU General Public License v3.0 6 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())
        path.addPolygon(self.head.geometry())

        if self.isSelected():
            for polygon in self.handles:
                path.addEllipse(polygon.geometry())
            for polygon in self.anchors.values():
                path.addEllipse(polygon.geometry())

        return path 
Example #3
Source File: CodeUIEdgeItem.py    From CodeAtlasSublime with Eclipse Public License 1.0 6 votes vote down vote up
def buildPath(self):
		srcPos, tarPos = self.getNodePos()
		if self.pathPnt and (self.pathPnt[0]-srcPos).manhattanLength() < 0.05 and (self.pathPnt[1]-tarPos).manhattanLength() < 0.05:
			return self.path
		self.pathPnt = (srcPos, tarPos)
		path = QtGui.QPainterPath()
		path.moveTo(srcPos)
		dx = tarPos.x() - srcPos.x()
		p1 = srcPos + QtCore.QPointF(dx*0.3, 0)
		p2 = tarPos + QtCore.QPointF(-dx*0.7, 0)
		path.cubicTo(p1,p2,tarPos)
		self.curve = QtGui.QPainterPath(path)
		self.path = path

		from PyQt5.QtGui import QPainterPathStroker
		stroker = QPainterPathStroker()
		stroker.setWidth(10.0)
		self.pathShape = stroker.createStroke(self.path)
		return path 
Example #4
Source File: QtImageViewer.py    From PyQtImageViewer with MIT License 6 votes vote down vote up
def mouseReleaseEvent(self, event):
        """ Stop mouse pan or zoom mode (apply zoom if valid).
        """
        QGraphicsView.mouseReleaseEvent(self, event)
        scenePos = self.mapToScene(event.pos())
        if event.button() == Qt.LeftButton:
            self.setDragMode(QGraphicsView.NoDrag)
            self.leftMouseButtonReleased.emit(scenePos.x(), scenePos.y())
        elif event.button() == Qt.RightButton:
            if self.canZoom:
                viewBBox = self.zoomStack[-1] if len(self.zoomStack) else self.sceneRect()
                selectionBBox = self.scene.selectionArea().boundingRect().intersected(viewBBox)
                self.scene.setSelectionArea(QPainterPath())  # Clear current selection area.
                if selectionBBox.isValid() and (selectionBBox != viewBBox):
                    self.zoomStack.append(selectionBBox)
                    self.updateViewer()
            self.setDragMode(QGraphicsView.NoDrag)
            self.rightMouseButtonReleased.emit(scenePos.x(), scenePos.y()) 
Example #5
Source File: qt.py    From eddy with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, width, height, color, border=None):
        """
        Initialize the icon.
        :type width: T <= int | float
        :type height: T <= int | float
        :type color: str
        :type border: str
        """
        pixmap = QtGui.QPixmap(width, height)
        painter = QtGui.QPainter(pixmap)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        path = QtGui.QPainterPath()
        path.addRect(QtCore.QRectF(QtCore.QPointF(0, 0), QtCore.QPointF(width, height)))
        painter.fillPath(path, QtGui.QBrush(QtGui.QColor(color)))
        if border:
            painter.setPen(QtGui.QPen(QtGui.QColor(border), 0, QtCore.Qt.SolidLine))
            painter.drawPath(path)
        painter.end()
        super().__init__(pixmap) 
Example #6
Source File: plotter.py    From qomui with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, parent = None):
        super(PlotArea, self).__init__(parent)
        self.down_values = []
        self.up_values = []
        self.max_val = 1
        self.x_off = 60
        self.offset = 5
        self.gap = 8
        bold_font = QtGui.QFont()
        bold_font.setPointSize(8)
        bold_font.setWeight(75)
        self.setFont(bold_font)
        self.up_path = QtGui.QPainterPath()
        self.down_path = QtGui.QPainterPath()
        self.setAutoFillBackground(True)
        self.wmax = self.width() - self.offset
        self.hmax = self.height() - self.offset 
Example #7
Source File: common.py    From eddy with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, geometry=QtGui.QPolygonF(),
         brush=QtGui.QBrush(QtCore.Qt.NoBrush),
         pen=QtGui.QPen(QtCore.Qt.NoPen)):
        """
        Initialize the polygon.
        :type geometry: T <= QRectF|QtGui.QPolygonF|QPainterPath
        :type brush: QBrush
        :type pen: QPen
        """
        self._geometry = geometry
        self._brush = brush
        self._pen = pen

    #############################################
    #   INTERFACE
    ################################# 
Example #8
Source File: Chart.py    From nanovna-saver with GNU General Public License v3.0 6 votes vote down vote up
def drawMarker(self, x, y, qp: QtGui.QPainter, color: QtGui.QColor, number=0):
        if self.markerAtTip:
            y -= self.markerSize
        pen = QtGui.QPen(color)
        qp.setPen(pen)
        qpp = QtGui.QPainterPath()
        qpp.moveTo(x, y + self.markerSize)
        qpp.lineTo(x - self.markerSize, y - self.markerSize)
        qpp.lineTo(x + self.markerSize, y - self.markerSize)
        qpp.lineTo(x, y + self.markerSize)

        if self.filledMarkers:
            qp.fillPath(qpp, color)
        else:
            qp.drawPath(qpp)

        if self.drawMarkerNumbers:
            number_x = x - 3
            number_y = y - self.markerSize - 3
            qp.drawText(number_x, number_y, str(number)) 
Example #9
Source File: qtPen.py    From Emoji-Tools with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, glyphSet, path=None):
		BasePen.__init__(self, glyphSet)
		if path is None:
			from PyQt5.QtGui import QPainterPath
			path = QPainterPath()
		self.path = path 
Example #10
Source File: image_graphics_view.py    From CvStudio with MIT License 5 votes vote down vote up
def mouseMoveEvent(self, evt: QtGui.QMouseEvent) -> None:
        mouse_pos = self.mapToScene(evt.pos())
        image_rect: QRectF = self._pixmap.boundingRect()
        if self.current_tool == SELECTION_TOOL.BOX:
            if not self._rectangle_tool_origin.isNull():
                geometry = QRect(self._rectangle_tool_origin, evt.pos()).normalized()
                self._rectangle_tool_picker.setGeometry(geometry)
        elif self.current_tool == SELECTION_TOOL.POLYGON:
            if self._current_polygon and image_rect.contains(mouse_pos):
                if self._current_polygon.count > 0:
                    last_point: QPointF = self._current_polygon.last_point
                    self._polygon_guide_line.setZValue(1)
                    self._polygon_guide_line.show()
                    mouse_pos = self.mapToScene(evt.pos())
                    self._polygon_guide_line.setLine(last_point.x(), last_point.y(), mouse_pos.x(), mouse_pos.y())
            else:
                self._polygon_guide_line.hide()
        elif self.current_tool == SELECTION_TOOL.ELLIPSE:
            if self._current_ellipse and image_rect.contains(mouse_pos):
                ellipse_rect = self._current_ellipse.rect()
                ellipse_pos = QPointF(ellipse_rect.x(), ellipse_rect.y())
                distance = math.hypot(mouse_pos.x() - ellipse_pos.x(), mouse_pos.y() - ellipse_pos.y())
                ellipse_rect.setWidth(distance)
                ellipse_rect.setHeight(distance)
                self._current_ellipse.setRect(ellipse_rect)
        elif self.current_tool == SELECTION_TOOL.FREE and evt.buttons() and QtCore.Qt.LeftButton:
            if self._current_free_path and image_rect.contains(mouse_pos):
                painter: QPainterPath = self._current_free_path.path()
                self._last_point_drawn = self.mapToScene(evt.pos())
                painter.lineTo(self._last_point_drawn)
                self._current_free_path.setPath(painter)
        super(ImageViewer, self).mouseMoveEvent(evt) 
Example #11
Source File: SymbolUIItem.py    From CodeAtlasSublime with Eclipse Public License 1.0 5 votes vote down vote up
def buildUI(self, uiAttr, scene):
		self.prepareGeometryChange()
		self.path = QtGui.QPainterPath()

		maxA = uiAttr.maxTheta
		minA = uiAttr.minTheta
		minR = scene.getBaseRadius()
		maxR = uiAttr.maxR
		self.txtRadius = uiAttr.minR
		self.theta = (minA, maxA)
		self.radius= (minR, maxR)
		begDir = (math.cos(minA), -math.sin(minA))
		endDir = (math.cos(maxA), -math.sin(maxA))

		width = maxR*2
		self.path.moveTo(maxR * begDir[0], maxR * begDir[1])
		self.path.arcTo(-maxR, -maxR, width, width, math.degrees(minA), math.degrees(maxA-minA))
		#self.rect = QtCore.QRectF(-maxR, -maxR, width, width)

		rect = QtCore.QRectF(1e6,1e6,-2e6,-2e6)
		self._addRectPnt(rect, minR * begDir[0], minR * begDir[1])
		self._addRectPnt(rect, minR * endDir[0], minR * endDir[1])
		angle = minA
		for i in range(7):
			x, y = maxR*math.cos(angle)*1.2, maxR*math.sin(angle)*-1.2
			angle += (maxA - minA)/7
			self._addRectPnt(rect, x, y)
		self.rect = rect

		width = minR*2
		self.path.arcTo(-minR, -minR, width, width, math.degrees(maxA), math.degrees(minA-maxA))
		self.path.closeSubpath()

		self.txtPos = self.polar2Coord(0.5*(self.radius[0] + self.radius[1]), 0.5*(self.theta[0]+ self.theta[1]))
		self.txtPos = QtCore.QPointF(self.txtPos[0], self.txtPos[1]) 
Example #12
Source File: common.py    From eddy with GNU General Public License v3.0 5 votes vote down vote up
def setGeometry(self, geometry):
        """
        Set the shape polygon.
        :type geometry: T <= QRectF | QPolygonF | QPainterPath
        """
        self._geometry = geometry 
Example #13
Source File: FFTSceneManager.py    From urh with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent, graphic_view=None):
        self.peak = []

        super().__init__(parent)
        self.scene = GridScene(parent=graphic_view)
        self.scene.setBackgroundBrush(settings.BGCOLOR)

        self.peak_item = self.scene.addPath(QPainterPath(), QPen(settings.PEAK_COLOR, 0))  # type: QGraphicsPathItem 
Example #14
Source File: FFTSceneManager.py    From urh with GNU General Public License v3.0 5 votes vote down vote up
def clear_peak(self):
        self.peak = []
        if self.peak_item:
            self.peak_item.setPath(QPainterPath()) 
Example #15
Source File: plotter.py    From qomui with GNU General Public License v3.0 5 votes vote down vote up
def addPoint(self, up, down):
        self.up_path = QtGui.QPainterPath()
        self.down_path = QtGui.QPainterPath()
        self.up_values.insert(0, up)
        self.down_values.insert(0, down)

        #check for highest value
        max_down = max(self.down_values)
        max_up = max(self.down_values)
        if max_down >= max_up:
            self.max_y = max_down
        else:
            self.max_y = max_up

        self.max_val = round(self.max_y/128, 1)
        if self.max_val < 0.1:
            self.max_val = 0.1 
        nx = int((self.wmax - self.x_off)/ self.gap)   
        if nx < (len(self.up_values)+1):
            self.up_values = self.up_values[:nx]
            self.down_values = self.down_values[:nx]

        scale_y = (self.max_y*1.1 / self.hmax) + 1
        start_x = self.wmax - self.x_off

        start_y = self.hmax - (self.up_values[0] / scale_y)
        self.up_path.moveTo(start_x, start_y)
        for i, p in enumerate(self.up_values[1:]):
            x = start_x - self.gap*(i+1)
            y = self.hmax - (p / scale_y)
            self.up_path.lineTo(x,y)

        start_y = self.hmax - (self.down_values[0] / scale_y)
        self.down_path.moveTo(start_x, start_y)
        for i, p in enumerate(self.down_values[1:]):
            x = start_x - self.gap*(i+1)
            y = self.hmax - (p / scale_y)
            self.down_path.lineTo(x,y)

        self.update() 
Example #16
Source File: CodeUIEdgeItem.py    From CodeAtlasSublime with Eclipse Public License 1.0 5 votes vote down vote up
def shape(self):
		#srcPos, tarPos = self.getNodePos()
		#path = QtGui.QPainterPath()
		# path.moveTo(srcPos)
		# path.lineTo(tarPos)
		#path.addRect(self.boundingRect())
		#return path
		path = QtGui.QPainterPath(self.pathShape)
		if self.orderData:
			pnt = self.orderData[1]
			rect = self.getNumberRect()
			path.addEllipse(rect)
		return path 
Example #17
Source File: SymbolScene.py    From CodeAtlasSublime with Eclipse Public License 1.0 5 votes vote down vote up
def __init__(self, start, end):
		self.startPnt = start
		self.endPnt = end
		self.path = QtGui.QPainterPath()
		self.path.moveTo(self.startPnt)
		self.path.cubicTo(self.startPnt* 0.5,
						  self.endPnt*0.5,
						  self.endPnt)

		self.isVisible = True
		self.weight = 1
		# nPnts = LineCache.N_POINTS
		# self.pntList = [None] * nPnts
		# for i in range(nPnts):
		# 	t = i / float(nPnts-1)
		# 	self.pntList[i] = QtCore.QPointF(self.path.pointAtPercent(t))
		#
		# if not self.COLOR_TABLE:
		# 	srcClr = (93,195,187)
		# 	tarClr = (255,104,104)
		# 	for i in range(nPnts-1):
		# 		t = i / float(nPnts-2)
		# 		c = [0,0,0]
		# 		for j in range(3):
		# 			c[j] = srcClr[j] * (1-t) + tarClr[j] * t
		# 		self.COLOR_TABLE.append(QtGui.QColor(c[0],c[1],c[2],50)) 
Example #18
Source File: BubbleTips.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, event):
        super(BubbleLabel, self).paintEvent(event)
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)  # 抗锯齿

        rectPath = QPainterPath()  # 圆角矩形
        triPath = QPainterPath()  # 底部三角形

        height = self.height() - 8  # 往上偏移8
        rectPath.addRoundedRect(QRectF(0, 0, self.width(), height), 5, 5)
        x = self.width() / 5 * 4
        triPath.moveTo(x, height)  # 移动到底部横线4/5处
        # 画三角形
        triPath.lineTo(x + 6, height + 8)
        triPath.lineTo(x + 12, height)

        rectPath.addPath(triPath)  # 添加三角形到之前的矩形上

        # 边框画笔
        painter.setPen(QPen(self.BorderColor, 1, Qt.SolidLine,
                            Qt.RoundCap, Qt.RoundJoin))
        # 背景画刷
        painter.setBrush(self.BackgroundColor)
        # 绘制形状
        painter.drawPath(rectPath)
        # 三角形底边绘制一条线保证颜色与背景一样
        painter.setPen(QPen(self.BackgroundColor, 1,
                            Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
        painter.drawLine(x, height, x + 12, height) 
Example #19
Source File: CColorControl.py    From CustomWidgets with GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, event):
        super(CColorControl, self).paintEvent(event)
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
        painter.setPen(Qt.NoPen)

        # 变换圆心
        painter.translate(self.rect().center())

        # 画背景方格图
        painter.save()
        # 保证方格在前景圆内部
        diameter = min(self.width(), self.height()) - 8
        radius = diameter / 2
        path = QPainterPath()
        path.addRoundedRect(-radius, -radius, diameter,
                            diameter, radius, radius)
        painter.setClipPath(path)

        pixSize = 5
        for x in range(int(self.width() / pixSize)):
            for y in range(int(self.height() / pixSize)):
                _x, _y = x * pixSize, y * pixSize
                painter.fillRect(_x - radius, _y - radius, pixSize, pixSize,
                                 Qt.white if x % 2 != y % 2 else Qt.darkGray)
        painter.restore()

        # 画前景颜色
        diameter = min(self.width(), self.height()) - 4
        radius = diameter / 2
        path = QPainterPath()
        path.addRoundedRect(-radius, -radius, diameter,
                            diameter, radius, radius)
        painter.setClipPath(path)

        painter.setBrush(self._color)
        painter.drawRoundedRect(-radius, -radius,
                                diameter, diameter, radius, radius) 
Example #20
Source File: CAvatar.py    From CustomWidgets with GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, event):
        super(CAvatar, self).paintEvent(event)
        # 画笔
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setRenderHint(QPainter.HighQualityAntialiasing, True)
        painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
        # 绘制
        path = QPainterPath()
        diameter = min(self.width(), self.height())
        if self.shape == self.Circle:
            radius = int(diameter / 2)
        elif self.shape == self.Rectangle:
            radius = 4
        halfW = self.width() / 2
        halfH = self.height() / 2
        painter.translate(halfW, halfH)
        path.addRoundedRect(
            QRectF(-halfW, -halfH, diameter, diameter), radius, radius)
        painter.setClipPath(path)
        # 如果是动画效果
        if self.rotateAnimation.state() == QPropertyAnimation.Running:
            painter.rotate(self._angle)  # 旋转
            painter.drawPixmap(
                QPointF(-self.pixmap.width() / 2, -self.pixmap.height() / 2), self.pixmap)
        else:
            painter.drawPixmap(-int(halfW), -int(halfH), self.pixmap)
        # 如果在加载
        if self.loadingTimer.isActive():
            diameter = 2 * self.pradius
            painter.setBrush(
                QColor(45, 140, 240, (1 - self.pradius / 10) * 255))
            painter.setPen(Qt.NoPen)
            painter.drawRoundedRect(
                QRectF(-self.pradius, -self.pradius, diameter, diameter), self.pradius, self.pradius) 
Example #21
Source File: pyqt_backend.py    From ezdxf with MIT License 5 votes vote down vote up
def draw(self, path: qg.QPainterPath):
        path.arcTo(self.rect, self.start_angle, self.span_angle) 
Example #22
Source File: common.py    From eddy with GNU General Public License v3.0 5 votes vote down vote up
def geometry(self):
        """
        Returns the polygon geometry.
        :rtype: T <= QRectF | QPolygonF | QPainterPath
        """
        return self._geometry 
Example #23
Source File: common.py    From eddy with GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        pass 
Example #24
Source File: concept.py    From eddy with GNU General Public License v3.0 5 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addRect(self.polygon.geometry())
        for polygon in self.handles:
            path.addEllipse(polygon.geometry())
        return path 
Example #25
Source File: concept.py    From eddy with GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addRect(self.polygon.geometry())
        return path 
Example #26
Source File: restriction.py    From eddy with GNU General Public License v3.0 5 votes vote down vote up
def shape(self, *args, **kwargs):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addRect(self.polygon.geometry())
        return path 
Example #27
Source File: restriction.py    From eddy with GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addRect(self.polygon.geometry())
        return path 
Example #28
Source File: operator.py    From eddy with GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPolygon(self.polygon.geometry())
        return path 
Example #29
Source File: operator.py    From eddy with GNU General Public License v3.0 5 votes vote down vote up
def boundingRect(self):
        """
        Returns the shape bounding rectangle.
        :rtype: QtCore.QRectF
        """
        path = QtGui.QPainterPath()
        path.addPolygon(self.selection.geometry())
        return path.boundingRect() 
Example #30
Source File: facet.py    From eddy with GNU General Public License v3.0 5 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPolygon(self.polygon.geometry())
        return path