SoFunction
Updated on 2024-12-20

python programming using PyQt to create UE blueprints

Ideas for implementation

1, site deployment: we need to have a place that can be used to draw nodes! See this post of mine for detailsBasic use of QGraphicsScene, QGraphicsView, this article uses the same approachPyQt makes preview windows (in-game mini-maps)
2, node creation: we need to customize the node, that is, the box in the figure below, the main thing involved is Qt in the QGraphicsItem, by inheriting this class to customize the node style
3, line: involves the Qt QGraphicsLineItem, inherit this class, and customize the line style in paint, such as I use here is qt comes with the Bezier curve
The implementation is as follows, nodes can connect to each other via ports

在这里插入图片描述

1. Site deployment

class EditorView(QGraphicsView):
    def __init__(self, parent=None):
        super(EditorView, self).__init__(parent)
         = parent
         = 1
         = QPointF()
         = EditorScene(self)
        ()
        (-1 << 30, -1 << 30, 1 << 31, 1 << 31)
        ()
        ()
        ().setEnabled(False)
        ().setEnabled(False)

class EditorScene(QGraphicsScene):
    def __init__(self, parent=None):
        super(EditorScene, self).__init__(parent)

	def drawBackground(self, painter, rect):
		pass
		# Drawing the base map here, the squiggle above #

2、Node creation

Here's the body of the node being created, just the black boxed thing

class NodeItem(QGraphicsItem):
    def __init__(self, parent=None):
        super(NodeItem, self).__init__(parent)
        (, True)
        (, True)
        (, True)
        (, True)
         = "Node"
         = 150
         = 50
		()
    def addPort(self):
        leftPort = PortItem(self)
        (5, /2.7)
        rightPort = PortItem(self)
        (-20, /2.7)
    def paint(self, painter, style, *args, **kwargs):
        brush = QBrush(QColor(0xaa, 0xaa, 0xaa, 0xaa))
        (brush)
        pen = QPen()
        (1)
        (pen)
        (0, 0, , )
        (/2.5, /1.8, )

Here is the creation of the node port

class PortItem(QGraphicsItem):
    def __init__(self, parent=None):
        super(PortItem, self).__init__(parent)
         = 15
    def paint(self, painter, style, *args, **kwargs):
        portColor = QColor(0x00, 0xaa, 0x00, 0x66)
        (portColor)
        pen = QPen()
        (portColor)
        (2)
        (pen)
        (0, 0, , )

Inside the node NodeItem, create two ports for connectivity

3、Linkage

①First, the creation of the linking class

class LineItem(QGraphicsItem):
    def __init__(self, posStart, posEnd, parent=None):
        super(LineItem, self).__init__(parent)
        (, True)
        (, True)
        (, True)
         = posStart
         = posEnd
    def paint(self, painter, style, *args, **kwargs):
        midPos = ( + )/2
        lineColor = QColor(0xff, 0x00, 0x00, 0xff)
        pen = QPen()
        (lineColor)
        (2)
        (pen)
        linePath = QPainterPath()
        ()
        (QPointF((), ()), midPos, )
        (linePath)

② How to connect nodes

def mouseReleaseEvent(self, event):
	 = LineItem(, )
    ()

ps written in the end, if your picture is not refreshed, you can shrink the window first and then open it, he will be refreshed, if you want him to refresh automatically, just call the () method!

Above is the detailed content of python programming using PyQt to create UE blueprints, more information about PyQt to create UE blueprints please pay attention to my other related articles!