目标
本章节里将真正的重点实现主界面的建立,以及功能的实现,将之前View上的按键功能移至主界面
在主界面中心放置View,下面添加statusBar,上面添加菜单栏,并且statusBar将实现当前鼠标在场景的位置显示,以及保存成功等消息的显示
实现
将之前的NodeEditWind改为NodeEditWidget
NodeEditWind将不再担任主界面的显示功能,而是作为一个特殊控件,执行节点编辑器功能
文件名为node_editor_widget.py
from node_scene import Scene
from node_node import Node
from node_graphics_view import QDMGraphicsView
from node_edge import *
class NodeEditWidget(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
# set QSS
self.stylesheet_filename = 'qss/nodestyle.qss'
self.loadStylesheet(self.stylesheet_filename)
# init
self.initUI()
def initUI(self):
self.layout = QVBoxLayout()
self.layout.setContentsMargins(0, 0, 0, 0)
# create graphics scene
self.scene = Scene()
self.grScene = self.scene.grScene
self.addNode()
# create graphics view
self.view = QDMGraphicsView(self.grScene, self)
self.layout.addWidget(self.view)
def addNode(self):
node1 = Node(self.scene, "这是一个节点", inputs=[0, 0, 0], outputs=[3])
node2 = Node(self.scene, "这是第二个节点", inputs=[1, 1, 1], outputs=[3])
node3 = Node(self.scene, "这是第三个节点", inputs=[2, 2, 2], outputs=[3])
node1.setPos(-550, -250)
node2.setPos(-275, 0)
node3.setPos(0, -150)
edge1 = Edge(self.scene, node1.outputs[0], node2.inputs[0], edge_type=EDGE_TYPE_BEZIER)
edge2 = Edge(self.scene, node2.outputs[0], node3.inputs[2], edge_type=EDGE_TYPE_BEZIER)
def loadStylesheet(self, filename):
print('STYLE loading', filename)
file = QFile(filename)
file.open(QFile.ReadOnly | QFile.Text)
stylesheet =